diff --git a/package-lock.json b/package-lock.json index 3d59b6b..551c1c9 100755 --- a/package-lock.json +++ b/package-lock.json @@ -30,7 +30,6 @@ "remark-preset-lint-consistent": "^6.0.0", "remark-preset-lint-recommended": "^7.0.0", "style-loader": "^3.3.3", - "uuid": "^10.0.0", "vue": "^2.7.14", "vue-apexcharts": "^1.6.2", "vue-codemirror6": "^1.3.4", @@ -21213,18 +21212,6 @@ "node": ">= 0.4.0" } }, - "node_modules/uuid": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", - "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", @@ -37943,11 +37930,6 @@ "dev": true, "peer": true }, - "uuid": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", - "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==" - }, "v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", diff --git a/package.json b/package.json index 5fae2c2..d199420 100755 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "remark-preset-lint-consistent": "^6.0.0", "remark-preset-lint-recommended": "^7.0.0", "style-loader": "^3.3.3", - "uuid": "^10.0.0", "vue": "^2.7.14", "vue-apexcharts": "^1.6.2", "vue-codemirror6": "^1.3.4", diff --git a/src/entities/schema/schema.ts b/src/entities/schema/schema.ts index 4239d09..4dcd6d9 100644 --- a/src/entities/schema/schema.ts +++ b/src/entities/schema/schema.ts @@ -31,7 +31,7 @@ export class Schema implements TSchema { const schema = z.object({ id: z.string().min(1), title: z.string().min(1), - version: z.string(), + version: z.string().regex(/^(?:\d+\.){2}\d+$/g, 'Invalid version format'), description: z.string(), summary: z.string(), required: z.array(z.string()), diff --git a/src/modals/Modals.vue b/src/modals/Modals.vue index d942037..fc22305 100755 --- a/src/modals/Modals.vue +++ b/src/modals/Modals.vue @@ -8,10 +8,10 @@ import { navigationStore } from '../store/store.js' - + - + diff --git a/src/modals/schema/EditSchema.vue b/src/modals/schema/EditSchema.vue index f248292..d6e4e16 100644 --- a/src/modals/schema/EditSchema.vue +++ b/src/modals/schema/EditSchema.vue @@ -3,8 +3,7 @@ import { schemaStore, navigationStore } from '../../store/store.js' - @@ -18,9 +17,6 @@ import { schemaStore, navigationStore } from '../../store/store.js' - @@ -91,36 +87,26 @@ export default { return { schemaItem: { title: '', - version: '', + version: '0.0.0', description: '', summary: '', - created: '', - updated: '', }, createAnother: false, success: false, loading: false, error: false, - hasUpdated: false, closeModalTimeout: null, } }, mounted() { this.initializeSchemaItem() }, - updated() { - if (navigationStore.modal === 'editSchema' && !this.hasUpdated) { - this.initializeSchemaItem() - this.hasUpdated = true - } - }, methods: { initializeSchemaItem() { if (schemaStore.schemaItem?.id) { this.schemaItem = { ...schemaStore.schemaItem, title: schemaStore.schemaItem.title || '', - version: schemaStore.schemaItem.version || '', description: schemaStore.schemaItem.description || '', summary: schemaStore.schemaItem.summary || '', } @@ -129,18 +115,6 @@ export default { closeModal() { navigationStore.setModal(false) clearTimeout(this.closeModalTimeout) - this.success = null - this.loading = false - this.error = false - this.hasUpdated = false - this.schemaItem = { - title: '', - version: '', - description: '', - summary: '', - created: '', - updated: '', - } }, async editSchema() { this.loading = true @@ -148,27 +122,28 @@ export default { schemaStore.saveSchema({ ...this.schemaItem, }).then(({ response }) => { + if (this.createAnother) { + // since saveSchema populates the schema item, we need to clear it schemaStore.setSchemaItem(null) + + // clear the form after 0.5s setTimeout(() => { - this.initializeSchemaItem() this.schemaItem = { title: '', - version: '0.0.1', + version: '0.0.0', description: '', summary: '', - created: '', - updated: '', } - this.loading = false }, 500) - setTimeout(() => { - this.success = null - }, 2000) + this.success = response.ok - this.hasUpdated = false this.error = false + // clear the success message after 2s + setTimeout(() => { + this.success = null + }, 2000) } else { this.success = response.ok this.error = false diff --git a/src/modals/schema/EditSchemaProperty.vue b/src/modals/schema/EditSchemaProperty.vue index d6354b8..f233e7a 100644 --- a/src/modals/schema/EditSchemaProperty.vue +++ b/src/modals/schema/EditSchemaProperty.vue @@ -2,9 +2,8 @@ import { navigationStore, schemaStore } from '../../store/store.js' - @@ -23,7 +22,9 @@ import { navigationStore, schemaStore } from '../../store/store.js' + :error="keyExists()" + :helper-text="keyExists() ? 'This key already exists on this schema' : ''" + :value.sync="propertyTitle" /> @@ -276,8 +277,6 @@ import Cancel from 'vue-material-design-icons/Cancel.vue' import Plus from 'vue-material-design-icons/Plus.vue' import ContentSaveOutline from 'vue-material-design-icons/ContentSaveOutline.vue' -import { v4 as uuidv4 } from 'uuid' - export default { name: 'EditSchemaProperty', components: { @@ -294,8 +293,8 @@ export default { }, data() { return { + propertyTitle: '', properties: { - title: '', description: '', type: 'string', format: '', @@ -328,7 +327,6 @@ export default { loading: false, success: null, error: false, - hasUpdated: false, closeModalTimeout: null, } }, @@ -363,17 +361,12 @@ export default { mounted() { this.initializeSchemaItem() }, - updated() { - if (navigationStore.modal === 'editSchemaProperty' && !this.hasUpdated) { - this.initializeSchemaItem() - this.hasUpdated = true - } - }, methods: { initializeSchemaItem() { if (schemaStore.schemaPropertyKey) { const schemaProperty = schemaStore.schemaItem.properties[schemaStore.schemaPropertyKey] + this.propertyTitle = schemaStore.schemaPropertyKey this.properties = { ...schemaProperty, minLength: schemaProperty.minLength ?? 0, @@ -386,42 +379,35 @@ export default { } } }, + /** + * check if the title already exists on properties as a key. + * returns true if it exists, false if it doesn't. + * + * When dealing with a key which is the same key as you are editing return false + */ + keyExists() { + if (this.propertyTitle === schemaStore.schemaPropertyKey) return false + return Object.keys(schemaStore.schemaItem.properties).includes(this.propertyTitle) + }, closeModal() { - navigationStore.setModal(false) + navigationStore.setModal(null) schemaStore.setSchemaPropertyKey(null) clearTimeout(this.closeModalTimeout) - this.success = null - this.hasUpdated = false - this.properties = { - title: '', - description: '', - type: '', - format: '', - pattern: '', - default: '', - behavior: '', - required: false, - deprecated: false, - minLength: 0, - maxLength: 0, - example: '', - minimum: 0, - maximum: 0, - multipleOf: 0, - exclusiveMin: false, - exclusiveMax: false, - minItems: 0, - maxItems: 0, - } }, addSchemaProperty() { this.loading = true + // delete the key when its an edit modal (the item will be re-created later, so don't worry about it) + // this is done incase you are also editing the title which acts as a key + if (schemaStore.schemaPropertyKey) { + delete schemaStore.schemaItem.properties[schemaStore.schemaPropertyKey] + } + const newSchemaItem = { ...schemaStore.schemaItem, properties: { ...schemaStore.schemaItem.properties, - [schemaStore.schemaPropertyKey || uuidv4()]: { // if no key is set, generate a new uuid + [this.propertyTitle]: { // create the new property with title as key ...this.properties, // due to bad (no) support for number fields inside nextcloud/vue, parse the text to a number minLength: parseFloat(this.properties.minLength) || null, diff --git a/src/store/modules/schema.js b/src/store/modules/schema.js index 0e14014..2429427 100644 --- a/src/store/modules/schema.js +++ b/src/store/modules/schema.js @@ -100,6 +100,7 @@ export const useSchemaStore = defineStore('schema', { const method = isNewSchema ? 'POST' : 'PUT' schemaItem.updated = new Date().toISOString() + delete schemaItem.version const response = await fetch( endpoint, diff --git a/src/views/schema/SchemaDetails.vue b/src/views/schema/SchemaDetails.vue index b29c338..ac7d9ab 100644 --- a/src/views/schema/SchemaDetails.vue +++ b/src/views/schema/SchemaDetails.vue @@ -62,9 +62,11 @@ import { schemaStore, navigationStore } from '../../store/store.js' + :force-display-actions="true" + @click="setActiveProperty(key)"> @@ -73,14 +75,14 @@ import { schemaStore, navigationStore } from '../../store/store.js' {{ property.description }} - Edit - @@ -149,6 +151,13 @@ export default { Download, Upload, }, + methods: { + setActiveProperty(key) { + if (JSON.stringify(schemaStore.schemaPropertyKey) === JSON.stringify(key)) { + schemaStore.setSchemaPropertyKey(null) + } else { schemaStore.setSchemaPropertyKey(key) } + }, + }, }