From a9c3824e7814e5150be799a1e9faa40ef7677dcf Mon Sep 17 00:00:00 2001 From: aaronshiel Date: Wed, 7 Feb 2024 22:29:08 -0800 Subject: [PATCH] mentor config lock subjects update --- client/src/api.ts | 3 ++ client/src/components/home/index.tsx | 4 +- client/src/hooks/graphql/use-with-setup.tsx | 2 +- .../use-with-mentor-recommender.tsx | 2 +- client/src/pages/setup.tsx | 2 +- client/src/pages/subjects.tsx | 45 ++++++++++++++++--- client/src/types-gql.ts | 1 + cypress/cypress/e2e/setup.cy.ts | 26 +++++++++-- cypress/cypress/e2e/subjects.cy.ts | 36 +++++++++++++++ cypress/cypress/support/types.ts | 1 + 10 files changed, 109 insertions(+), 13 deletions(-) diff --git a/client/src/api.ts b/client/src/api.ts index 13cfc51e..ce3c155d 100644 --- a/client/src/api.ts +++ b/client/src/api.ts @@ -346,6 +346,7 @@ export async function fetchUsers( mentorConfig{ configId subjects + lockedToSubjects publiclyVisible mentorType orgPermissions{ @@ -1084,6 +1085,7 @@ export async function fetchMentorById( mentorConfig{ configId subjects + lockedToSubjects publiclyVisible mentorType orgPermissions{ @@ -1266,6 +1268,7 @@ export async function fetchMentorConfig( fetchMentorConfig(mentorConfigId:$mentorConfigId){ configId subjects + lockedToSubjects publiclyVisible mentorType orgPermissions{ diff --git a/client/src/components/home/index.tsx b/client/src/components/home/index.tsx index 1ed03b52..055b59cb 100644 --- a/client/src/components/home/index.tsx +++ b/client/src/components/home/index.tsx @@ -276,7 +276,7 @@ function HomePage(props: { ]); useEffect(() => { - const lockedToSubjects = mentorConfig?.subjects.length; + const lockedToSubjects = mentorConfig?.lockedToSubjects; if ( !lockedToConfig || !mentorConfig || @@ -532,7 +532,7 @@ function HomePage(props: { {name} ))} - {mentorConfig?.subjects.length ? undefined : ( + {mentorConfig?.lockedToSubjects ? undefined : ( isAnswerComplete(answer, undefined, state.mentorData.mentorType) ); - if (state.mentorData.mentorConfig?.subjects.length) { + if (state.mentorData.mentorConfig?.lockedToSubjects) { return false; } // mentorData.answers contains complete AND incomplete answers. diff --git a/client/src/pages/setup.tsx b/client/src/pages/setup.tsx index 72e659f0..d9884ba6 100644 --- a/client/src/pages/setup.tsx +++ b/client/src/pages/setup.tsx @@ -266,7 +266,7 @@ function SetupPage(props: { } return ( -
+
({ @@ -109,6 +110,7 @@ function SubjectsPage(props: { isLoading: isMentorLoading, isSaving: isMentorSaving, error: mentorError, + getData, } = useActiveMentor(); const [viewUtteranceSubjects, setViewUtteranceSubjects] = useState(false); @@ -120,6 +122,12 @@ function SubjectsPage(props: { useMentorEdits(); const mentorSubjectIds = editedMentor?.subjects.map((subject) => subject._id) || []; + const mentorConfig: MentorConfig | undefined = getData( + (state) => state.data?.mentorConfig + ); + const [showAllSubjects, setShowAllSubjects] = useState(false); + const filterToConfigSubjects = + mentorConfig && !mentorConfig.lockedToSubjects && !showAllSubjects; const { pageData: subjects, isLoading: isSubjectsLoading, @@ -143,7 +151,13 @@ function SubjectsPage(props: { useEffect(() => { if (viewArchivedSubjects) { - setPreFilter(); + setPreFilter({ + filter: (s) => { + return filterToConfigSubjects + ? mentorConfig.subjects.includes(s._id) + : true; + }, + }); setPostSort({ sort: (a, b) => { if (a.isArchived === b.isArchived) { @@ -157,11 +171,23 @@ function SubjectsPage(props: { }); } else { setPreFilter({ - filter: (s) => !s.isArchived || mentorSubjectIds.includes(s._id), + filter: (s) => { + return ( + (!s.isArchived || mentorSubjectIds.includes(s._id)) && + (filterToConfigSubjects + ? mentorConfig.subjects.includes(s._id) + : true) + ); + }, }); setPostSort(); } - }, [viewArchivedSubjects, mentorSubjectIds.length]); + }, [ + viewArchivedSubjects, + mentorSubjectIds.length, + mentorConfig, + filterToConfigSubjects, + ]); function toggleSubject(subject: Subject) { if (!editedMentor) { @@ -208,7 +234,7 @@ function SubjectsPage(props: { return (
-
+
@@ -275,6 +301,15 @@ function SubjectsPage(props: { })}
+ {mentorConfig && ( + + )}
diff --git a/client/src/types-gql.ts b/client/src/types-gql.ts index 29d40366..2f95de6e 100644 --- a/client/src/types-gql.ts +++ b/client/src/types-gql.ts @@ -56,6 +56,7 @@ export interface OrgPermissionsGQL { export interface MentorConfig { configId: string; subjects: string[]; + lockedToSubjects: boolean; publiclyVisible: boolean; mentorType: MentorType; orgPermissions: OrgPermissionsGQL[]; diff --git a/cypress/cypress/e2e/setup.cy.ts b/cypress/cypress/e2e/setup.cy.ts index 15f4a48e..1e15812d 100644 --- a/cypress/cypress/e2e/setup.cy.ts +++ b/cypress/cypress/e2e/setup.cy.ts @@ -1414,15 +1414,35 @@ describe("Setup", () => { it("Select Subjects slide not shown to mentors with locked subjects", () => { cyMockDefault(cy, { - mentor: videoMentorWithConfig, + mentor: { + ...videoMentorWithConfig, + mentorConfig: { + ...videoMentorWithConfig.mentorConfig, + lockedToSubjects: true, + }, + }, }); - cyVisitSetupScreen(cy, SetupScreen.Select_Subjects); - cy.get("[data-cy=slide-title]").should( + cyVisitSetupScreen(cy, SetupScreen.Welcome); + cy.get("[data-cy=setup-page]").should( "not.contain.text", "Select subjects?" ); }); + it("Select Subjects slide shown to mentors without locked subjects", () => { + cyMockDefault(cy, { + mentor: { + ...videoMentorWithConfig, + mentorConfig: { + ...videoMentorWithConfig.mentorConfig, + lockedToSubjects: false, + }, + }, + }); + cyVisitSetupScreen(cy, SetupScreen.Welcome); + cy.get("[data-cy=setup-page]").should("contain.text", "Select subjects?"); + }); + it("Record required subject slide considers answer as complete if upload in progress", () => { const videoWithConfigAndUnansweredQ: Mentor = { ...completeMentor(videoMentor), diff --git a/cypress/cypress/e2e/subjects.cy.ts b/cypress/cypress/e2e/subjects.cy.ts index 9d692d0c..a9923e65 100644 --- a/cypress/cypress/e2e/subjects.cy.ts +++ b/cypress/cypress/e2e/subjects.cy.ts @@ -16,6 +16,7 @@ import { } from "../support/types"; import { completeSubjectQuestion } from "../support/helpers"; import { login as loginDefault } from "../fixtures/login"; +import { mentorConfig } from "../fixtures/recording/video_mentors"; const mentor: Mentor = { _id: "clintanderson", @@ -361,6 +362,41 @@ describe("Select Subjects", () => { }); }); +describe("mentors with configs", () => { + it("page is not visible to mentors with locked subjects", () => { + // TODO + }); + + it.only("only show subjects that are part of config, with dropdown for others", () => { + cySetup(cy); + cyMockDefault(cy, { + mentor: { + ...mentor, + mentorConfig: { + ...mentorConfig, + subjects: ["background"], + }, + }, + subjects: [allSubjects], + gqlQueries: [ + mockGQL("UpdateMentorSubjects", { me: { updateMentorSubjects: true } }), + ], + }); + cy.visit("/subjects"); + cy.get("[data-cy=subjects]").children().should("have.length", 1); + cy.get("[data-cy=subjects-page]").should("contain.text", "Background"); + cy.get("[data-cy=subjects-page]").should("not.contain.text", "Leadership"); + cy.get("[data-cy=show-all-subjects-button]").click(); + cy.get("[data-cy=subjects]").children().should("have.length", 2); + cy.get("[data-cy=subjects-page]").should("contain.text", "Background"); + cy.get("[data-cy=subjects-page]").should("contain.text", "Leadership"); + cy.get("[data-cy=show-all-subjects-button]").click(); + cy.get("[data-cy=subjects]").children().should("have.length", 1); + cy.get("[data-cy=subjects-page]").should("contain.text", "Background"); + cy.get("[data-cy=subjects-page]").should("not.contain.text", "Leadership"); + }); +}); + describe("Dropdown button list", () => { it("Primary button set to Exit when there are no edits", () => { cySetup(cy); diff --git a/cypress/cypress/support/types.ts b/cypress/cypress/support/types.ts index 2dddb779..9aa057e9 100644 --- a/cypress/cypress/support/types.ts +++ b/cypress/cypress/support/types.ts @@ -99,6 +99,7 @@ export interface OrgPermissionsGQL { export interface MentorConfig { configId: string; subjects: string[]; + lockedToSubjects: boolean; publiclyVisible: boolean; mentorType: MentorType; orgPermissions: OrgPermissionsGQL[];