-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/929/js custom question pages #1193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from 8 commits
4ac4b1d
1be811d
2276ab8
de224be
63910c7
0415056
e9a2489
874d572
6aa50e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import Loading from '@/components/Loading'; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this new component just in case, so page loads can fall back to this if it takes longer than 300ms
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. This is a good idea |
||
|
|
||
| {/** Next.js only shows this if it takes longer than ~300ms to load */ } | ||
| export default function LocaleLoading() { | ||
| return <Loading />; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,7 +88,7 @@ import { | |
| import { | ||
| isOptionsType, | ||
| getOverrides, | ||
| } from './hooks/useEditQuestion'; | ||
| } from '@/app/hooks/useEditQuestion'; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the |
||
| import styles from './questionEdit.module.scss'; | ||
|
|
||
| const QuestionEdit = () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,15 @@ import { | |
| Text | ||
| } from "react-aria-components"; | ||
|
|
||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This page was updated to pass in new props to the shared |
||
| // GraphQL | ||
| import { useMutation, useQuery } from '@apollo/client/react'; | ||
| import { | ||
| AddQuestionDocument, | ||
| QuestionsDisplayOrderDocument, | ||
| } from '@/generated/graphql'; | ||
|
|
||
|
|
||
| // Components | ||
| import PageHeader from "@/components/PageHeader"; | ||
| import { ContentContainer, LayoutContainer, } from '@/components/Container'; | ||
|
|
@@ -30,6 +39,17 @@ import { QuestionFormatInterface } from '@/app/types'; | |
| import styles from './newQuestion.module.scss'; | ||
| import { getQuestionTypes } from "@/utils/questionTypeHandlers"; | ||
|
|
||
| const TemplateQuestionBreadcrumbs = ({ templateId, sectionId, Global }: { templateId: string; sectionId: string; Global: (key: string, values?: Record<string, string | number>) => string }) => { | ||
| return ( | ||
| <Breadcrumbs> | ||
| <Breadcrumb><Link href={routePath('projects.index')}>{Global('breadcrumbs.home')}</Link></Breadcrumb> | ||
| <Breadcrumb><Link href={routePath('template.index', { templateId })}>{Global('breadcrumbs.templates')}</Link></Breadcrumb> | ||
| <Breadcrumb><Link href={routePath('template.show', { templateId })}>{Global('breadcrumbs.editTemplate')}</Link></Breadcrumb> | ||
| <Breadcrumb><Link href={routePath('template.q.new', { templateId }, { section_id: sectionId, step: 1 })}>{Global('breadcrumbs.selectQuestionType')}</Link></Breadcrumb> | ||
| <Breadcrumb>{Global('breadcrumbs.question')}</Breadcrumb> | ||
| </Breadcrumbs > | ||
| ) | ||
| } | ||
|
|
||
| const QuestionTypeSelectPage: React.FC = () => { | ||
| // Get templateId param | ||
|
|
@@ -58,6 +78,37 @@ const QuestionTypeSelectPage: React.FC = () => { | |
| const Global = useTranslations('Global'); | ||
| const QuestionTypeSelect = useTranslations('QuestionTypeSelectPage'); | ||
|
|
||
| // Initialize add and update question mutations | ||
| const [addQuestionMutation] = useMutation(AddQuestionDocument); | ||
|
|
||
| // Query request for questions to calculate max displayOrder | ||
| const { data: questionDisplayOrders } = useQuery(QuestionsDisplayOrderDocument, { | ||
| variables: { | ||
| sectionId: Number(sectionId) | ||
| }, | ||
| skip: !sectionId | ||
| }) | ||
|
|
||
| // Calculate the display order of the new question based on the last displayOrder number | ||
| const getDisplayOrder = useCallback(() => { | ||
| if (!questionDisplayOrders?.questions?.length) { | ||
| return 1; | ||
| } | ||
|
|
||
| // Filter out null/undefined questions and handle missing displayOrder | ||
| const validDisplayOrders = questionDisplayOrders.questions | ||
| .map(q => q?.displayOrder) | ||
| .filter((order): order is number => typeof order === 'number'); | ||
|
|
||
| if (validDisplayOrders.length === 0) { | ||
| return 1; | ||
| } | ||
|
|
||
| const maxDisplayOrder = Math.max(...validDisplayOrders); | ||
| return maxDisplayOrder + 1; | ||
| }, [questionDisplayOrders]); | ||
|
|
||
|
|
||
| // Handle the selection of a question type | ||
| const handleSelect = ( | ||
| { | ||
|
|
@@ -247,6 +298,19 @@ const QuestionTypeSelectPage: React.FC = () => { | |
| questionName={selectedQuestionType?.questionName ?? null} | ||
| questionJSON={selectedQuestionType?.questionJSON ?? ''} | ||
| sectionId={sectionId ? sectionId : ''} | ||
| breadcrumbs={<TemplateQuestionBreadcrumbs templateId={templateId} sectionId={sectionId} Global={Global} />} | ||
| backUrl={routePath('template.q.new', { templateId }, { section_id: sectionId, step: 1 })} | ||
| successUrl={routePath('template.show', { templateId })} | ||
| onSave={async (commonFields) => { | ||
| const input = { | ||
| templateId: Number(templateId), | ||
| sectionId: Number(sectionId), | ||
| displayOrder: getDisplayOrder(), | ||
| isDirty: true, | ||
| ...commonFields, | ||
| }; | ||
| await addQuestionMutation({ variables: { input } }); | ||
| }} | ||
| /> | ||
| </> | ||
| )} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import FormInput from '@/components/Form/FormInput'; | |
|
|
||
| import { debounce } from '@/hooks/debounce'; | ||
| import { useQueryStep } from '@/app/[locale]/template/create/useQueryStep'; | ||
| import Loading from '@/components/Loading'; | ||
|
|
||
| const TemplateCreatePage: React.FC = () => { | ||
| const router = useRouter(); | ||
|
|
@@ -68,7 +69,7 @@ const TemplateCreatePage: React.FC = () => { | |
|
|
||
| // TODO: Need to implement a shared loading component | ||
| if (step === null) { | ||
| return <div>...{Global('messaging.loading')}</div> | ||
| return <Loading />; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
| } | ||
|
|
||
| return ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the
affiliationName.displayNameto theMeQueryfor the QuestionPreview so that we could be explicit about which Org added the guidance, therefore I was required to add it to some unit test mocks.