-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M #-: Schedule actions tab on services. Perform action on role. (#3206)
Signed-off-by: dcarracedo <[email protected]>
- Loading branch information
1 parent
92541b6
commit 5dff938
Showing
14 changed files
with
433 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/fireedge/src/client/components/Forms/Service/PerformAction/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* ------------------------------------------------------------------------- * | ||
* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may * | ||
* not use this file except in compliance with the License. You may obtain * | ||
* a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
* ------------------------------------------------------------------------- */ | ||
import { createForm } from 'client/utils' | ||
|
||
import { | ||
FIELDS, | ||
SCHEMA, | ||
} from 'client/components/Forms/Service/PerformAction/schema' | ||
|
||
const PerformActionForm = createForm(SCHEMA, FIELDS, { | ||
transformBeforeSubmit: (formData) => { | ||
// Transform args for an action that needs some arguments | ||
if (formData?.ARGS) { | ||
if (formData?.ARGS?.NAME) { | ||
formData.ARGS = formData.ARGS.NAME | ||
} else if (formData?.ARGS?.SNAPSHOT_ID) { | ||
formData.ARGS = formData.ARGS.SNAPSHOT_ID | ||
} | ||
} | ||
|
||
return formData | ||
}, | ||
}) | ||
|
||
export default PerformActionForm |
132 changes: 132 additions & 0 deletions
132
src/fireedge/src/client/components/Forms/Service/PerformAction/schema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* ------------------------------------------------------------------------- * | ||
* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may * | ||
* not use this file except in compliance with the License. You may obtain * | ||
* a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
* ------------------------------------------------------------------------- */ | ||
import { ObjectSchema, string } from 'yup' | ||
import { getObjectSchemaFromFields, arrayToOptions, Field } from 'client/utils' | ||
import { | ||
INPUT_TYPES, | ||
T, | ||
VM_ACTIONS_WITH_SCHEDULE, | ||
VM_ACTIONS, | ||
ARGS_TYPES, | ||
} from 'client/constants' | ||
|
||
import { getRequiredArgsByAction } from 'client/models/Scheduler' | ||
|
||
/** | ||
* @returns {Field} Action name field | ||
*/ | ||
const ACTION_FIELD = { | ||
name: 'ACTION', | ||
label: T.Action, | ||
type: INPUT_TYPES.AUTOCOMPLETE, | ||
optionsOnly: true, | ||
values: () => { | ||
const validActions = { | ||
...VM_ACTIONS_WITH_SCHEDULE, | ||
} | ||
|
||
/** | ||
* BACKUP: Not supported by oneflow api | ||
*/ | ||
delete validActions[VM_ACTIONS.BACKUP] | ||
|
||
return arrayToOptions( | ||
Object.entries({ | ||
...validActions, | ||
}), | ||
{ | ||
addEmpty: false, | ||
getText: ([, text]) => text, | ||
getValue: ([value]) => value, | ||
} | ||
) | ||
}, | ||
validation: string().trim().required(), | ||
grid: { xs: 12 }, | ||
} | ||
|
||
export const ACTION_FIELD_NAME = 'ACTION' | ||
|
||
const createArgField = (argName, htmlType) => ({ | ||
name: `ARGS.${argName}`, | ||
dependOf: ACTION_FIELD_NAME, | ||
htmlType: (action) => { | ||
const prueba = getRequiredArgsByAction(action) | ||
console.log(argName, prueba.includes(argName)) | ||
|
||
return !getRequiredArgsByAction(action)?.includes(argName) | ||
? INPUT_TYPES.HIDDEN | ||
: htmlType | ||
}, | ||
}) | ||
|
||
/** @type {Field} Snapshot name field */ | ||
const ARGS_NAME_FIELD = { | ||
...createArgField(ARGS_TYPES.NAME), | ||
label: T.SnapshotName, | ||
type: INPUT_TYPES.TEXT, | ||
} | ||
|
||
/** | ||
* @returns {Field} Snapshot id field | ||
*/ | ||
const ARGS_SNAPSHOT_ID_FIELD = { | ||
...createArgField(ARGS_TYPES.SNAPSHOT_ID), | ||
label: T.Snapshot + ' ' + T.ID, | ||
type: INPUT_TYPES.TEXT, | ||
} | ||
|
||
const ROLE_FIELD = (roles) => ({ | ||
name: 'ROLE', | ||
label: T.Role, | ||
type: INPUT_TYPES.AUTOCOMPLETE, | ||
optionsOnly: true, | ||
values: () => { | ||
const rolesWithAll = roles.map((role) => ({ | ||
name: role.name, | ||
value: role.name, | ||
})) | ||
|
||
rolesWithAll.push({ | ||
name: T.All, | ||
value: 'ALL', | ||
}) | ||
|
||
return arrayToOptions(rolesWithAll, { | ||
addEmpty: false, | ||
getText: (role) => role.name, | ||
getValue: (role) => role.value, | ||
}) | ||
}, | ||
validation: string().trim().required(), | ||
grid: { xs: 12 }, | ||
}) | ||
|
||
/** | ||
* @param {object} props - Properties of the form | ||
* @param {object} props.roles - Roles of the service | ||
* @returns {Array} - List of fields | ||
*/ | ||
export const FIELDS = ({ roles }) => [ | ||
ACTION_FIELD, | ||
ROLE_FIELD(roles), | ||
ARGS_NAME_FIELD, | ||
ARGS_SNAPSHOT_ID_FIELD, | ||
] | ||
|
||
/** @type {ObjectSchema} Schema */ | ||
export const SCHEMA = ({ roles }) => | ||
getObjectSchemaFromFields(FIELDS({ roles })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.