From 90eb40fd09f9d44475044ee37cf659568c0eca32 Mon Sep 17 00:00:00 2001 From: Pierre Donias Date: Wed, 6 Oct 2021 17:46:55 +0200 Subject: [PATCH 1/3] fix(xo-web/job): properly handle array arguments See https://xcp-ng.org/forum/topic/5010 When creating/editing a job, properties of type `array` must not go through the cross product builder, they must be saved as arrays. --- CHANGELOG.unreleased.md | 2 ++ packages/xo-web/src/xo-app/jobs/new/index.js | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 377666f0086..0eb7faf1c6d 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -13,6 +13,8 @@ > Users must be able to say: “I had this issue, happy to know it's fixed” +- [Jobs] Fix `job.runSequence` method + ### Packages to release > Packages will be released in the order they are here, therefore, they should diff --git a/packages/xo-web/src/xo-app/jobs/new/index.js b/packages/xo-web/src/xo-app/jobs/new/index.js index 18bec1868fa..e6a52e2f90f 100644 --- a/packages/xo-web/src/xo-app/jobs/new/index.js +++ b/packages/xo-web/src/xo-app/jobs/new/index.js @@ -92,10 +92,10 @@ const reduceObject = (value, propertyName = 'id') => (value != null && value[pro /** * Adapts all data "arrayed" by UI-multiple-selectors to job's cross-product trick */ -const dataToParamVectorItems = function (params, data) { +const dataToParamVectorItems = function (params, data, properties) { const items = [] forEach(params, (param, name) => { - if (Array.isArray(data[name]) && param.items) { + if (properties[name].multi && param.items) { // We have an array for building cross product, the "real" type was $type const values = [] if (data[name].length === 1) { @@ -287,7 +287,8 @@ export default class Jobs extends Component { _handleSubmit = () => { const { name, method, params } = this.refs - const { job, owner, timeout } = this.state + const { actions, job, owner, timeout } = this.state + const action = find(actions, { method: job.method }) const _job = { type: 'call', name: name.value, @@ -295,7 +296,7 @@ export default class Jobs extends Component { method: method.value.method, paramsVector: { type: 'crossProduct', - items: dataToParamVectorItems(method.value.info.properties, params.value), + items: dataToParamVectorItems(method.value.info.properties, params.value, action.uiSchema.properties), }, userId: owner !== undefined ? owner : this.props.currentUser.id, timeout: timeout ? timeout * 1e3 : undefined, From 4914c040b1810d1f8d1623c11bcefe052273f7fe Mon Sep 17 00:00:00 2001 From: Pierre Donias Date: Mon, 11 Oct 2021 16:40:23 +0200 Subject: [PATCH 2/3] PR --- CHANGELOG.unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 0eb7faf1c6d..fb2f59153cd 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -13,7 +13,7 @@ > Users must be able to say: “I had this issue, happy to know it's fixed” -- [Jobs] Fix `job.runSequence` method +- [Jobs] Fix `job.runSequence` method (PR [#5944](https://github.com/vatesfr/xen-orchestra/pull/5944)) ### Packages to release From 9393f843dcef474c9aba6bab4bc01788e49f288f Mon Sep 17 00:00:00 2001 From: Pierre Donias Date: Fri, 15 Oct 2021 10:19:14 +0200 Subject: [PATCH 3/3] Fix creation case --- packages/xo-web/src/xo-app/jobs/new/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/xo-web/src/xo-app/jobs/new/index.js b/packages/xo-web/src/xo-app/jobs/new/index.js index e6a52e2f90f..00e9015fd82 100644 --- a/packages/xo-web/src/xo-app/jobs/new/index.js +++ b/packages/xo-web/src/xo-app/jobs/new/index.js @@ -286,9 +286,9 @@ export default class Jobs extends Component { _handleSubmit = () => { const { name, method, params } = this.refs + const { action, actions, job, owner, timeout } = this.state - const { actions, job, owner, timeout } = this.state - const action = find(actions, { method: job.method }) + const _action = job === undefined ? action : find(actions, { method: job.method }) const _job = { type: 'call', name: name.value, @@ -296,7 +296,7 @@ export default class Jobs extends Component { method: method.value.method, paramsVector: { type: 'crossProduct', - items: dataToParamVectorItems(method.value.info.properties, params.value, action.uiSchema.properties), + items: dataToParamVectorItems(method.value.info.properties, params.value, _action.uiSchema.properties), }, userId: owner !== undefined ? owner : this.props.currentUser.id, timeout: timeout ? timeout * 1e3 : undefined,