Skip to content
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

🐛 Intitial values for stakeholders #1389

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
identity?: Ref;
createTime?: string;
createUser?: string;
id: any;

Check warning on line 208 in client/src/app/api/models.ts

View workflow job for this annotation

GitHub Actions / unit-test (18.x)

Unexpected any. Specify a different type
enabled: boolean;
}

Expand Down Expand Up @@ -362,7 +362,7 @@

export interface TaskgroupTask {
name: string;
data: any;

Check warning on line 365 in client/src/app/api/models.ts

View workflow job for this annotation

GitHub Actions / unit-test (18.x)

Unexpected any. Specify a different type
application: Ref;
}

Expand Down Expand Up @@ -709,8 +709,8 @@
description: string;
status: AssessmentStatus;
risk: Risk;
stakeholders: Ref[];
stakeholderGroups: Ref[];
stakeholders?: Ref[];
stakeholderGroups?: Ref[];
}
export interface CategorizedTag {
category: TagCategory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Assessment,
AssessmentStatus,
Question,
Ref,
Section,
} from "@app/api/models";
import { CustomWizardFooter } from "../custom-wizard-footer";
Expand All @@ -35,6 +36,8 @@ import { Paths } from "@app/Paths";
import { yupResolver } from "@hookform/resolvers/yup";
import { AssessmentStakeholdersForm } from "../assessment-stakeholders-form/assessment-stakeholders-form";
import useIsArchetype from "@app/hooks/useIsArchetype";
import { useFetchStakeholderGroups } from "@app/queries/stakeholdergoups";
import { useFetchStakeholders } from "@app/queries/stakeholders";

export const SAVE_ACTION_KEY = "saveAction";

Expand Down Expand Up @@ -67,6 +70,8 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
}) => {
const isArchetype = useIsArchetype();
const queryClient = useQueryClient();
const { stakeholderGroups } = useFetchStakeholderGroups();
const { stakeholders } = useFetchStakeholders();

const onHandleUpdateAssessmentSuccess = () => {
queryClient.invalidateQueries([
Expand Down Expand Up @@ -127,13 +132,11 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
}, [assessment]);

useEffect(() => {
console.log("asssessment.stakeholders", assessment?.stakeholders);
methods.reset({
stakeholders:
assessment?.stakeholders.map((stakeholder) => stakeholder.name) || [],
stakeholders: assessment?.stakeholders?.map((sh) => sh.name).sort() ?? [],
stakeholderGroups:
assessment?.stakeholderGroups.map(
(stakeholderGroup) => stakeholderGroup.name
) || [],
assessment?.stakeholderGroups?.map((sg) => sg.name).sort() ?? [],
// comments: initialComments,
questions: initialQuestions,
[SAVE_ACTION_KEY]: SAVE_ACTION_VALUE.SAVE_AS_DRAFT,
Expand All @@ -149,11 +152,9 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
defaultValues: useMemo(() => {
return {
stakeholders:
assessment?.stakeholders.map((stakeholder) => stakeholder.name) || [],
assessment?.stakeholders?.map((sh) => sh.name).sort() ?? [],
stakeholderGroups:
assessment?.stakeholderGroups.map(
(stakeholderGroup) => stakeholderGroup.name
) || [],
assessment?.stakeholderGroups?.map((sg) => sg.name).sort() ?? [],
// comments: initialComments,
questions: initialQuestions,
[SAVE_ACTION_KEY]: SAVE_ACTION_VALUE.SAVE_AS_DRAFT,
Expand Down Expand Up @@ -276,6 +277,25 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
const assessmentStatus: AssessmentStatus = "started";
const payload: Assessment = {
...assessment,
stakeholders:
values.stakeholders === undefined
? undefined
: (values.stakeholders
.map((name) => stakeholders.find((s) => s.name === name))
.map<Ref | undefined>((sh) =>
!sh ? undefined : { id: sh.id, name: sh.name }
)
.filter(Boolean) as Ref[]),

stakeholderGroups:
values.stakeholderGroups === undefined
? undefined
: (values.stakeholderGroups
.map((name) => stakeholderGroups.find((s) => s.name === name))
.map<Ref | undefined>((sg) =>
!sg ? undefined : { id: sg.id, name: sg.name }
)
.filter(Boolean) as Ref[]),
sections,
status: assessmentStatus,
};
Expand Down Expand Up @@ -320,6 +340,25 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({

const payload: Assessment = {
...assessment,
stakeholders:
values.stakeholders === undefined
? undefined
: (values.stakeholders
.map((name) => stakeholders.find((s) => s.name === name))
.map<Ref | undefined>((sh) =>
!sh ? undefined : { id: sh.id, name: sh.name }
)
.filter(Boolean) as Ref[]),

stakeholderGroups:
values.stakeholderGroups === undefined
? undefined
: (values.stakeholderGroups
.map((name) => stakeholderGroups.find((s) => s.name === name))
.map<Ref | undefined>((sg) =>
!sg ? undefined : { id: sg.id, name: sg.name }
)
.filter(Boolean) as Ref[]),
sections,
status: assessmentStatus,
};
Expand Down Expand Up @@ -367,6 +406,25 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({

const payload: Assessment = {
...assessment,
stakeholders:
values.stakeholders === undefined
? undefined
: (values.stakeholders
.map((name) => stakeholders.find((s) => s.name === name))
.map<Ref | undefined>((sh) =>
!sh ? undefined : { id: sh.id, name: sh.name }
)
.filter(Boolean) as Ref[]),

stakeholderGroups:
values.stakeholderGroups === undefined
? undefined
: (values.stakeholderGroups
.map((name) => stakeholderGroups.find((s) => s.name === name))
.map<Ref | undefined>((sg) =>
!sg ? undefined : { id: sg.id, name: sg.name }
)
.filter(Boolean) as Ref[]),
sections,
status: assessmentStatus,
};
Expand Down
Loading