From 591c922c98e6b61e7e9bf501fac37667ca4a7606 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 16 Nov 2021 08:49:28 +0100 Subject: [PATCH 1/5] Add missing subselection to query, update tests --- client/src/graphql/gql/queries/myActivity.gql | 11 +++---- server/assignments/schema/queries.py | 1 - .../assignments/tests/test_myassignments.py | 32 +++++++++++++------ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/client/src/graphql/gql/queries/myActivity.gql b/client/src/graphql/gql/queries/myActivity.gql index 46201edc..e4ec9313 100644 --- a/client/src/graphql/gql/queries/myActivity.gql +++ b/client/src/graphql/gql/queries/myActivity.gql @@ -5,7 +5,11 @@ query MyActivityQuery { id title contents - type + type { + id + type + category + } slug bookmarks { id @@ -13,11 +17,6 @@ query MyActivityQuery { note { id text - } - instrument { - id - type - contents } } } diff --git a/server/assignments/schema/queries.py b/server/assignments/schema/queries.py index ae25ddf2..83c12822 100644 --- a/server/assignments/schema/queries.py +++ b/server/assignments/schema/queries.py @@ -1,7 +1,6 @@ from graphene import relay from graphene_django.filter import DjangoFilterConnectionField -from assignments.models import StudentSubmission from assignments.schema.types import AssignmentNode, StudentSubmissionNode diff --git a/server/assignments/tests/test_myassignments.py b/server/assignments/tests/test_myassignments.py index ff9399fe..b7a4e205 100644 --- a/server/assignments/tests/test_myassignments.py +++ b/server/assignments/tests/test_myassignments.py @@ -1,12 +1,3 @@ -# -*- coding: utf-8 -*- -# -# ITerativ GmbH -# http://www.iterativ.ch/ -# -# Copyright (c) 2019 ITerativ GmbH. All rights reserved. -# -# Created on 2019-04-11 -# @author: chrigu from django.conf import settings import json @@ -119,6 +110,29 @@ class MyAssignemntsText(DefaultUserTestCase): } } } + myInstrumentActivity { + edges { + node { + id + title + contents + type { + id + type + category + } + slug + bookmarks { + id + uuid + note { + id + text + } + } + } + } + } } ''' From febd820267ff5a9c1cd7a48d220ef9c88685ed51 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 16 Nov 2021 10:20:25 +0100 Subject: [PATCH 2/5] Fix broken bookmark creation --- .../update-content-bookmark-mutation.js | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/client/src/helpers/update-content-bookmark-mutation.js b/client/src/helpers/update-content-bookmark-mutation.js index cedf0214..674e449c 100644 --- a/client/src/helpers/update-content-bookmark-mutation.js +++ b/client/src/helpers/update-content-bookmark-mutation.js @@ -7,57 +7,8 @@ const compareUuid = uuid => element => element.uuid === uuid; export const constructContentComponentBookmarkMutation = (uuid, bookmarked, parent, root) => { let mutation = {}; - - if (parent.__typename === 'ContentBlockNode') { - mutation = { - mutation: UPDATE_CONTENT_BOOKMARK, - variables: { - input: { - uuid, - contentBlock: root, - bookmarked - } - }, - update: (store, response) => { - const query = CONTENT_BLOCK_QUERY; - const variables = {id: root}; - const data = store.readQuery({ - query, - variables - }); - - const bookmarks = data.contentBlock.bookmarks; - - if (bookmarked) { - bookmarks.push({ - note: null, - uuid, - __typename: 'ContentBlockBookmarkNode' - }); - } else { - let index = bookmarks.findIndex(compareUuid(uuid)); - if (index > -1) { - bookmarks.splice(index, 1); - } - } - - data.contentBlock.bookmarks = bookmarks; - - store.writeQuery({ - data, - query, - variables - }); - }, - optimisticResponse: { - __typename: 'Mutation', - updateContentBookmark: { - __typename: 'UpdateContentBookmarkPayload', - success: true - } - } - }; - } else { + + if (parent.__typename === 'InstrumentNode') { mutation = { mutation: UPDATE_INSTRUMENT_BOOKMARK, variables: { @@ -106,6 +57,55 @@ export const constructContentComponentBookmarkMutation = (uuid, bookmarked, pare } } }; + } else { + mutation = { + mutation: UPDATE_CONTENT_BOOKMARK, + variables: { + input: { + uuid, + contentBlock: root, + bookmarked + } + }, + update: (store, response) => { + const query = CONTENT_BLOCK_QUERY; + const variables = {id: root}; + const data = store.readQuery({ + query, + variables + }); + + const bookmarks = data.contentBlock.bookmarks; + + if (bookmarked) { + bookmarks.push({ + note: null, + uuid, + __typename: 'ContentBlockBookmarkNode' + }); + } else { + let index = bookmarks.findIndex(compareUuid(uuid)); + if (index > -1) { + bookmarks.splice(index, 1); + } + } + + data.contentBlock.bookmarks = bookmarks; + + store.writeQuery({ + data, + query, + variables + }); + }, + optimisticResponse: { + __typename: 'Mutation', + updateContentBookmark: { + __typename: 'UpdateContentBookmarkPayload', + success: true + } + } + }; } return mutation; }; From ffcf382c51da8495e49ae7632771683dfa440d74 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 16 Nov 2021 10:45:59 +0100 Subject: [PATCH 3/5] Make linter happy --- client/src/helpers/update-content-bookmark-mutation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/helpers/update-content-bookmark-mutation.js b/client/src/helpers/update-content-bookmark-mutation.js index 674e449c..51b75574 100644 --- a/client/src/helpers/update-content-bookmark-mutation.js +++ b/client/src/helpers/update-content-bookmark-mutation.js @@ -7,7 +7,7 @@ const compareUuid = uuid => element => element.uuid === uuid; export const constructContentComponentBookmarkMutation = (uuid, bookmarked, parent, root) => { let mutation = {}; - + if (parent.__typename === 'InstrumentNode') { mutation = { mutation: UPDATE_INSTRUMENT_BOOKMARK, From 36932baa89e1b60d437cd46f75851fb8e9f95ed9 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 16 Nov 2021 10:50:43 +0100 Subject: [PATCH 4/5] Fix instrument colors --- .../src/components/instruments/FilterEntry.vue | 4 ++-- .../components/instruments/InstrumentEntry.vue | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/src/components/instruments/FilterEntry.vue b/client/src/components/instruments/FilterEntry.vue index 8f0a56e6..5044520e 100644 --- a/client/src/components/instruments/FilterEntry.vue +++ b/client/src/components/instruments/FilterEntry.vue @@ -124,11 +124,11 @@ } &--language-communication { - @include filter-block($color-accent-2-dark); + @include filter-block($color-accent-1-dark); } &--society { - @include filter-block($color-accent-1-dark); + @include filter-block($color-accent-2-dark); } &--interdisciplinary { diff --git a/client/src/components/instruments/InstrumentEntry.vue b/client/src/components/instruments/InstrumentEntry.vue index ea127195..2650816c 100644 --- a/client/src/components/instruments/InstrumentEntry.vue +++ b/client/src/components/instruments/InstrumentEntry.vue @@ -56,19 +56,19 @@ $root: &; &__language-communication { - background-color: $color-accent-2-light; - - #{$root}__category { - color: $color-accent-2-dark; - } - } - - &__society { background-color: $color-accent-1-light; #{$root}__category { color: $color-accent-1-dark; } + } + + &__society { + background-color: $color-accent-2-light; + + #{$root}__category { + color: $color-accent-2-dark; + } } From b0aed1ca74485086d49c6c9db9f20dfec5f420a3 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 16 Nov 2021 11:55:04 +0100 Subject: [PATCH 5/5] Add type to parent if missing --- client/src/components/content-blocks/ContentComponent.vue | 4 ++++ server/notes/mutations.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/client/src/components/content-blocks/ContentComponent.vue b/client/src/components/content-blocks/ContentComponent.vue index 61fd6e28..e255f1b3 100644 --- a/client/src/components/content-blocks/ContentComponent.vue +++ b/client/src/components/content-blocks/ContentComponent.vue @@ -92,6 +92,10 @@ export default { methods: { addNote(id) { + if (!this.parent.hasOwnProperty('__typename')) { + this.parent.__typename = 'ContentBlockNode'; + } + this.$store.dispatch('addNote', { content: id, type: this.parent.__typename, diff --git a/server/notes/mutations.py b/server/notes/mutations.py index f6ec80ef..91da6a30 100644 --- a/server/notes/mutations.py +++ b/server/notes/mutations.py @@ -80,7 +80,7 @@ class AddNote(relay.ClientIDMutation): user=user ) else: - instrument = BasicKnowledge.objects.get(slug=content_block_id) + instrument = BasicKnowledge.objects.get(slug=content_block_id) bookmark = InstrumentBookmark.objects.get( instrument=instrument, uuid=content_uuid,