diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/DeleteForm/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/DeleteForm/index.js new file mode 100644 index 0000000000..b0871bc31a --- /dev/null +++ b/src/fireedge/src/client/components/Forms/VmTemplate/DeleteForm/index.js @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- * + * Copyright 2002-2022, 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 { + SCHEMA, + FIELDS, +} from 'client/components/Forms/VmTemplate/DeleteForm/schema' + +const DeleteForm = createForm(SCHEMA, FIELDS) + +export default DeleteForm diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/DeleteForm/schema.js b/src/fireedge/src/client/components/Forms/VmTemplate/DeleteForm/schema.js new file mode 100644 index 0000000000..eca0bea0bc --- /dev/null +++ b/src/fireedge/src/client/components/Forms/VmTemplate/DeleteForm/schema.js @@ -0,0 +1,32 @@ +/* ------------------------------------------------------------------------- * + * Copyright 2002-2022, 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 { object, boolean } from 'yup' +import { T, INPUT_TYPES } from 'client/constants' +import { getValidationFromFields } from 'client/utils' + +const DELETE_IMAGE = { + name: 'image', + label: T.DeleteAllImages, + type: INPUT_TYPES.SWITCH, + tooltip: T.DeleteAllImagesConcept, + validation: boolean() + .notRequired() + .default(() => false), +} + +export const FIELDS = [DELETE_IMAGE] + +export const SCHEMA = object(getValidationFromFields(FIELDS)) diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/index.js index 663cadfcf6..46b2c62904 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/index.js @@ -31,6 +31,13 @@ const CloneForm = (configProps) => const CreateForm = (configProps) => AsyncLoadForm({ formPath: 'VmTemplate/CreateForm' }, configProps) +/** + * @param {ConfigurationProps} configProps - Configuration + * @returns {ReactElement|CreateStepsCallback} Asynchronous loaded form + */ +const DeleteForm = (configProps) => + AsyncLoadForm({ formPath: 'VmTemplate/DeleteForm' }, configProps) + /** * @param {ConfigurationProps} configProps - Configuration * @returns {ReactElement|CreateStepsCallback} Asynchronous loaded form @@ -38,4 +45,4 @@ const CreateForm = (configProps) => const InstantiateForm = (configProps) => AsyncLoadForm({ formPath: 'VmTemplate/InstantiateForm' }, configProps) -export { CloneForm, CreateForm, InstantiateForm } +export { CloneForm, CreateForm, DeleteForm, InstantiateForm } diff --git a/src/fireedge/src/client/components/Tables/VmTemplates/actions.js b/src/fireedge/src/client/components/Tables/VmTemplates/actions.js index 206d27683c..662da90e2a 100644 --- a/src/fireedge/src/client/components/Tables/VmTemplates/actions.js +++ b/src/fireedge/src/client/components/Tables/VmTemplates/actions.js @@ -37,7 +37,7 @@ import { } from 'client/features/OneApi/vmTemplate' import { ChangeUserForm, ChangeGroupForm } from 'client/components/Forms/Vm' -import { CloneForm } from 'client/components/Forms/VmTemplate' +import { CloneForm, DeleteForm } from 'client/components/Forms/VmTemplate' import { createActions, GlobalAction, @@ -318,14 +318,26 @@ const Actions = () => { color: 'error', options: [ { - isConfirmDialog: true, dialogProps: { - title: T.Delete, - children: MessageToConfirmAction, + title: (rows) => { + const isMultiple = rows?.length > 1 + const { ID, NAME } = rows?.[0]?.original ?? {} + + return [ + Tr( + isMultiple ? T.DeleteSeveralTemplates : T.DeleteTemplate + ), + !isMultiple && `#${ID} ${NAME}`, + ] + .filter(Boolean) + .join(' - ') + }, }, - onSubmit: (rows) => async () => { + form: DeleteForm, + onSubmit: (rows) => async (formData) => { + const { image } = formData ?? {} const ids = rows?.map?.(({ original }) => original?.ID) - await Promise.all(ids.map((id) => remove({ id }))) + await Promise.all(ids.map((id) => remove({ id, image }))) }, }, ], diff --git a/src/fireedge/src/client/constants/translates.js b/src/fireedge/src/client/constants/translates.js index 98732e44b8..c237300b03 100644 --- a/src/fireedge/src/client/constants/translates.js +++ b/src/fireedge/src/client/constants/translates.js @@ -63,7 +63,10 @@ module.exports = { Delete: 'Delete', DeleteDb: 'Delete database', DeleteScheduleAction: 'Delete schedule action: %s', + DeleteSeveralTemplates: 'Delete several Templates', + DeleteTemplate: 'Delete Template', DeleteSomething: 'Delete: %s', + DeleteAllImages: 'Delete all images', Deploy: 'Deploy', Detach: 'Detach', DetachSomething: 'Detach: %s', @@ -733,6 +736,8 @@ module.exports = { Number of virtual CPUs. This value is optional, the default hypervisor behavior is used, usually one virtual CPU`, /* VM Template schema - actions */ + DeleteAllImagesConcept: + 'Enable to delete the template plus any image defined in DISK', CopyOf: 'Copy of ', PrefixMultipleConcept: 'Several templates are selected, please choose prefix to name the new copies', diff --git a/src/fireedge/src/client/features/OneApi/vmTemplate.js b/src/fireedge/src/client/features/OneApi/vmTemplate.js index db7bd975d1..f27b2bcb8a 100644 --- a/src/fireedge/src/client/features/OneApi/vmTemplate.js +++ b/src/fireedge/src/client/features/OneApi/vmTemplate.js @@ -33,7 +33,7 @@ import { import { LockLevel, FilterFlag, Permission, VmTemplate } from 'client/constants' const { TEMPLATE } = ONE_RESOURCES -const { TEMPLATE_POOL, VM_POOL } = ONE_RESOURCES_POOL +const { TEMPLATE_POOL, VM_POOL, IMAGE_POOL } = ONE_RESOURCES_POOL const vmTemplateApi = oneApi.injectEndpoints({ endpoints: (builder) => ({ @@ -163,7 +163,11 @@ const vmTemplateApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: [TEMPLATE_POOL], + invalidatesTags: (_, __, { id, image }) => [ + TEMPLATE_POOL, + { type: TEMPLATE, id }, + ...(image ? [IMAGE_POOL] : []), + ], }), instantiateTemplate: builder.mutation({ /**