Skip to content

Commit

Permalink
default topics for categories
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Feb 6, 2024
1 parent 9e0970a commit 1418be2
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clean:

.PHONY: develop
develop: node_modules/gatsby
npx gatsby develop -p 8000
npx gatsby develop -p 80

.PHONY: pretty
pretty:
Expand Down
50 changes: 43 additions & 7 deletions client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,16 @@ export async function fetchSubject(id: string): Promise<SubjectGQL> {
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
}
questions {
useDefaultTopics
question {
_id
question
Expand All @@ -494,11 +497,13 @@ export async function fetchSubject(id: string): Promise<SubjectGQL> {
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
}
}
}
Expand Down Expand Up @@ -538,13 +543,16 @@ export async function fetchSubjects(
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
}
questions {
useDefaultTopics
question {
_id
question
Expand All @@ -559,12 +567,14 @@ export async function fetchSubjects(
id
name
description
defaultTopics
}
topics {
id
name
description
}
categoryParent
}
}
}
}
Expand Down Expand Up @@ -609,13 +619,16 @@ export async function updateSubject(
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
description
}
questions {
useDefaultTopics
question {
_id
question
Expand All @@ -630,11 +643,13 @@ export async function updateSubject(
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
}
}
}
Expand Down Expand Up @@ -674,6 +689,7 @@ export async function addOrUpdateSubjectQuestions(
question
category
topics
useDefaultTopics
}
}
}
Expand Down Expand Up @@ -1104,13 +1120,16 @@ export async function fetchMentorById(
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
}
questions(mentor:$mentor) {
useDefaultTopics
question {
_id
clientId
Expand All @@ -1119,10 +1138,12 @@ export async function fetchMentorById(
id
name
description
defaultTopics
}
topics {
id
name
categoryParent
description
}
}
Expand Down Expand Up @@ -2222,14 +2243,17 @@ export async function exportMentor(
topics {
id
name
categoryParent
description
}
categories {
id
name
description
defaultTopics
}
questions {
useDefaultTopics
question {
_id
question
Expand All @@ -2244,11 +2268,13 @@ export async function exportMentor(
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
description
}
}
}
Expand Down Expand Up @@ -2358,14 +2384,17 @@ export async function importMentorPreview(
topics {
id
name
description
categoryParent
description
}
categories {
id
name
description
defaultTopics
}
questions {
useDefaultTopics
question {
_id
question
Expand All @@ -2380,11 +2409,13 @@ export async function importMentorPreview(
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
description
}
}
}
Expand All @@ -2396,16 +2427,19 @@ export async function importMentorPreview(
isRequired
isArchived
topics {
id
categoryParent
id
name
description
}
categories {
id
name
description
defaultTopics
}
questions {
useDefaultTopics
question {
_id
question
Expand All @@ -2420,11 +2454,13 @@ export async function importMentorPreview(
id
name
description
defaultTopics
}
topics {
id
name
description
categoryParent
description
}
}
}
Expand Down
74 changes: 73 additions & 1 deletion client/src/components/author/category-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ import {
IconButton,
Collapse,
ListSubheader,
Autocomplete,
ListItemText,
ListItemSecondaryAction,
} from "@mui/material";
import DeleteIcon from "@mui/icons-material/Delete";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import { Category } from "types";
import { Category, Topic } from "types";
import QuestionListItem from "./question-list-item";
import { SubjectQuestionGQL } from "types-gql";
import { onTextInputChanged } from "helpers";

export function CategoryListItem(props: {
category: Category;
topics: Topic[];
questions: SubjectQuestionGQL[];
selectedQuestion?: string;
selectedCategory?: string;
Expand All @@ -38,6 +42,7 @@ export function CategoryListItem(props: {
}): JSX.Element {
const {
category,
topics,
questions,
selectedQuestion,
selectedCategory,
Expand Down Expand Up @@ -121,6 +126,73 @@ export function CategoryListItem(props: {
shrink: true,
}}
/>
<ListSubheader>Default Topics</ListSubheader>
<Autocomplete
data-cy="default-topic-input"
options={topics.filter(
(t) =>
!category.defaultTopics.find((id) => id === t.id) &&
!t.categoryParent
)}
getOptionLabel={(option: Topic) => option.name}
onChange={(e, v) => {
if (!v?.id) {
return;
}
updateCategory({
...category,
defaultTopics: [...category.defaultTopics, v.id],
});
}}
style={{ width: "100%" }}
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
placeholder="Add a default topic"
/>
)}
/>
<List data-cy="default-topics-list">
{category.defaultTopics.map((t, i) => {
const topic = topics.find((topic) => topic.id === t);
if (!topic) {
return null;
}
let topicName =

Check failure on line 162 in client/src/components/author/category-list-item.tsx

View workflow job for this annotation

GitHub Actions / test

'topicName' is never reassigned. Use 'const' instead
topic.categoryParent === category.id
? `${category.name}`
: topic.name || "";
return (
<ListItem key={`topic-${i}`} data-cy={`topic-${i}`}>
<div>
<ListItemText
data-cy="topic-name"
data-test={topicName}
primary={topicName}
/>
<ListItemSecondaryAction>
<IconButton
data-cy="delete-topic"
edge="end"
size="small"
onClick={() => {
updateCategory({
...category,
defaultTopics: category.defaultTopics.filter(
(topicId) => topicId !== topic.id
),
});
}}
>
<DeleteIcon />
</IconButton>
</ListItemSecondaryAction>
</div>
</ListItem>
);
})}
</List>
<Droppable droppableId={`category-${category.id}`}>
{(provided) => (
<List
Expand Down
9 changes: 9 additions & 0 deletions client/src/components/author/question-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import ParaphraseList from "components/author/question-paraphrase-list";
import TopicsList from "components/author/question-topics-list";
import { SubjectQuestionGQL } from "types-gql";
import questions from "store/slices/questions";

Check warning on line 30 in client/src/components/author/question-edit.tsx

View workflow job for this annotation

GitHub Actions / test

'questions' is defined but never used

export function QuestionEditCard(props: {
subjectType: SubjectTypes;
Expand Down Expand Up @@ -178,9 +179,17 @@ export function QuestionEditCard(props: {
<TopicsList
classes={classes}
allTopics={props.topics}
updateUseDefaultTopics={(val: boolean) =>
props.updateQuestion({
...question,
useDefaultTopics: val,
})
}
useDefaultTopics={Boolean(question.useDefaultTopics)}
questionTopics={question.topics.filter((t) =>
props.topics.map((t) => t.id).includes(t.id)
)}
questionCategory={question.category}
updateTopics={(t: Topic[]) =>
props.updateQuestion({ ...question, topics: t })
}
Expand Down
Loading

0 comments on commit 1418be2

Please sign in to comment.