Skip to content

Commit

Permalink
feat(form-admin-app): support navigation to next result
Browse files Browse the repository at this point in the history
  • Loading branch information
tzuge committed Jan 28, 2025
1 parent c1184f9 commit b625d44
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
15 changes: 11 additions & 4 deletions apps/form-admin-app/src/app/components/DetailsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ const DetailsLayoutContainer = styled.div`
right: 0;
display: flex;
flex-direction: column;
& > * {
flex: 1
}
& > :first-child {
background: var(--goa-color-greyscale-100);
border-bottom: 1px solid var(--goa-color-greyscale-200);
flex: 0;
}
& > :first-child [trailingicon='arrow-forward'] {
margin-left: auto;
}
`;

interface DetailsLayoutProps {
initialized: boolean;
navButtons?: ReactNode;
nextTo?: string;
header: ReactNode;
children: ReactNode;
actionsForm?: ReactNode;
Expand All @@ -33,6 +34,7 @@ interface DetailsLayoutProps {
export const DetailsLayout: FunctionComponent<DetailsLayoutProps> = ({
initialized,
navButtons,
nextTo,
header,
children,
actionsForm,
Expand All @@ -42,11 +44,16 @@ export const DetailsLayout: FunctionComponent<DetailsLayoutProps> = ({
return (
<DetailsLayoutContainer>
<div>
<GoAButtonGroup alignment="start" mt="s" ml="s">
<GoAButtonGroup alignment="start" mt="s" ml="s" mr="s">
<GoAButton type="secondary" leadingIcon="arrow-back" onClick={() => navigate(-1)}>
Back
</GoAButton>
{navButtons}
{nextTo && (
<GoAButton type="secondary" trailingIcon="arrow-forward" onClick={() => navigate(nextTo)}>
Next
</GoAButton>
)}
</GoAButtonGroup>
{header}
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/form-admin-app/src/app/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const TabContainer = styled.div`
display: flex;
flex-direction: column;
min-height: 0;
flex: 1;
& > .heading {
flex: 0;
border-bottom: 1px solid var(--goa-color-greyscale-100);
Expand Down
3 changes: 2 additions & 1 deletion apps/form-admin-app/src/app/containers/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const Form = () => {
const [showArchiveConfirm, setShowArchiveConfirm] = useState(false);

const definition = useSelector(definitionSelector);
const form = useSelector(formSelector);
const { form, next } = useSelector(formSelector);
const files = useSelector(formFilesSelector);
const topic = useSelector((state: AppState) => topicSelector(state, form?.urn));

Expand Down Expand Up @@ -88,6 +88,7 @@ export const Form = () => {
</PropertiesContainer>
)
}
nextTo={next && `../forms/${next}`}
>
<Tabs>
<Tab heading="Form">
Expand Down
3 changes: 2 additions & 1 deletion apps/form-admin-app/src/app/containers/FormSubmission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const FormSubmission = () => {
const { submissionId } = useParams();
const busy = useSelector(formBusySelector);
const definition = useSelector(definitionSelector);
const submission = useSelector(submissionSelector);
const { submission, next } = useSelector(submissionSelector);
const files = useSelector(submissionFilesSelector);
const draft = useSelector(dispositionDraftSelector);

Expand All @@ -54,6 +54,7 @@ export const FormSubmission = () => {
</GoAButton>
)
}
nextTo={next && `../submissions/${next}`}
header={
submission && (
<PropertiesContainer>
Expand Down
18 changes: 14 additions & 4 deletions apps/form-admin-app/src/app/state/form.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,26 +990,36 @@ export const submissionsSelector = createSelector(
export const formSelector = createSelector(
(state: AppState) => state.form.forms,
(state: AppState) => state.form.selectedForm,
(forms, selected) => forms[selected]
(state: AppState) => state.form.results.forms,
(forms, selected, results) => {
const selectedIndex = results.indexOf(selected);
const next = selectedIndex >= 0 ? results[selectedIndex + 1] : undefined;
return { form: forms[selected], next };
}
);

export const formFilesSelector = createSelector(
formSelector,
(state: AppState) => state.file.metadata,
(form, metadata) =>
({ form }, metadata) =>
Object.entries(form?.files || {}).reduce((files, [key, urn]) => ({ ...files, [key]: metadata[urn] }), {})
);

export const submissionSelector = createSelector(
(state: AppState) => state.form.submissions,
(state: AppState) => state.form.selectedSubmission,
(submissions, selected) => submissions[selected]
(state: AppState) => state.form.results.submissions,
(submissions, selected, results) => {
const selectedIndex = results.indexOf(selected);
const next = selectedIndex >= 0 ? results[selectedIndex + 1] : undefined;
return { submission: submissions[selected], next };
}
);

export const submissionFilesSelector = createSelector(
(state: AppState) => state.file.metadata,
submissionSelector,
(metadata, submission) =>
(metadata, { submission }) =>
Object.entries(submission?.formFiles || {}).reduce((files, [key, urn]) => ({ ...files, [key]: metadata[urn] }), {})
);

Expand Down

0 comments on commit b625d44

Please sign in to comment.