Skip to content

Commit

Permalink
Merge pull request #129 from DiSSCo/RefactorDigitalSpecimenTour
Browse files Browse the repository at this point in the history
Refactor digital specimen tour
  • Loading branch information
TomDijkema authored Nov 18, 2024
2 parents 2570f8f + 347d3bd commit 07c17c3
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 14 deletions.
20 changes: 16 additions & 4 deletions src/components/digitalSpecimen/DigitalSpecimen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getDigitalSpecimen, setDigitalSpecimen } from 'redux-store/DigitalSpeci
/* Import Types */
import { DigitalMedia } from 'app/types/DigitalMedia';
import { DigitalSpecimen as DigitalSpecimenType } from 'app/types/DigitalSpecimen';
import { TourTopic } from 'app/Types';

/* Import Sources */
import DigitalSpecimenSchema from 'sources/dataModel/digitalSpecimen.json';
Expand All @@ -27,6 +28,7 @@ import GetDigitalSpecimenMasJobRecords from 'api/digitalSpecimen/GetDigitalSpeci
import ScheduleDigitalSpecimenMas from "api/digitalSpecimen/ScheduleDigitalSpecimenMas";

/* Import Components */
import DigitalSpecimenTourSteps from './tourSteps/DigitalSpecimenTourSteps';
import { ContentBlock, IdCard, TopBar } from './components/DigitalSpecimenComponents';
import { AnnotationSidePanel, BreadCrumbs, Header, Footer } from 'components/elements/Elements';
import { LoadingScreen } from 'components/elements/customUI/CustomUI';
Expand All @@ -46,6 +48,11 @@ const DigitalSpecimen = () => {
const digitalSpecimen = useAppSelector(getDigitalSpecimen);
const [digitalSpecimenDigitalMedia, setDigitalSpecimenDigitalMedia] = useState<DigitalMedia[] | undefined>();
const [annotationMode, setAnnotationMode] = useState<boolean>(false);
const [selectedTabIndex, setSelectedTabIndex] = useState<number>(0);
const tourTopics: TourTopic[] = [{
name: 'digitalSpecimen',
title: 'About this page'
}];

/* OnLoad, fetch digital specimen data */
fetch.FetchMultiple({
Expand Down Expand Up @@ -104,7 +111,7 @@ const DigitalSpecimen = () => {
<Col className={`${digitalSpecimenBodyClass} h-100 tr-smooth`}>
<div className={`${digitalSpecimenContentClass} h-100 d-flex flex-column tr-smooth`}>
{/* Render header*/}
<Header />
<Header tourTopics={tourTopics} />

{/* Digital specimen page body */}
<Container fluid className="flex-grow-1 overflow-hidden my-5">
Expand All @@ -121,7 +128,7 @@ const DigitalSpecimen = () => {
</Col>
</Row>
{/* Top bar */}
<Row className="mt-2">
<Row className="tourDigitalSpecimen2 mt-2">
<Col>
<TopBar digitalSpecimen={digitalSpecimen}
annotationMode={annotationMode}
Expand All @@ -133,18 +140,21 @@ const DigitalSpecimen = () => {
<Row className="flex-grow-1 overflow-hidden mt-4">
{/* ID card */}
<Col lg={{ span: 3 }}
className="h-100"
className="tourDigitalSpecimen5 h-100"
>
<IdCard digitalSpecimen={digitalSpecimen}
digitalSpecimenDigitalMedia={digitalSpecimenDigitalMedia}
/>
</Col>
{/* Content block */}
<Col lg={{ span: 9 }}
className="h-100"
className="tourDigitalSpecimen6 tourDigitalSpecimen7 tourDigitalSpecimen8 tourDigitalSpecimen9 tourDigitalSpecimen10
tourDigitalSpecimen11 tourDigitalSpecimen12 h-100"
>
<ContentBlock digitalSpecimen={digitalSpecimen}
digitalSpecimenDigitalMedia={digitalSpecimenDigitalMedia}
selectedTabIndex={selectedTabIndex}
SetSelectedTabIndex={setSelectedTabIndex}
/>
</Col>
</Row>
Expand Down Expand Up @@ -179,6 +189,8 @@ const DigitalSpecimen = () => {
}
</Row>
</Container>

<DigitalSpecimenTourSteps SetSelectedTabIndex={setSelectedTabIndex} />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* Import Dependencies */
import { isEmpty } from 'lodash';
import { useState } from 'react';

/* Import Types */
import { DigitalMedia } from 'app/types/DigitalMedia';
Expand All @@ -14,21 +13,24 @@ import { Tabs } from 'components/elements/customUI/CustomUI';
/* Props Type */
type Props = {
digitalSpecimen: DigitalSpecimen,
digitalSpecimenDigitalMedia: DigitalMedia[] | undefined
digitalSpecimenDigitalMedia: DigitalMedia[] | undefined,
selectedTabIndex: number,
SetSelectedTabIndex: Function
};


/**
* Component that renders the content block on the digital specimen page
* @param digitalSpecimen The selected digital specimen
* @param digitalSpecimenDigitalMedia The digital media attached to the digital specimen
* @param selectedTabIndex The selected index for the digital specimen tabs
* @param SetSelectedTabIndex Function to set the selected tab index
* @returns JSX Component
*/
const ContentBlock = (props: Props) => {
const { digitalSpecimen, digitalSpecimenDigitalMedia } = props;
const { digitalSpecimen, digitalSpecimenDigitalMedia, selectedTabIndex, SetSelectedTabIndex } = props;

/* Base variables */
const [selectedTabIndex, setSelectedTabIndex] = useState<number>(0);
const tabs = {
'digitalSpecimen': <DigitalSpecimenOverview digitalSpecimen={digitalSpecimen} />,
...(digitalSpecimenDigitalMedia && !isEmpty(digitalSpecimenDigitalMedia) && {
Expand All @@ -51,7 +53,7 @@ const ContentBlock = (props: Props) => {
}}
tabClassName="fs-5 px-3"
tabPanelClassName="h-100 overflow-y-scroll overflow-x-hidden"
SetSelectedIndex={(index: number) => setSelectedTabIndex(index)}
SetSelectedIndex={(index: number) => SetSelectedTabIndex(index)}
/>
</div>
);
Expand Down
6 changes: 4 additions & 2 deletions src/components/digitalSpecimen/components/topBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ const TopBar = (props: Props) => {
</span>
</Col>
{versionDropdownItems &&
<Col lg="auto">
<Col lg="auto"
className="tourDigitalSpecimen3"
>
<Dropdown items={versionDropdownItems}
selectedItem={{
label: fetch.loading ? 'Loading..' : `Version ${digitalSpecimen['ods:version']}`,
Expand All @@ -151,7 +153,7 @@ const TopBar = (props: Props) => {
}
</Row>
</Col>
<Col>
<Col className="tourDigitalSpecimen4">
<TopBarActions actionDropdownItems={actionDropdownItems}
annotationMode={annotationMode}
ToggleAnnotationSidePanel={ToggleAnnotationSidePanel}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* Import Dependencies */
import { Steps } from 'intro.js-react';

/* Import Config */
import StepsConfig from 'app/config/StepsConfig';

/* Import Hooks */
import { useAppSelector, useAppDispatch } from 'app/Hooks';

/* Import Store */
import { getTourTopic, setTourTopic } from 'redux-store/GlobalSlice';

/* Import Sources */
import DigitalSpecimenTourStepsText from 'sources/tourText/digitalSpecimen.json';


/* Props Type */
type Props = {
SetSelectedTabIndex: Function
};


/**
* Component that renders the tour steps for the digital specimen page
* @param SetSelectedTabIndex Function to set the selected tab index
* @returns JSX Component
*/
const DigitalSpecimenTourSteps = (props: Props) => {
const { SetSelectedTabIndex } = props;

/* Hooks */
const dispatch = useAppDispatch();

/* Base variables */
const tourTopic = useAppSelector(getTourTopic);
const digitalSpecimenSteps = DigitalSpecimenTourStepsText.digitalSpecimen;
const { options } = StepsConfig();
let steps: {
intro: string,
element?: string
}[] = [];

/* Construct Intro.js steps for digital specimen page */
digitalSpecimenSteps.forEach((step, index) => {
steps.push({
intro: step,
element: `.tourDigitalSpecimen${index + 1}`
});
});

/**
* Function that checks what to do on a step change
* @param nextIndex The next (selected) index in the step chain
* @param resolve Function to resolve the step promise
*/
const OnStepChange = (nextIndex: number, resolve: Function) => {
const nextIndexToTabIndexMap = {
6: 0,
7: 1,
8: 2,
9: 3,
10: 4,
11: 5
};

if (Object.keys(nextIndexToTabIndexMap).includes(`${nextIndex}`)) {
/* On step 7: set tab to digital specimen */
SetSelectedTabIndex(0);

resolve();
} else {
resolve();
}
};

return (
<Steps enabled={tourTopic === 'digitalSpecimen'}
steps={steps}
initialStep={0}
onBeforeChange={(nextIndex) => {
return new Promise((resolve) => {
OnStepChange(nextIndex, resolve);
});
}}
onStart={() => SetSelectedTabIndex(0)}
onExit={() => {
SetSelectedTabIndex(0);
dispatch(setTourTopic(undefined));
}}
options={options}
/>
);
};

export default DigitalSpecimenTourSteps;
4 changes: 2 additions & 2 deletions src/components/search/tourSteps/CompareTourSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Props = {


/**
* Component that renders the tour steps for the homepage
* Component that renders the tour steps for the compare functionality on the search page
* @param pagination The pagination object used to index the digital specimen results
* @returns JSX Component
*/
Expand All @@ -47,7 +47,7 @@ const CompareTourSteps = (props: Props) => {
element?: string
}[] = [];

/* Construct Intro.js steps for Homepage */
/* Construct Intro.js steps for compare functionality on search page */
compareSteps.forEach((step, index) => {
steps.push({
intro: step,
Expand Down
2 changes: 1 addition & 1 deletion src/components/search/tourSteps/SearchTourSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const SearchTourSteps = (props: Props) => {
element?: string
}[] = [];

/* Construct Intro.js steps for Homepage */
/* Construct Intro.js steps for Search page */
searchSteps.forEach((step, index) => {
steps.push({
intro: step,
Expand Down
Loading

0 comments on commit 07c17c3

Please sign in to comment.