Skip to content

Commit

Permalink
fix(xo-web/job): properly handle array arguments (#5944)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pdonias committed Oct 15, 2021
1 parent 84dccd8 commit e2e4539
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Backups] Delete unused snapshots related to other schedules (even no longer existing) (PR [#5949](https://github.com/vatesfr/xen-orchestra/pull/5949))
- [Jobs] Fix `job.runSequence` method (PR [#5944](https://github.com/vatesfr/xen-orchestra/pull/5944))

### Packages to release

Expand Down
9 changes: 5 additions & 4 deletions packages/xo-web/src/xo-app/jobs/new/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -286,16 +286,17 @@ export default class Jobs extends Component {

_handleSubmit = () => {
const { name, method, params } = this.refs
const { action, actions, job, owner, timeout } = this.state

const { job, owner, timeout } = this.state
const _action = job === undefined ? action : find(actions, { method: job.method })
const _job = {
type: 'call',
name: name.value,
key: JOB_KEY,
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,
Expand Down

0 comments on commit e2e4539

Please sign in to comment.