-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Document/Assignment Tag (#101)
* Add DocumentTag in graphql * Remove tags table * Add, remove tag in frontend * Add link from gradebook to assignment document and submission document * Filter gradebook by assignment tags
- Loading branch information
1 parent
65b924d
commit 7c82e03
Showing
25 changed files
with
823 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...cument/DocumentBody/CoverPage/AssignmentCoverPageBody/GeneralInformation/TagAttribute.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { IconButton, TextField } from "@radix-ui/themes"; | ||
import { PlusIcon } from "@radix-ui/react-icons"; | ||
import React, { useState } from "react"; | ||
import { useMutation } from "@apollo/client"; | ||
import { t } from "@lingui/macro"; | ||
|
||
import { ADD_DOCUMENT_TAG } from "graphql/mutation/DocumentMutation"; | ||
import useDocumentStore from "store/DocumentStore"; | ||
import { AddDocumentTag } from "graphql/types"; | ||
import DocumentTag from "components/DocumentTag"; | ||
|
||
export type TagAttributeProps = { | ||
readOnly: boolean; | ||
}; | ||
|
||
const TagAttribute = ({ readOnly }: TagAttributeProps) => { | ||
const documentId = useDocumentStore((state) => state.activeDocumentId); | ||
const activeDocumentTags = useDocumentStore( | ||
(state) => state.activeDocument?.tags, | ||
); | ||
const addActiveDocumentTag = useDocumentStore( | ||
(state) => state.addActiveDocumentTag, | ||
); | ||
const [addTag, { loading }] = useMutation<AddDocumentTag>(ADD_DOCUMENT_TAG); | ||
const [newTag, setNewTag] = useState(""); | ||
|
||
const onAddNewTag = async () => { | ||
const existingTag = activeDocumentTags.find( | ||
(innerTag) => innerTag.tag === newTag, | ||
); | ||
if (existingTag || !documentId) return; | ||
|
||
const { data } = await addTag({ | ||
variables: { | ||
tag: { | ||
documentId, | ||
tag: newTag, | ||
}, | ||
}, | ||
}); | ||
|
||
if (data) { | ||
addActiveDocumentTag(data.documentAddTag); | ||
setNewTag(""); | ||
} | ||
}; | ||
|
||
return ( | ||
<div style={{ display: "flex", gap: 4, alignItems: "center" }}> | ||
{activeDocumentTags.map((tag) => ( | ||
<DocumentTag tag={tag} key={tag.tag} readOnly={readOnly} /> | ||
))} | ||
{!readOnly && ( | ||
<div style={{ display: "flex", alignItems: "center" }}> | ||
<TextField.Root | ||
size="1" | ||
variant="soft" | ||
placeholder={t`Typing new tag`} | ||
value={newTag} | ||
onChange={(e) => setNewTag(e.currentTarget.value)} | ||
style={{ width: 100 }} | ||
/> | ||
<IconButton | ||
variant="soft" | ||
size="1" | ||
style={{ marginLeft: 5 }} | ||
onClick={onAddNewTag} | ||
loading={loading} | ||
> | ||
<PlusIcon /> | ||
</IconButton> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TagAttribute; |
63 changes: 63 additions & 0 deletions
63
...DocumentBody/CoverPage/AssignmentCoverPageBody/GeneralInformation/VisibilityAttribute.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Select, Text } from "@radix-ui/themes"; | ||
import { Trans } from "@lingui/macro"; | ||
import React from "react"; | ||
|
||
import { DocumentVisibility } from "graphql/types"; | ||
|
||
export type VisibilityAttributeProps = { | ||
visibility: DocumentVisibility; | ||
onChangeVisibility: (visibility: DocumentVisibility) => void; | ||
}; | ||
|
||
const VisibilityAttribute = ({ | ||
visibility, | ||
onChangeVisibility, | ||
}: VisibilityAttributeProps) => { | ||
return ( | ||
<div style={{ display: "flex", gap: 4, flexDirection: "column" }}> | ||
<Select.Root | ||
value={visibility} | ||
onValueChange={onChangeVisibility} | ||
size="1" | ||
> | ||
<Select.Trigger variant="soft" style={{ width: "fit-content" }} /> | ||
<Select.Content> | ||
<Select.Group> | ||
<Select.Item value={DocumentVisibility.PUBLIC}> | ||
<Trans>Public</Trans> | ||
</Select.Item> | ||
<Select.Item value={DocumentVisibility.PRIVATE}> | ||
<Trans>Private</Trans> | ||
</Select.Item> | ||
<Select.Item value={DocumentVisibility.ASSIGNEES}> | ||
<Trans>Assignees only</Trans> | ||
</Select.Item> | ||
</Select.Group> | ||
</Select.Content> | ||
</Select.Root> | ||
<div> | ||
{visibility === DocumentVisibility.PUBLIC && ( | ||
<Text color="gray"> | ||
<Trans> | ||
All students of this space can access this assignment. | ||
</Trans> | ||
</Text> | ||
)} | ||
{visibility === DocumentVisibility.PRIVATE && ( | ||
<Text color="gray"> | ||
<Trans>Only you can access this assignment.</Trans> | ||
</Text> | ||
)} | ||
{visibility === DocumentVisibility.ASSIGNEES && ( | ||
<Text color="gray"> | ||
<Trans> | ||
Only assignees (listed below) can access this assignment. | ||
</Trans> | ||
</Text> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default VisibilityAttribute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.