Skip to content

Commit

Permalink
refactor: kids-first#3346 remove fences provider
Browse files Browse the repository at this point in the history
  • Loading branch information
evans-g-crsj committed Jul 14, 2021
1 parent 00517ea commit bcb86f3
Show file tree
Hide file tree
Showing 23 changed files with 667 additions and 791 deletions.
2 changes: 2 additions & 0 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,5 @@ export const DB_GA_P = 'dbGaP';

export const generateUrlForDbGap = (dbGaPStudyId) =>
`https://www.ncbi.nlm.nih.gov/projects/gap/cgi-bin/study.cgi?study_id=${dbGaPStudyId}.v1.p1`;

export const INTEGRATION_PREFIX = 'integration_';
3 changes: 1 addition & 2 deletions src/components/ContextProvider/ContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { EGO_JWT_KEY } from 'common/constants';
import { ApiContext, initializeApi } from 'services/api';
import history, { HistoryContext } from 'services/history';
import { logoutAll } from 'services/login';
import { provideFenceConnections, provideLoggedInUser } from 'stateProviders';
import { provideLoggedInUser } from 'stateProviders';

import ScrollbarSizeProvider from './ScrollbarSizeProvider';

export default compose(
provideLoggedInUser,
provideFenceConnections,
injectState,
)(({ children }) => (
<HistoryContext.Provider>
Expand Down
90 changes: 43 additions & 47 deletions src/components/Fence/FenceAuthorizedStudies.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { Fragment } from 'react';
import { Spin } from 'antd';
import { injectState } from 'freactal';
import get from 'lodash/get';
import React from 'react';
import { compose } from 'recompose';

import useFenceConnections from 'hooks/useFenceConnections';
import useFenceStudies from 'hooks/useFenceStudies';
import RightChevron from 'icons/DoubleChevronRightIcon';
import StackIcon from 'icons/StackIcon';
import { withApi } from 'services/api';
import { withHistory } from 'services/history';
import { fenceConnectionInitializeHoc } from 'stateProviders/provideFenceConnections';
import Column from 'uikit/Column';
import { Span } from 'uikit/Core';
import ExternalLink from 'uikit/ExternalLink';
import { PromptMessageContainer } from 'uikit/PromptMessage';
import Row from 'uikit/Row';
import { Spinner } from 'uikit/Spinner';

import './FenceAuthorizedStudies.css';

Expand All @@ -29,61 +29,57 @@ const sqonForStudy = (studyId) => ({
],
});

const FenceProjectList = ({ history, fenceConnectionsInitialized, authStudies }) =>
!fenceConnectionsInitialized ? (
<Spin />
) : (
authStudies.map(({ id, studyShortName }) => {
const sqon = sqonForStudy(id);
return (
<Row className={'itemRowContainer'} key={id}>
<Column justifyContent="center" p={15}>
<StackIcon width={20} />
</Column>
<Column flex={1} justifyContent="center" pr={10}>
<Span>
<strong>{studyShortName}</strong> ({`${id}`})
</Span>
</Column>
<Column justifyContent="center">
<ExternalLink hasExternalIcon={false}>
<Span
onClick={() => history.push(`/search/file?sqon=${encodeURI(JSON.stringify(sqon))}`)}
>
{'View data files'} <RightChevron width={10} fill={'#90278e'} />
</Span>
</ExternalLink>
</Column>
</Row>
);
})
);

const FenceAuthorizedStudies = compose(
withApi,
withHistory,
injectState,
fenceConnectionInitializeHoc,
)(({ fence, history, state: { fenceStudies, fenceConnectionsInitialized } }) => {
const authStudies = get(fenceStudies, `${fence}.authorizedStudies`, []);
)(({ onCloseModalCb, api, fence, history }) => {
const { isFetchingAllFenceConnections } = useFenceConnections(api, [fence]);
const { isFetchingAllFenceStudies, fenceAuthStudies } = useFenceStudies(api);

const isLoadingStudies = isFetchingAllFenceConnections || isFetchingAllFenceStudies;
if (isLoadingStudies) {
return <Spinner />;
}
return (
<div className={'fenceAuthorizedStudiesContainer'}>
<Column>
{authStudies.length ? (
<Fragment>
{fenceAuthStudies.length ? (
<>
<Row style={{ margin: '10px 0' }}>
<Span className="title" fontWeight={'bold'}>
{' '}
You have access to controlled datasets from the following studies:
</Span>
</Row>
<Column pl={15}>
<FenceProjectList
authStudies={authStudies}
history={history}
fenceConnectionsInitialized={fenceConnectionsInitialized}
/>
{fenceAuthStudies.map(({ id, studyShortName }) => (
<Row className={'itemRowContainer'} key={id}>
<Column justifyContent="center" p={15}>
<StackIcon width={20} />
</Column>
<Column flex={1} justifyContent="center" pr={10}>
<Span>
<strong>{studyShortName}</strong> ({`${id}`})
</Span>
</Column>
<Column justifyContent="center">
<ExternalLink hasExternalIcon={false}>
<Span
onClick={() => {
history.push(
`/search/file?sqon=${encodeURI(JSON.stringify(sqonForStudy(id)))}`,
);
onCloseModalCb();
}}
>
{'View data files'} <RightChevron width={10} fill={'#90278e'} />
</Span>
</ExternalLink>
</Column>
</Row>
))}
</Column>
</Fragment>
</>
) : (
<Row>
<PromptMessageContainer warning mb={0} width={'100%'}>
Expand Down
47 changes: 21 additions & 26 deletions src/components/FileRepo/CustomColumns/ActionsColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Tooltip from 'uikit/Tooltip';
import { ControlledIcon } from '../ui';

import './customColumns.css';
const enhance = compose(withApi);

const FenceDownloadButton = ({ fence, kfId }) =>
// DCF files currently aren't available to download, so we show tooltip and grey out button
Expand Down Expand Up @@ -59,29 +58,6 @@ FenceDownloadButton.propTypes = {
kfId: PropTypes.string.isRequired,
};

const ActionItems = ({ value, fence, hasAccess }) => (
<>
{hasAccess ? (
<FenceDownloadButton fence={fence} kfId={value} />
) : (
<Tooltip
position="bottom"
interactive
html={<Row p={'10px'}>You do not have access to this file.</Row>}
>
<ControlledIcon fill={theme.lightBlue} />
</Tooltip>
)}
</>
);

ActionItems.propTypes = {
fence: PropTypes.string.isRequired,
file: PropTypes.object.isRequired,
hasAccess: PropTypes.bool.isRequired,
value: PropTypes.any.isRequired,
};

const ActionsColumn = ({ value, api, fenceAcls }) => (
<Query
renderError
Expand Down Expand Up @@ -116,6 +92,13 @@ const ActionsColumn = ({ value, api, fenceAcls }) => (
},
}}
render={({ loading: loadingQuery, data }) => {
if (loadingQuery) {
return (
<Row center className={'action-column-row'}>
<Spin size={'small'} />
</Row>
);
}
const file = get(data, 'file.hits.edges[0].node', {});
const acl = file.acl || [];
const repository = file.repository;
Expand All @@ -125,7 +108,19 @@ const ActionsColumn = ({ value, api, fenceAcls }) => (
{loadingQuery ? (
<Spin size={'small'} />
) : (
<ActionItems value={value} fence={repository} hasAccess={hasAccess} file={file} />
<>
{hasAccess ? (
<FenceDownloadButton fence={repository} kfId={value} />
) : (
<Tooltip
position="bottom"
interactive
html={<Row p={'10px'}>You do not have access to this file.</Row>}
>
<ControlledIcon fill={theme.lightBlue} />
</Tooltip>
)}
</>
)}
</Row>
);
Expand All @@ -139,4 +134,4 @@ ActionsColumn.propTypes = {
fenceAcls: PropTypes.arrayOf(PropTypes.string).isRequired,
};

export default enhance(ActionsColumn);
export default compose(withApi)(ActionsColumn);
Loading

0 comments on commit bcb86f3

Please sign in to comment.