-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from aehrc/feature/collapsible-form
Feature/collapsible form
- Loading branch information
Showing
25 changed files
with
781 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
apps/smart-forms-app/src/components/Button/ReauthenticateButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Button } from '@mui/material'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
function ReauthenticateButton() { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<Button | ||
variant="contained" | ||
sx={{ mt: 4 }} | ||
onClick={() => { | ||
navigate('/'); | ||
}} | ||
data-test="button-unlaunched-state"> | ||
Re-authenticate | ||
</Button> | ||
); | ||
} | ||
|
||
export default ReauthenticateButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2023 Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import CenteredWrapper from '../../components/Wrapper/CenteredWrapper.tsx'; | ||
import { Stack, Typography } from '@mui/material'; | ||
import UnlaunchedButton from '../../components/Button/UnlaunchedButton.tsx'; | ||
import useConfigStore from '../../stores/useConfigStore.ts'; | ||
import ReauthenticateButton from '../../components/Button/ReauthenticateButton.tsx'; | ||
|
||
function NotFound() { | ||
const smartClient = useConfigStore((state) => state.smartClient); | ||
|
||
const isNotLaunched = !smartClient; | ||
|
||
const authSessionFound = isNotLaunched && sessionStorage.getItem('authorised') === 'true'; | ||
|
||
return ( | ||
<CenteredWrapper> | ||
<Stack rowGap={2}> | ||
<Typography variant="h3">Error 404</Typography> | ||
<Typography fontSize={13}> | ||
{authSessionFound | ||
? "We couldn't find the page you were looking for, but we detected a recent auth session. You would need to be re-authenticated. Do you want to try re-authenticating?" | ||
: "We couldn't find the page you were looking for. Do you want to go back to the home page?"} | ||
</Typography> | ||
</Stack> | ||
{authSessionFound ? <ReauthenticateButton /> : <UnlaunchedButton />} | ||
</CenteredWrapper> | ||
); | ||
} | ||
|
||
export default NotFound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...s-app/src/features/renderer/components/FormPage/Collapsible/FormBodySingleCollapsible.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2023 Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { ReactNode } from 'react'; | ||
import { memo } from 'react'; | ||
import { | ||
Accordion, | ||
AccordionDetails, | ||
AccordionSummary, | ||
Box, | ||
Tooltip, | ||
Typography | ||
} from '@mui/material'; | ||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
import { getContextDisplays } from '../../../utils/tabs.ts'; | ||
import type { QuestionnaireItem } from 'fhir/r4'; | ||
import { getShortText } from '../../../utils/itemControl.ts'; | ||
import GroupHeadingIcon from '../QFormComponents/GroupItem/GroupHeadingIcon.tsx'; | ||
|
||
interface FormBodySingleCollapsibleProps { | ||
qItem: QuestionnaireItem; | ||
index: number; | ||
selectedIndex: number; | ||
onToggleExpand: (index: number) => void; | ||
children: ReactNode; | ||
} | ||
|
||
const FormBodySingleCollapsible = memo(function FormBodySingleCollapsible( | ||
props: FormBodySingleCollapsibleProps | ||
) { | ||
const { qItem, index, selectedIndex, onToggleExpand, children } = props; | ||
|
||
const contextDisplayItems = getContextDisplays(qItem); | ||
|
||
const collapsibleLabel = getShortText(qItem) ?? qItem.text ?? ''; | ||
|
||
return ( | ||
<Accordion | ||
expanded={selectedIndex === index} | ||
TransitionProps={{ unmountOnExit: true }} | ||
onChange={() => onToggleExpand(index)}> | ||
<AccordionSummary | ||
expandIcon={ | ||
<Tooltip title={'Expand'}> | ||
<ExpandMoreIcon /> | ||
</Tooltip> | ||
}> | ||
<Box display="flex" alignItems="center" justifyContent="space-between" width="100%" mr={3}> | ||
<Typography variant="subtitle2">{collapsibleLabel}</Typography> | ||
<Box display="flex" columnGap={0.5}> | ||
{contextDisplayItems.map((item) => { | ||
return <GroupHeadingIcon key={item.linkId} displayItem={item} />; | ||
})} | ||
</Box> | ||
</Box> | ||
</AccordionSummary> | ||
<AccordionDetails>{children}</AccordionDetails> | ||
</Accordion> | ||
); | ||
}); | ||
|
||
export default FormBodySingleCollapsible; |
59 changes: 59 additions & 0 deletions
59
...rc/features/renderer/components/FormPage/Collapsible/FormBodySingleCollapsibleWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2023 Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4'; | ||
import GroupItem from '../QFormComponents/GroupItem/GroupItem.tsx'; | ||
import FormBodySingleCollapsible from './FormBodySingleCollapsible.tsx'; | ||
import type { PropsWithQrItemChangeHandler } from '../../../types/renderProps.interface.ts'; | ||
import useHidden from '../../../hooks/useHidden.ts'; | ||
|
||
interface FormBodySingleCollapsibleProps | ||
extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem> { | ||
qItem: QuestionnaireItem; | ||
qrItem: QuestionnaireResponseItem; | ||
index: number; | ||
selectedIndex: number; | ||
onToggleExpand: (index: number) => void; | ||
} | ||
|
||
function FormBodySingleCollapsibleWrapper(props: FormBodySingleCollapsibleProps) { | ||
const { qItem, qrItem, index, selectedIndex, onToggleExpand, onQrItemChange } = props; | ||
|
||
const itemIsHidden = useHidden(qItem); | ||
if (itemIsHidden) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<FormBodySingleCollapsible | ||
key={qItem.linkId} | ||
qItem={qItem} | ||
index={index} | ||
selectedIndex={selectedIndex} | ||
onToggleExpand={onToggleExpand}> | ||
<GroupItem | ||
qItem={qItem} | ||
qrItem={qrItem} | ||
isRepeated={true} | ||
groupCardElevation={1} | ||
onQrItemChange={onQrItemChange} | ||
/> | ||
</FormBodySingleCollapsible> | ||
); | ||
} | ||
|
||
export default FormBodySingleCollapsibleWrapper; |
Oops, something went wrong.