From f563483b7992b86250f769a75bb4914ee9a3ba4c Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Thu, 10 Feb 2022 12:06:03 +0100 Subject: [PATCH] Add edit route for custom content blocks --- client/src/components/ContentBlock.vue | 9 +- .../content-block-form/ContentBlockForm.vue | 308 ++++++++++++++++++ .../EditContentBlockWizard.vue | 2 +- .../components/content-block-form/helpers.js | 40 +++ ...eContentBlock.gql => editContentBlock.gql} | 0 client/src/helpers/visibility.js | 4 +- client/src/pages/createContentBlock.vue | 298 ++--------------- client/src/pages/editContentBlock.vue | 94 ++++++ client/src/router/module.names.js | 1 + client/src/router/module.routes.js | 24 +- 10 files changed, 490 insertions(+), 290 deletions(-) create mode 100644 client/src/components/content-block-form/ContentBlockForm.vue create mode 100644 client/src/components/content-block-form/helpers.js rename client/src/graphql/gql/mutations/{mutateContentBlock.gql => editContentBlock.gql} (100%) create mode 100644 client/src/pages/editContentBlock.vue diff --git a/client/src/components/ContentBlock.vue b/client/src/components/ContentBlock.vue index 15b7975c..2e6c3d8b 100644 --- a/client/src/components/ContentBlock.vue +++ b/client/src/components/ContentBlock.vue @@ -85,6 +85,7 @@ import {CONTENT_TYPE} from '@/consts/types'; import PopoverLink from '@/components/ui/PopoverLink'; import {removeAtIndex} from '@/graphql/immutable-operations'; + import {EDIT_CONTENT_BLOCK_PAGE} from '@/router/module.names'; const ContentComponent = () => import(/* webpackChunkName: "content-components" */'@/components/content-blocks/ContentComponent'); const instruments = { @@ -207,7 +208,13 @@ }, methods: { editContentBlock(contentBlock) { - this.$store.dispatch('editContentBlock', contentBlock.id); + const route = { + name: EDIT_CONTENT_BLOCK_PAGE, + params: { + id: contentBlock.id + } + }; + this.$router.push(route); }, deleteContentBlock(contentBlock) { const parent = this.parent; diff --git a/client/src/components/content-block-form/ContentBlockForm.vue b/client/src/components/content-block-form/ContentBlockForm.vue new file mode 100644 index 00000000..115cf038 --- /dev/null +++ b/client/src/components/content-block-form/ContentBlockForm.vue @@ -0,0 +1,308 @@ + + + + + diff --git a/client/src/components/content-block-form/EditContentBlockWizard.vue b/client/src/components/content-block-form/EditContentBlockWizard.vue index ae40ba5c..0495da57 100644 --- a/client/src/components/content-block-form/EditContentBlockWizard.vue +++ b/client/src/components/content-block-form/EditContentBlockWizard.vue @@ -12,7 +12,7 @@ import store from '@/store/index'; - import EDIT_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/mutateContentBlock.gql'; + import EDIT_CONTENT_BLOCK_MUTATION from 'gql/mutations/editContentBlock.gql'; import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql'; import CONTENT_BLOCK_QUERY from '@/graphql/gql/queries/contentBlockQuery.gql'; import { setUserBlockType } from '@/helpers/content-block'; diff --git a/client/src/components/content-block-form/helpers.js b/client/src/components/content-block-form/helpers.js new file mode 100644 index 00000000..4d37a13e --- /dev/null +++ b/client/src/components/content-block-form/helpers.js @@ -0,0 +1,40 @@ +import {setUserBlockType} from '@/helpers/content-block'; +import NEW_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/addContentBlock.gql'; +import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql'; + +export const CHOOSER = 'content-block-element-chooser-widget'; +export const chooserFilter = value => value.type !== CHOOSER; + +export const cleanUpContents = (contents) => { + let filteredContents = contents + .filter(chooserFilter); // only use items that are not chooser elements + + return filteredContents.map(content => { + // if the element has a contents property, it's a list of contents, filter them + if (content.contents) { + return { + ...content, + contents: content.contents.filter(chooserFilter) + }; + } + // else just return it + return content; + }); +}; + +// transform value prop to contents, to better handle the input type on the server +export const transformInnerContents = (contents) => { + let ret = []; + for (let content of contents) { + if (Array.isArray(content.value)) { + const {value, ...contentWithoutValue} = content; + ret.push({ + ...contentWithoutValue, + contents: value + }); + } else { + ret.push(content); + } + } + return ret; +}; diff --git a/client/src/graphql/gql/mutations/mutateContentBlock.gql b/client/src/graphql/gql/mutations/editContentBlock.gql similarity index 100% rename from client/src/graphql/gql/mutations/mutateContentBlock.gql rename to client/src/graphql/gql/mutations/editContentBlock.gql diff --git a/client/src/helpers/visibility.js b/client/src/helpers/visibility.js index b8484423..0598d34c 100644 --- a/client/src/helpers/visibility.js +++ b/client/src/helpers/visibility.js @@ -5,7 +5,7 @@ import { OBJECTIVE_GROUP_TYPE, OBJECTIVE_TYPE } from '@/consts/types'; -import CHANGE_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/mutateContentBlock.gql'; +import EDIT_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/editContentBlock.gql'; import UPDATE_OBJECTIVE_VISIBILITY_MUTATION from '@/graphql/gql/mutations/updateObjectiveVisibility.gql'; import UPDATE_OBJECTIVE_GROUP_VISIBILITY_MUTATION from '@/graphql/gql/mutations/updateObjectiveGroupVisibility.gql'; import UPDATE_CHAPTER_VISIBILITY_MUTATION from '@/graphql/gql/mutations/updateChapterVisibility.gql'; @@ -14,7 +14,7 @@ export const createVisibilityMutation = (type, id, visibility) => { let mutation, variables; switch (type) { case CONTENT_TYPE: - mutation = CHANGE_CONTENT_BLOCK_MUTATION; + mutation = EDIT_CONTENT_BLOCK_MUTATION; variables = { input: { id, diff --git a/client/src/pages/createContentBlock.vue b/client/src/pages/createContentBlock.vue index 0d9c97e2..13e1aa55 100644 --- a/client/src/pages/createContentBlock.vue +++ b/client/src/pages/createContentBlock.vue @@ -1,108 +1,20 @@ - - diff --git a/client/src/pages/editContentBlock.vue b/client/src/pages/editContentBlock.vue new file mode 100644 index 00000000..2d379f9c --- /dev/null +++ b/client/src/pages/editContentBlock.vue @@ -0,0 +1,94 @@ + + + diff --git a/client/src/router/module.names.js b/client/src/router/module.names.js index b407d320..2cfd2091 100644 --- a/client/src/router/module.names.js +++ b/client/src/router/module.names.js @@ -6,3 +6,4 @@ export const SNAPSHOT_LIST = 'snapshot-list'; export const SNAPSHOT_DETAIL = 'snapshot-detail'; export const CREATE_CONTENT_BLOCK_AFTER_PAGE = 'create-content-block-after'; export const CREATE_CONTENT_BLOCK_UNDER_PARENT_PAGE = 'create-content-block-under-parent'; +export const EDIT_CONTENT_BLOCK_PAGE = 'edit-content-block'; diff --git a/client/src/router/module.routes.js b/client/src/router/module.routes.js index 4f829237..0ffe6c17 100644 --- a/client/src/router/module.routes.js +++ b/client/src/router/module.routes.js @@ -5,10 +5,12 @@ import { SNAPSHOT_LIST, SUBMISSIONS_PAGE, VISIBILITY_PAGE, - CREATE_CONTENT_BLOCK_AFTER_PAGE, CREATE_CONTENT_BLOCK_UNDER_PARENT_PAGE, + CREATE_CONTENT_BLOCK_AFTER_PAGE, + CREATE_CONTENT_BLOCK_UNDER_PARENT_PAGE, EDIT_CONTENT_BLOCK_PAGE, } from '@/router/module.names'; import {LAYOUT_SIMPLE} from '@/router/core.constants'; import createContentBlock from '@/pages/createContentBlock'; +import editContentBlock from '@/pages/editContentBlock'; const moduleBase = () => import(/* webpackChunkName: "modules" */'@/pages/module/module-base'); const module = () => import(/* webpackChunkName: "modules" */'@/pages/module/module'); @@ -18,14 +20,15 @@ const settingsPage = () => import(/* webpackChunkName: "modules" */'@/pages/modu const snapshots = () => import(/* webpackChunkName: "modules" */'@/pages/snapshot/snapshots'); const snapshot = () => import(/* webpackChunkName: "modules" */'@/pages/snapshot/snapshot'); +const contentBlockFormMeta = { + // layout: LAYOUT_SIMPLE, + hideFooter: true, + hideHeader: true, + showSubNavigation: true + }; const createContentBlockRouteFragment = { component: createContentBlock, - meta: { - // layout: LAYOUT_SIMPLE, - hideFooter: true, - hideHeader: true, - showSubNavigation: true - }, + meta: contentBlockFormMeta, props: true }; @@ -85,6 +88,13 @@ export default [ fullWidth: true, }, }, + { + path: 'edit/:id', + meta: contentBlockFormMeta, + props: true, + component: editContentBlock, + name: EDIT_CONTENT_BLOCK_PAGE + }, { ...createContentBlockRouteFragment, path: 'add-after/:after',