|
3 | 3 | <Element |
4 | 4 | :section="root" |
5 | 5 | :parentPathComplete="parentPathComplete" |
6 | | - :blockSchemaPath="[blockSchemaPath, 'properties', root.split('.').pop()].join('/')" |
7 | | - :element="{ |
8 | | - id: model?.id ?? 'Set a task', |
| 6 | + :blockSchemaPath |
| 7 | + :element="Object.keys(model).length > 0 ? { |
| 8 | + id: (localSchema?.properties?.id ? model?.id : undefined), |
9 | 9 | type: model?.type, |
10 | | - }" |
| 10 | + } : {id: fieldTitle}" |
11 | 11 | typeFieldSchema="type" |
12 | 12 | @remove-element="removeElement()" |
13 | 13 | /> |
|
20 | 20 | PARENT_PATH_INJECTION_KEY, |
21 | 21 | REF_PATH_INJECTION_KEY, |
22 | 22 | CREATING_TASK_INJECTION_KEY, |
23 | | - BLOCK_SCHEMA_PATH_INJECTION_KEY |
| 23 | + BLOCK_SCHEMA_PATH_INJECTION_KEY, |
| 24 | + FULL_SCHEMA_INJECTION_KEY |
24 | 25 | } from "../../injectionKeys"; |
25 | 26 | import Element from "./taskList/Element.vue"; |
| 27 | + import {getValueAtJsonPath} from "../../../../utils/utils"; |
| 28 | +
|
26 | 29 |
|
27 | 30 | const model = defineModel({ |
28 | 31 | type: Object, |
|
36 | 39 | }, |
37 | 40 | }); |
38 | 41 |
|
| 42 | + defineOptions({ |
| 43 | + inheritAttrs: false |
| 44 | + }) |
| 45 | +
|
39 | 46 | const parentPath = inject(PARENT_PATH_INJECTION_KEY, ""); |
40 | 47 | const refPath = inject(REF_PATH_INJECTION_KEY, undefined); |
41 | 48 | const creatingTask = inject(CREATING_TASK_INJECTION_KEY, false); |
42 | | - const blockSchemaPath = inject(BLOCK_SCHEMA_PATH_INJECTION_KEY, ref()) |
| 49 | + const blockSchemaPathInjected = inject(BLOCK_SCHEMA_PATH_INJECTION_KEY, ref()) |
| 50 | + const fullSchema = inject(FULL_SCHEMA_INJECTION_KEY, ref({})) |
| 51 | +
|
| 52 | + const blockSchemaPath = computed(() => { |
| 53 | + return [blockSchemaPathInjected.value, "properties", props.root.split(".").pop()].join("/") |
| 54 | + }) |
| 55 | +
|
| 56 | + const localSchema = computed(() => getValueAtJsonPath(fullSchema.value, blockSchemaPath.value)) |
| 57 | +
|
| 58 | + const fieldTitle = computed(() => { |
| 59 | + const schema = localSchema.value; |
| 60 | +
|
| 61 | + if(schema?.anyOf && Array.isArray(schema.anyOf)){ |
| 62 | + // find all the title fields in the anyOf |
| 63 | + const titles: string[] = schema.anyOf.map((s: any) => s.allOf?.find((a: any) => a.title)?.title ?? s.title); |
| 64 | +
|
| 65 | + // if all the titles are the same, return that title |
| 66 | + if(titles.every((t) => t === titles[0])){ |
| 67 | + return titles[0]; |
| 68 | + } |
| 69 | + } |
| 70 | + return "Set a task" |
| 71 | + }) |
43 | 72 |
|
44 | 73 | const parentPathComplete = computed(() => { |
45 | 74 | return `${[ |
|
0 commit comments