Skip to content

Commit 81cf360

Browse files
committed
fix: Handle object values correctly in QStringControlRenderer setup function
1 parent 5b33270 commit 81cf360

File tree

6 files changed

+47
-22
lines changed

6 files changed

+47
-22
lines changed

src/components/2pan/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ async function cancel() {
285285
targetId.value = null
286286
target.value = null
287287
selected.value = []
288-
router.push({ query: { ...route.query, read: undefined } })
288+
await router.push({ query: { ...route.query, read: null } })
289289
}
290290
async function read(row) {
291291
targetId.value = row?._id
@@ -357,6 +357,7 @@ onMounted(async () => {
357357
return
358358
}
359359
const newTarget = await props.actions.onMounted()
360+
console.log('newTarget', newTarget)
360361
if (newTarget) {
361362
target.value = { ...newTarget }
362363
targetId.value = (newTarget as any)?._id

src/components/quasar-jsonform/controls/QArrayControlRenderer.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template lang="pug">
22
//control-wrapper(v-bind="controlWrapper" :styles="styles" :isFocused="isFocused" :appliedOptions="appliedOptions")
33
div
4+
//- pre(v-html="JSON.stringify(control.data)")
45
q-select(
56
:model-value="control.data"
67
:options="suggestions"
@@ -68,11 +69,20 @@ const QStringControlRenderer = defineComponent({
6869
setup(props: RendererProps<ControlElement>) {
6970
return useQuasarControl(
7071
useJsonFormsControl(props),
71-
(value) => isObject(value) ? value.value : value || undefined
72+
(value) => {
73+
return isObject(value) ? value.value || [] : value || []
74+
}
7275
)
7376
},
7477
methods: {
78+
onChange(val) {
79+
console.log('val', val)
80+
},
7581
createValue(val, done) {
82+
if (!this.control.data) {
83+
this.control.data = []
84+
this.handleChange('', null)
85+
}
7686
done(val, 'add-unique')
7787
},
7888
isIterable(obj) {
@@ -112,6 +122,12 @@ const QStringControlRenderer = defineComponent({
112122
return this.control.label === undefined ? this.control.schema.title : this.control.label;
113123
},
114124
},
125+
mounted() {
126+
if (!this.control.data) {
127+
this.control.data = []
128+
this.handleChange('', null)
129+
}
130+
}
115131
});
116132
export default QStringControlRenderer;
117133

src/components/quasar-jsonform/controls/QStringControlRenderer.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ const QStringControlRenderer = defineComponent({
7070
)
7171
},
7272
methods: {
73+
onChange(val) {
74+
console.log('val', val)
75+
},
7376
isIterable(obj) {
7477
// checks for null and undefined
7578
if (obj == null) {

src/components/quasar-jsonform/util/composition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ export const useQuasarControl = <
115115

116116
console.log('input', input.control.value.path, input.control.value.data)
117117
if (typeof input.control.value.data === 'undefined' || input.control.value.data === null && input.control.value.errors) {
118+
input.handleChange(input.control.value.path, input.control.value.schema.default || null)
118119
console.log('input.data', input.control.value.data)
119-
input.handleChange(input.control.value.path, '')
120120
}
121121
console.log('input.data', input.control.value)
122122

@@ -282,4 +282,4 @@ export const useNested = (element: false | 'array' | 'object'): NestedInfo => {
282282
});
283283
}
284284
return nestedInfo;
285-
};
285+
};

src/composables/useAgentsSchema.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function useAgentsSchema() {
2121
},
2222
"state.current": {
2323
"type": "number",
24+
"default": 1,
2425
"description": "État actuel"
2526
},
2627
"baseURL": {
@@ -96,24 +97,24 @@ export default function useAgentsSchema() {
9697
}
9798
]
9899
},
99-
// {
100-
// "type": "HorizontalLayout",
101-
// "elements": [
102-
// {
103-
// "type": "Control",
104-
// "label": "Base URL",
105-
// "scope": "#/properties/baseURL"
106-
// },
107-
// {
108-
// "type": "Control",
109-
// "label": "Allowed Networks",
110-
// "scope": "#/properties/allowedNetworks",
111-
// "options": {
112-
// "detail": "List of networks allowed to access the agent"
113-
// }
114-
// }
115-
// ]
116-
// },
100+
{
101+
"type": "HorizontalLayout",
102+
"elements": [
103+
{
104+
"type": "Control",
105+
"label": "Base URL",
106+
"scope": "#/properties/baseURL"
107+
},
108+
{
109+
"type": "Control",
110+
"label": "Allowed Networks",
111+
"scope": "#/properties/allowedNetworks",
112+
"options": {
113+
"detail": "List of networks allowed to access the agent"
114+
}
115+
}
116+
]
117+
},
117118
]
118119
})
119120

src/pages/agents/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,12 @@ function logs(agent: Agent) {
165165
const actions = {
166166
cancel: async (row: Agent) => {
167167
console.log('cancel')
168+
validations.value = {}
168169
},
169170
create: async (row: Agent) => {
170171
172+
// console.log('row', row)
173+
171174
const sanitizedAgent = { ...row }
172175
delete sanitizedAgent.metadata
173176
@@ -259,6 +262,7 @@ const actions = {
259262
const { data } = await useHttp<Agent>(`/core/agents/${row._id}`, {
260263
method: 'get',
261264
})
265+
validations.value = {}
262266
return data.value?.data
263267
},
264268
onMounted: async () => {

0 commit comments

Comments
 (0)