@ditojs/admin 2.34.3 → 2.34.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/admin",
3
- "version": "2.34.3",
3
+ "version": "2.34.5",
4
4
  "type": "module",
5
5
  "description": "Dito.js Admin is a schema based admin interface for Dito.js Server, featuring auto-generated views and forms and built with Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/admin",
@@ -91,5 +91,5 @@
91
91
  "vite": "^5.4.8"
92
92
  },
93
93
  "types": "types",
94
- "gitHead": "5a5381114ae8012a9111015e2279fbc9e322c73a"
94
+ "gitHead": "ff641d5efcf55eed5ce7ebdd0a63d4d59dcbd43e"
95
95
  }
@@ -236,6 +236,8 @@ export default {
236
236
  store = this.setStore(key, reactive({}))
237
237
  }
238
238
  if (index != null) {
239
+ // temporary uid keys will change between persistence, so we need to
240
+ // assign the key to the index even when the store already existed.
239
241
  this.setStoreKeyByIndex(index, key)
240
242
  }
241
243
  return store
@@ -269,7 +271,7 @@ export default {
269
271
 
270
272
  getLabel(schema, name) {
271
273
  return schema
272
- ? this.getSchemaValue('label', { type: String, schema }) ||
274
+ ? this.getSchemaValue('label', { schema, type: [String, Object] }) ||
273
275
  labelize(name || schema.name)
274
276
  : labelize(name) || ''
275
277
  },
@@ -17,27 +17,27 @@ import {
17
17
  export default {
18
18
  mixins: [DataMixin],
19
19
 
20
- data() {
21
- return {
22
- hasOptions: false
23
- }
24
- },
25
-
26
20
  computed: {
27
21
  selectedValue: {
28
22
  get() {
29
- const convertValue = value =>
30
- this.relate
31
- ? this.hasOption(value)
32
- ? this.getValueForOption(value)
23
+ const convertValue = value => {
24
+ const val = this.relate
25
+ ? this.getValueForOption(value)
26
+ : value
27
+
28
+ return this.hasOptions
29
+ ? this.getOptionForValue(val)
30
+ ? val
33
31
  : null
34
32
  : value
33
+ }
34
+
35
35
  const value = isArray(this.value)
36
36
  ? this.value.map(convertValue).filter(value => value !== null)
37
37
  : convertValue(this.value)
38
+
38
39
  if (
39
- // When relating and as soon as the options are available...
40
- this.relate &&
40
+ // As soon as the options are available, and...
41
41
  this.hasOptions && (
42
42
  // ...if the value is forced to null because a disappeared option...
43
43
  value === null && this.value !== null ||
@@ -54,13 +54,14 @@ export default {
54
54
  },
55
55
 
56
56
  set(value) {
57
- const convert = value =>
57
+ const convertValue = value =>
58
58
  this.relate
59
59
  ? this.getOptionForValue(value)
60
60
  : value
61
+
61
62
  this.value = isArray(value)
62
- ? value.map(convert)
63
- : convert(value)
63
+ ? value.map(convertValue)
64
+ : convertValue(value)
64
65
  }
65
66
  },
66
67
 
@@ -73,9 +74,6 @@ export default {
73
74
  if (!isArray(data)) {
74
75
  throw new Error(`Invalid options data, should be array: ${data}`)
75
76
  }
76
- // TODO: Fix side-effects
77
- // eslint-disable-next-line vue/no-side-effects-in-computed-properties
78
- this.hasOptions = data.length > 0
79
77
  return this.processOptions(data)
80
78
  },
81
79
 
@@ -85,6 +83,10 @@ export default {
85
83
  return this.options
86
84
  },
87
85
 
86
+ hasOptions() {
87
+ return this.activeOptions.length > 0
88
+ },
89
+
88
90
  relate: getSchemaAccessor('relate', {
89
91
  // TODO: Convert to `relateBy: 'id'`
90
92
  type: Boolean,
@@ -216,10 +218,6 @@ export default {
216
218
  return options
217
219
  },
218
220
 
219
- hasOption(option) {
220
- return !!this.getOptionForValue(this.getValueForOption(option))
221
- },
222
-
223
221
  getOptionForValue(value) {
224
222
  const findOption = (options, value, groupBy) => {
225
223
  // Search for the option object with the given value and return the
@@ -244,7 +242,7 @@ export default {
244
242
  getValueForOption(option) {
245
243
  const { optionValue } = this
246
244
  return isString(optionValue)
247
- ? option?.[optionValue]
245
+ ? option?.[optionValue] ?? null
248
246
  : isFunction(optionValue)
249
247
  ? optionValue(new DitoContext(this, { option }))
250
248
  : option