Skip to content

Commit

Permalink
wip: modify creation and modification logic to link non private colle…
Browse files Browse the repository at this point in the history
…ctions always to missing collections catalog collection
  • Loading branch information
sjschlapbach committed Jan 22, 2025
1 parent 84c1e07 commit d71905d
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { FormikSelectField } from '@uzh-bf/design-system'
import { faWarning } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { FormikSelectField, Tooltip } from '@uzh-bf/design-system'
import { useField } from 'formik'
import { useTranslations } from 'next-intl'
import { twMerge } from 'tailwind-merge'

Expand All @@ -8,25 +11,36 @@ function AnswerCollectionCatalogSelection({
className?: string
}) {
const t = useTranslations()
const [field] = useField('catalogCollectionId')

return (
<FormikSelectField
name="catalogCollectionId"
label={t('manage.resources.catalogCollection')}
tooltip={t('manage.resources.catalogCollectionTooltip')}
items={[
{
label: t('manage.resources.noCatalogCollectionSelected'),
value: '',
data: { cy: 'select-no-catalog-collection' },
},
]}
data={{ cy: 'answer-collection-catalog-collection' }}
className={{
select: { trigger: 'h-9 w-full', root: 'w-full' },
root: twMerge('w-full', className),
}}
/>
<div className="flex flex-row items-start gap-3">
<FormikSelectField
name="catalogCollectionId"
label={t('manage.resources.catalogCollection')}
tooltip={t('manage.resources.catalogCollectionTooltip')}
items={[
{
label: t('manage.resources.noCatalogCollectionSelected'),
value: '',
data: { cy: 'select-no-catalog-collection' },
},
]}
data={{ cy: 'answer-collection-catalog-collection' }}
className={{
select: { trigger: 'h-9 w-full', root: 'w-full' },
root: twMerge('w-full', className),
}}
/>
{field.value === '' && (
<Tooltip
tooltip={t('manage.catalog.noCatalogCollectionSelectedWarning')}
className={{ trigger: 'mt-9', tooltip: 'max-w-[30rem] text-sm' }}
>
<FontAwesomeIcon icon={faWarning} className="text-orange-500" />
</Tooltip>
)}
</div>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type AnswerCollectionFormValues = {
access: ObjectAccess
description?: string
entries: { value?: string }[]
catalogCollectionId: string
}

function AnswerCollectionCreationForm({
Expand Down Expand Up @@ -84,6 +85,10 @@ function AnswerCollectionCreationForm({
description: values.description!,
access: values.access,
answers: values.entries.map((entry) => entry.value!),
catalogCollectionId:
values.catalogCollectionId === ''
? undefined
: values.catalogCollectionId,
},
update: (cache, { data }) => {
if (!data?.createAnswerCollection) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function AnswerCollectionEditModal({
/>
</div>
<Toast
dismissible
type="success"
openExternal={successToast}
onCloseExternal={() => setSuccessToast(false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function AnswerCollectionMetaForm({
name: collection.name,
access: collection.access,
description: collection.description,
catalogCollectionId: collection.catalogCollectionId ?? '',
}}
onSubmit={async (values) => {
const { data } = await modifyAnswerCollection({
Expand All @@ -52,6 +53,10 @@ function AnswerCollectionMetaForm({
values.description !== collection.description
? values.description
: undefined,
catalogCollectionId:
values.catalogCollectionId === ''
? undefined
: values.catalogCollectionId,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ mutation CreateAnswerCollection(
$access: ObjectAccess!
$description: String!
$answers: [String!]!
$catalogCollectionId: String
) {
createAnswerCollection(
name: $name
access: $access
description: $description
answers: $answers
catalogCollectionId: $catalogCollectionId
) {
id
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ mutation ModifyAnswerCollection(
$name: String
$access: ObjectAccess
$description: String
$catalogCollectionId: String
) {
modifyAnswerCollection(
id: $id
name: $name
access: $access
description: $description
catalogCollectionId: $catalogCollectionId
) {
id
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ query GetAnswerCollections {
description
ownerShortname
numSharedUsers
catalogCollectionId

isOwner
isEditable
isImported
isAccessGranted
isRemovable

entries {
id
value
Expand Down
36 changes: 36 additions & 0 deletions packages/graphql/src/ops.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "catalogCollectionId",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "description",
"description": null,
Expand Down Expand Up @@ -12368,6 +12380,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "catalogCollectionId",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "description",
"description": null,
Expand Down Expand Up @@ -16468,6 +16492,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "catalogCollectionId",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "description",
"description": null,
Expand Down
13 changes: 9 additions & 4 deletions packages/graphql/src/ops.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/graphql/src/public/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ChangeParticipantLocale": "a35b384c5614ee4c314767f21d4310c0b1be94ef14c6759ef275a4bea5efbba3",
"ChangeShortname": "07ed8db96ea01e17e68f1b598ba830a22199d44248cc473072fe2428491c4656",
"ChangeUserLocale": "0a5f88b275c2319ba6c569426183657cdb7962b17651bf16a738f24766affd67",
"CreateAnswerCollection": "4f7e8779e34ed6f26c7b7b15e3214d36863016071e96d828d638319b9b82934e",
"CreateAnswerCollection": "a5ece5752d2fb5400752bd546661726e474ad078f3152784dbe9aaae2accf4fe",
"CreateCourse": "189a624ca4fd8df46b23bc5d190dd07f08065cf518f1f862b949b8e658a823f1",
"CreateFeedback": "5a4a9e710048cb5b679e7d8217907d623c7c53638fec41183a0257931fc8b136",
"CreateGroupActivity": "9c85b7f85dedb882046baca8e77b53825968986109803caeba4662540b07f5a2",
Expand Down Expand Up @@ -81,7 +81,7 @@
"ManipulateSelectionQuestion": "8bc67900e871de18a92350c2965e20b6e0c3199a5f3f9ba5b5c5948e3928e3d9",
"ManualRandomGroupAssignments": "065e7940fcbf5da113b4d0e672b23ad0ef53639a355414998b1ecae2d626be40",
"MarkMicroLearningCompleted": "e066d2e279e3ae5d8b242ae0cf1894590924aa1f0544a8d6770c35b6b7dcc6b0",
"ModifyAnswerCollection": "a773a3a21da71fd0037ac7f4dd8e48e9f270de3da71a4456080df9b4267967a7",
"ModifyAnswerCollection": "05cbd0bf175c5de30fde4a419a05a7e3dd65f2cf33a55bcb8b19c5a6f20a6dc9",
"OpenGroupActivity": "141c222a2df6aaac9693d837bc0ad7b2490117c4e4a74674672d0bdaf29937e9",
"PinFeedback": "4e85dc7afc775cd2cb2a74a43422f00f95a2f8e9d63c48e6a5c59a52fd73e87d",
"PublishFeedback": "9af23d61fac70a3eb49989c0381653bea8129dc99891cd64dccdaeccddd725e9",
Expand Down Expand Up @@ -123,7 +123,7 @@
"CountCatalogSharingRequests": "e74997c0befad19b7412afb8dd053b68fe35067d889c2f9ecaf98319bfdfd48b",
"GetActiveUserCourses": "877f83a65cb320f69a51a5bf243f0d62bb8cce9e4c1d0bcab8cec8dd367bed86",
"GetActivityAnalytics": "bcbe895236bd0027e2db37d5884645cfa3230e90a7ce6de893783c5fdc54fa1b",
"GetAnswerCollections": "6c2457d25d976b95962388dc9239c8ce191d0acd346c0bb3ab4fc57a6b5337f4",
"GetAnswerCollections": "506906b083928fabc3fcb498c4c077debaf309bde93b897077a3d4b62a5dccf5",
"GetArtificialInstance": "30fdf3eb25f2e2d9f0971ea70f23a7dbf71b047d492c23b54a74fdaf6fe53d5f",
"GetBasicCourseInformation": "14169116abd9278adb08977b9c153403e6065ab0c3d02a6beb38017e1c8b19d6",
"GetBookmarkedElementStacks": "638064005a0d2326c21c2a58b9411fe89b2f540e687270d66be348517db69d31",
Expand Down
5 changes: 3 additions & 2 deletions packages/graphql/src/public/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum ActivityType {
type AnswerCollection {
access: ObjectAccess!
accessType: AccessType!
catalogCollectionId: String
description: String!
entries: [AnswerCollectionEntry!]
id: Int!
Expand Down Expand Up @@ -1053,7 +1054,7 @@ type Mutation {
changeParticipantLocale(locale: LocaleType!): Participant
changeShortname(shortname: String!): User
changeUserLocale(locale: LocaleType!): User
createAnswerCollection(access: ObjectAccess!, answers: [String!]!, description: String!, name: String!): AnswerCollection
createAnswerCollection(access: ObjectAccess!, answers: [String!]!, catalogCollectionId: String, description: String!, name: String!): AnswerCollection
createCourse(color: String, description: String, displayName: String!, endDate: Date!, groupDeadlineDate: Date!, isGamificationEnabled: Boolean!, isGroupCreationEnabled: Boolean!, maxGroupSize: Int!, name: String!, notificationEmail: String, preferredGroupSize: Int!, startDate: Date!): Course
createFeedback(content: String!, quizId: String!): Feedback
createGroupActivity(clues: [GroupActivityClueInput!]!, courseId: String!, description: String, displayName: String!, endDate: Date!, multiplier: Int!, name: String!, stack: ElementStackInput!, startDate: Date!): GroupActivity
Expand Down Expand Up @@ -1119,7 +1120,7 @@ type Mutation {
manipulateSelectionQuestion(content: String, explanation: String, id: Int, name: String, options: OptionsSelectionInput, pointsMultiplier: Int, status: ElementStatus, tags: [String!]): Element
manualRandomGroupAssignments(courseId: String!): Course
markMicroLearningCompleted(courseId: String!, id: String!): Participation
modifyAnswerCollection(access: ObjectAccess, description: String, id: Int!, name: String): AnswerCollection
modifyAnswerCollection(access: ObjectAccess, catalogCollectionId: String, description: String, id: Int!, name: String): AnswerCollection
openGroupActivity(id: String!): GroupActivity
pinFeedback(id: Int!, isPinned: Boolean!): Feedback
publishFeedback(id: Int!, isPublished: Boolean!): Feedback
Expand Down
Loading

0 comments on commit d71905d

Please sign in to comment.