Skip to content

Commit

Permalink
mentor config lock subjects update
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Feb 8, 2024
1 parent aec4548 commit a9c3824
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 13 deletions.
3 changes: 3 additions & 0 deletions client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export async function fetchUsers(
mentorConfig{
configId
subjects
lockedToSubjects
publiclyVisible
mentorType
orgPermissions{
Expand Down Expand Up @@ -1084,6 +1085,7 @@ export async function fetchMentorById(
mentorConfig{
configId
subjects
lockedToSubjects
publiclyVisible
mentorType
orgPermissions{
Expand Down Expand Up @@ -1266,6 +1268,7 @@ export async function fetchMentorConfig(
fetchMentorConfig(mentorConfigId:$mentorConfigId){
configId
subjects
lockedToSubjects
publiclyVisible
mentorType
orgPermissions{
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function HomePage(props: {
]);

useEffect(() => {
const lockedToSubjects = mentorConfig?.subjects.length;
const lockedToSubjects = mentorConfig?.lockedToSubjects;
if (
!lockedToConfig ||
!mentorConfig ||
Expand Down Expand Up @@ -532,7 +532,7 @@ function HomePage(props: {
{name}
</MenuItem>
))}
{mentorConfig?.subjects.length ? undefined : (
{mentorConfig?.lockedToSubjects ? undefined : (
<MenuItem
key={"add-subject"}
data-cy={"add-subject"}
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/graphql/use-with-setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export function useWithSetup(
requiredSubjects,
isSetupComplete,
});
const mentorSubjectsLocked = mentor.mentorConfig?.subjects.length;
const mentorSubjectsLocked = mentor.mentorConfig?.lockedToSubjects;
const mentorPrivacyLocked =
mentor.mentorConfig?.publiclyVisible !== undefined ||
mentor.mentorConfig?.orgPermissions.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ export function useWithMentorRecommender(
const completeMentorAnswers = state.mentorData.answers.filter((answer) =>
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.
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function SetupPage(props: {
}

return (
<div className={classes.root}>
<div className={classes.root} data-cy="setup-page">
<NavBar onNav={onLeave} title="Mentor Setup" mentorId={mentor?._id} />
<Carousel
// key={steps.length} // ensure carousel re-renders if # steps change
Expand Down
45 changes: 40 additions & 5 deletions client/src/pages/subjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
TableRow,
Toolbar,
Theme,
Button,
} from "@mui/material";
import { makeStyles } from "tss-react/mui";
import KeyboardArrowLeftIcon from "@mui/icons-material/KeyboardArrowLeft";
Expand All @@ -35,7 +36,7 @@ import withLocation from "wrap-with-location";
import { useMentorEdits } from "store/slices/mentor/useMentorEdits";
import useActiveMentor from "store/slices/mentor/useActiveMentor";
import ButtonGroupDropdown from "components/ButtonGroupDropdown";
import { convertSubjectGQL } from "types-gql";
import { MentorConfig, convertSubjectGQL } from "types-gql";
import { useWithLogin } from "store/slices/login/useWithLogin";

const useStyles = makeStyles({ name: { SubjectsPage } })((theme: Theme) => ({
Expand Down Expand Up @@ -109,6 +110,7 @@ function SubjectsPage(props: {
isLoading: isMentorLoading,
isSaving: isMentorSaving,
error: mentorError,
getData,
} = useActiveMentor();
const [viewUtteranceSubjects, setViewUtteranceSubjects] =
useState<boolean>(false);
Expand All @@ -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<boolean>(false);
const filterToConfigSubjects =
mentorConfig && !mentorConfig.lockedToSubjects && !showAllSubjects;
const {
pageData: subjects,
isLoading: isSubjectsLoading,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -208,7 +234,7 @@ function SubjectsPage(props: {
return (
<div>
<NavBar title="Subjects" mentor={editedMentor?._id} onBack={onBack} />
<div className={classes.root}>
<div className={classes.root} data-cy="subjects-page">
<Paper className={classes.container}>
<TableContainer>
<Table stickyHeader aria-label="sticky table">
Expand Down Expand Up @@ -275,6 +301,15 @@ function SubjectsPage(props: {
})}
</TableBody>
</Table>
{mentorConfig && (
<Button
onClick={() => setShowAllSubjects(!showAllSubjects)}
style={{ margin: "15px" }}
data-cy="show-all-subjects-button"
>
{showAllSubjects ? "Less" : "More"}
</Button>
)}
</TableContainer>
</Paper>
<AppBar position="sticky" color="default" className={classes.appBar}>
Expand Down
1 change: 1 addition & 0 deletions client/src/types-gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface OrgPermissionsGQL {
export interface MentorConfig {
configId: string;
subjects: string[];
lockedToSubjects: boolean;
publiclyVisible: boolean;
mentorType: MentorType;
orgPermissions: OrgPermissionsGQL[];
Expand Down
26 changes: 23 additions & 3 deletions cypress/cypress/e2e/setup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
36 changes: 36 additions & 0 deletions cypress/cypress/e2e/subjects.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions cypress/cypress/support/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface OrgPermissionsGQL {
export interface MentorConfig {
configId: string;
subjects: string[];
lockedToSubjects: boolean;
publiclyVisible: boolean;
mentorType: MentorType;
orgPermissions: OrgPermissionsGQL[];
Expand Down

0 comments on commit a9c3824

Please sign in to comment.