From 8d74de75faba037252fce8d229420982e7588bfd Mon Sep 17 00:00:00 2001 From: TeodoraPavlova <27234545+TeodoraPavlova@users.noreply.github.com> Date: Wed, 8 May 2024 15:52:24 +0300 Subject: [PATCH] Load schema on demand (fixes #203) (#207) * Load schema on demand (fixes #203) * refactor move schema.js to composables * rename event update-schema to updateSchema in order to find occurrences easily --- frontend/src/App.vue | 1 - frontend/src/components/Entity.vue | 194 +++++++++--------- frontend/src/components/EntityBulkEdit.vue | 134 ++++++------ frontend/src/components/Schema.vue | 166 ++++++++------- frontend/src/components/SchemaEdit.vue | 4 +- .../inputs/ReferencedEntitySelect.vue | 2 +- frontend/src/composables/schema.js | 19 ++ 7 files changed, 277 insertions(+), 243 deletions(-) create mode 100644 frontend/src/composables/schema.js diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 07c543d..934914d 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -63,7 +63,6 @@ export default { }, provide() { return { - activeSchema: computed(() => this.activeSchema), availableSchemas: computed(() => this.$refs.schemalist.schemas), updatePendingRequests: this.onPendingReviews, apiInfo: computed(() => this.apiInfo) diff --git a/frontend/src/components/Entity.vue b/frontend/src/components/Entity.vue index b471120..46fde45 100644 --- a/frontend/src/components/Entity.vue +++ b/frontend/src/components/Entity.vue @@ -1,113 +1,115 @@ - - - - - {{ activeSchema?.name || 'n/a' }} - - - {{ title }} + + + + + + + {{ activeSchema?.name || 'n/a' }} + + + {{ title }} + + + + delete + This entity is deleted. + + + + - - - delete - This entity is deleted. - - - - + - diff --git a/frontend/src/components/EntityBulkEdit.vue b/frontend/src/components/EntityBulkEdit.vue index c5a9457..d4ff442 100644 --- a/frontend/src/components/EntityBulkEdit.vue +++ b/frontend/src/components/EntityBulkEdit.vue @@ -1,87 +1,85 @@ - - - - - {{ activeSchema?.name || 'n/a' }} - - - Bulk Editor - - + + + + + {{ activeSchema?.name || 'n/a' }} + + + Bulk Editor + + + :batch-mode="true" :ref="el => { entityFormRefs[`e_form_${e.id}`] = el }" + v-on:save-all="saveAll"/> - - - diff --git a/frontend/src/components/Schema.vue b/frontend/src/components/Schema.vue index 7944489..53a06d7 100644 --- a/frontend/src/components/Schema.vue +++ b/frontend/src/components/Schema.vue @@ -1,22 +1,25 @@ - - - {{ title }} + + + + + {{ title }} + + + + delete + This schema is deleted. + + + + - - - delete - This schema is deleted. - - - - - - + - + +watch( + route, + () => init(), + { + immediate: true + } +); + + \ No newline at end of file diff --git a/frontend/src/components/SchemaEdit.vue b/frontend/src/components/SchemaEdit.vue index 9cd31ed..9100743 100644 --- a/frontend/src/components/SchemaEdit.vue +++ b/frontend/src/components/SchemaEdit.vue @@ -49,6 +49,7 @@ export default { name: "SchemaEdit", components: {EditAttributes, TextInput, Checkbox}, props: ["schema"], + emits: ["updateSchema"], inject: ["availableSchemas"], data() { return { @@ -115,8 +116,9 @@ export default { schemaSlug: this.schema.slug, body: toSend, }); - if (response.status === 200) { + if (response?.id) { this.$router.push({name: 'schema-view', params: {schemaSlug: this.schema.slug}}); + this.$emit('updateSchema'); } }, }, diff --git a/frontend/src/components/inputs/ReferencedEntitySelect.vue b/frontend/src/components/inputs/ReferencedEntitySelect.vue index 3ae8229..a10d97c 100644 --- a/frontend/src/components/inputs/ReferencedEntitySelect.vue +++ b/frontend/src/components/inputs/ReferencedEntitySelect.vue @@ -39,7 +39,7 @@ export default { components: {BaseInput, EntityList, ModalDialog}, emits: ["changed", "selected", "update:modelValue"], props: ["args", "label", "modelValue", "fkSchemaId", "selectType", "required"], - inject: ["activeSchema", "availableSchemas"], + inject: ["availableSchemas"], data() { return { loading: true, diff --git a/frontend/src/composables/schema.js b/frontend/src/composables/schema.js new file mode 100644 index 0000000..eee5449 --- /dev/null +++ b/frontend/src/composables/schema.js @@ -0,0 +1,19 @@ +import {ref} from 'vue'; +import {api} from '@/composables/api'; +import {useRoute} from 'vue-router'; + +export const useSchema = () => { + const activeSchema = ref(null); + const route = useRoute(); + const getSchema = async () => { + const slug = route.params.schemaSlug; + if (slug) { + activeSchema.value = await api.getSchema({slugOrId: slug}); + } + } + + return { + activeSchema, + getSchema + } +} \ No newline at end of file