Skip to content

Commit

Permalink
mentor config lock subjects update (#314)
Browse files Browse the repository at this point in the history
* mentor config lock subjects update
  • Loading branch information
aaronshiel authored Feb 8, 2024
1 parent aec4548 commit 5afa43f
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 18 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
1 change: 0 additions & 1 deletion client/src/pages/record.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ function RecordPage(props: {
const curAnswerBelongsToMentor = curEditedQuestion?.mentor === mentorId;
const warnEmptyTranscript =
curAnswer?.attentionNeeded === AnswerAttentionNeeded.NEEDS_TRANSCRIPT;

useEffect(() => {
if (!curAnswer) {
return;
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
8 changes: 7 additions & 1 deletion cypress/cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,13 @@ describe("My Mentor Page", () => {
it("users with locked subjects cannot see '+ add a subject' in dropdown menu", () => {
cySetup(cy);
cyMockDefault(cy, {
mentor: clintWithConfig,
mentor: {
...clintWithConfig,
mentorConfig: {
...clintWithConfig.mentorConfig,
lockedToSubjects: true,
},
},
});
cy.visit("/");
cy.get("[data-cy=setup-no]").trigger("mouseover").click();
Expand Down
19 changes: 18 additions & 1 deletion cypress/cypress/e2e/record.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2971,7 +2971,8 @@ describe("Record", () => {
});
});

it("warns user of empty transcript", () => {
// TODO: flaky, for unknown reason, media is getting dropped from answer after completion
it.skip("warns user of empty transcript", () => {
cyMockDefault(cy, {
mentor: [videoMentor],
questions: videoQuestions,
Expand Down Expand Up @@ -3002,6 +3003,22 @@ describe("Record", () => {
question: videoMentor.answers[0].question.question,
},

...taskListBuild("IN_PROGRESS"),
transcript: "",
...uploadTaskMediaBuild(),
},
],
},
},
{
me: {
uploadTasks: [
{
question: {
_id: videoMentor.answers[0].question._id,
question: videoMentor.answers[0].question.question,
},

...taskListBuild("DONE"),
transcript: "",
...uploadTaskMediaBuild(),
Expand Down
30 changes: 25 additions & 5 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 Expand Up @@ -1486,8 +1506,8 @@ describe("Setup", () => {
mockGQL("Subjects", { edges: [allSubjects.edges[0]] }),
],
});
cy.visit(`/setup?i=5`);
cy.get("[data-cy=slide-5]").should("contain.text", "2 / 2");
cy.visit(`/setup?i=6`);
cy.get("[data-cy=slide-6]").should("contain.text", "2 / 2");
cy.visit("/");
cy.get("[data-cy=setup-no]").should("not.exist");
cy.get("[data-cy=nav-bar]").should("contain.text", "My Mentor");
Expand Down
32 changes: 32 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,37 @@ describe("Select Subjects", () => {
});
});

describe("mentors with configs", () => {
it("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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 5afa43f

Please sign in to comment.