Skip to content

Commit

Permalink
Render button in panel instead of AllAnalyses
Browse files Browse the repository at this point in the history
  • Loading branch information
chowington committed Sep 12, 2023
1 parent 966c84b commit 31293ab
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 37 deletions.
19 changes: 19 additions & 0 deletions packages/libs/coreui/src/components/icons/Plus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SVGProps } from 'react';
import { Add } from '@material-ui/icons';

const Plus = (props: SVGProps<SVGSVGElement>) => {
const { height = '1em', width = '1em' } = props;
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="-16 176 352 224"
height={height}
width={width}
{...props}
>
<Add />
</svg>
);
};

export default Plus;
1 change: 1 addition & 0 deletions packages/libs/coreui/src/components/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as Filter } from './Filter';
export { default as Loading } from './Loading';
export { default as NoEdit } from './NoEdit';
export { default as Pencil } from './Pencil';
export { default as Plus } from './Plus';
export { default as SampleDetailsDark } from './SampleDetailsDark';
export { default as SampleDetailsLight } from './SampleDetailsLight';
export { default as Share } from './Share';
Expand Down
49 changes: 47 additions & 2 deletions packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import { DocumentationContainer } from '../../core/components/docs/Documentation
import {
CheckIcon,
Download,
Plus,
FilledButton,
Filter as FilterIcon,
FloatingButton,
H5,
Table,
} from '@veupathdb/coreui';
Expand Down Expand Up @@ -69,9 +71,10 @@ import { useLoginCallbacks } from '../../workspace/sharing/hooks';
import NameAnalysis from '../../workspace/sharing/NameAnalysis';
import NotesTab from '../../workspace/NotesTab';
import ConfirmShareAnalysis from '../../workspace/sharing/ConfirmShareAnalysis';
import { useHistory } from 'react-router';
import { useHistory, useRouteMatch } from 'react-router';

import { uniq } from 'lodash';
import Path from 'path';
import DownloadTab from '../../workspace/DownloadTab';
import { RecordController } from '@veupathdb/wdk-client/lib/Controllers';
import {
Expand All @@ -87,7 +90,6 @@ import {
import { leastAncestralEntity } from '../../core/utils/data-element-constraints';
import { getDefaultOverlayConfig } from './utils/defaultOverlayConfig';
import { AllAnalyses } from '../../workspace/AllAnalyses';
import { getStudyId } from '@veupathdb/study-data-access/lib/shared/studies';
import { isSavedAnalysis } from '../../core/utils/analysis';
import {
MapTypeConfigurationMenu,
Expand Down Expand Up @@ -115,6 +117,7 @@ import { DraggablePanelCoordinatePair } from '@veupathdb/coreui/lib/components/c
import _ from 'lodash';

import EZTimeFilter from './EZTimeFilter';
import AnalysisNameDialog from '../../workspace/AnalysisNameDialog';

enum MapSideNavItemLabels {
Download = 'Download',
Expand Down Expand Up @@ -717,6 +720,23 @@ function MapAnalysisImpl(props: ImplProps) {

const filteredEntities = uniq(filters?.map((f) => f.entityId));

const [isAnalysisNameDialogOpen, setIsAnalysisNameDialogOpen] =
useState(false);
const { url: urlRouteMatch } = useRouteMatch();
const redirectURL = studyId
? urlRouteMatch.endsWith(studyId)
? `/workspace/${urlRouteMatch}/new`
: Path.resolve(urlRouteMatch, '../new')
: null;
const redirectToNewAnalysis = useCallback(() => {
if (redirectURL) {
history.push(redirectURL);
// push() alone doesn't seem to work in this context; the URL changes,
// but the page doesn't load, so we force a refresh
history.go(0);
}
}, [history, redirectURL]);

const sideNavigationButtonConfigurationObjects: SideNavigationItemConfigurationObject[] =
[
{
Expand Down Expand Up @@ -1071,6 +1091,31 @@ function MapAnalysisImpl(props: ImplProps) {
maxWidth: '1500px',
}}
>
{analysisId && redirectToNewAnalysis ? (
<div style={{ float: 'right' }}>
<FloatingButton
text="Create new analysis"
icon={Plus}
onPress={
analysisState.analysis?.displayName ===
DEFAULT_ANALYSIS_NAME
? () => setIsAnalysisNameDialogOpen(true)
: redirectToNewAnalysis
}
/>
</div>
) : (
<></>
)}
{analysisState.analysis && (
<AnalysisNameDialog
isOpen={isAnalysisNameDialogOpen}
setIsOpen={setIsAnalysisNameDialogOpen}
initialAnalysisName={analysisState.analysis.displayName}
setAnalysisName={analysisState.setName}
redirectToNewAnalysis={redirectToNewAnalysis}
/>
)}
<AllAnalyses
analysisClient={analysisClient}
analysisState={
Expand Down
33 changes: 0 additions & 33 deletions packages/libs/eda/src/lib/workspace/AllAnalyses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
AnalysisClient,
AnalysisState,
AnalysisSummary,
DEFAULT_ANALYSIS_NAME,
StudyRecord,
useAnalysisList,
usePinnedAnalyses,
Expand All @@ -51,7 +50,6 @@ import {
makeCurrentProvenanceString,
makeOnImportProvenanceString,
} from '../core/utils/analysis';
import { AnalysisNameDialog } from './AnalysisNameDialog';
import { convertISOToDisplayFormat } from '../core/utils/date-conversion';
import ShareFromAnalysesList from './sharing/ShareFromAnalysesList';
import { Checkbox, Toggle, colors } from '@veupathdb/coreui';
Expand Down Expand Up @@ -128,8 +126,6 @@ export function AllAnalyses(props: Props) {
const history = useHistory();
const location = useLocation();
const classes = useStyles();
const [isAnalysisNameDialogOpen, setIsAnalysisNameDialogOpen] =
useState(false);
const analysis = analysisState?.analysis;
const activeAnalysisId = getAnalysisId(analysis);
const studyId = studyRecord ? getStudyId(studyRecord) : null;
Expand Down Expand Up @@ -345,24 +341,6 @@ export function AllAnalyses(props: Props) {
selectedAnalyses.has(analysis.analysisId),
},
actions: [
{
element:
activeAnalysisId && redirectToNewAnalysis ? (
<Button
type="button"
startIcon={<Icon color="action" className="fa fa-plus" />}
onClick={
analysis && analysis.displayName === DEFAULT_ANALYSIS_NAME
? () => setIsAnalysisNameDialogOpen(true)
: redirectToNewAnalysis
}
>
Create new analysis
</Button>
) : (
<></>
),
},
{
element: (
<Button
Expand Down Expand Up @@ -684,8 +662,6 @@ export function AllAnalyses(props: Props) {
user,
studyId,
activeAnalysisId,
analysis,
redirectToNewAnalysis,
]
);

Expand Down Expand Up @@ -757,15 +733,6 @@ export function AllAnalyses(props: Props) {
</Mesa.Mesa>
) : null}
</div>
{analysis && (
<AnalysisNameDialog
isOpen={isAnalysisNameDialogOpen}
setIsOpen={setIsAnalysisNameDialogOpen}
initialAnalysisName={analysis.displayName}
setAnalysisName={analysisState.setName}
redirectToNewAnalysis={redirectToNewAnalysis}
/>
)}
</>
);
}
2 changes: 1 addition & 1 deletion packages/libs/eda/src/lib/workspace/AnalysisNameDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface AnalysisNameDialogProps {
redirectToNewAnalysis: () => void;
}

export function AnalysisNameDialog({
export default function AnalysisNameDialog({
isOpen,
setIsOpen,
initialAnalysisName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Path from 'path';
import { H3, Table, FloatingButton } from '@veupathdb/coreui';

import { safeHtml } from '@veupathdb/wdk-client/lib/Utils/ComponentUtils';
import { AnalysisNameDialog } from './AnalysisNameDialog';
import AnalysisNameDialog from './AnalysisNameDialog';
import AddIcon from '@material-ui/icons/Add';

// Hooks
Expand Down

0 comments on commit 31293ab

Please sign in to comment.