1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

F #5877: sunstone storage app actions (#2187)

This commit is contained in:
Jorge Miguel Lobo Escalona 2022-06-24 18:39:41 +02:00 committed by GitHub
parent f1beecd07e
commit ee61537df2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 200 additions and 12 deletions

View File

@ -19,7 +19,12 @@ import {
AddCircledOutline,
CloudDownload,
DownloadCircledOutline,
Lock,
MoreVert,
Group,
Trash,
} from 'iconoir-react'
import PropTypes from 'prop-types'
import { useViews } from 'client/features/Auth'
import { useGeneralApi } from 'client/features/General'
@ -27,6 +32,12 @@ import { Translate } from 'client/components/HOC'
import {
useExportAppMutation,
useDownloadAppMutation,
useLockAppMutation,
useUnlockAppMutation,
useEnableAppMutation,
useDisableAppMutation,
useChangeAppOwnershipMutation,
useDeleteAppMutation,
} from 'client/features/OneApi/marketplaceApp'
import { ExportForm } from 'client/components/Forms/MarketplaceApp'
@ -37,22 +48,37 @@ import {
import { PATH } from 'client/apps/sunstone/routesOne'
import { T, RESOURCE_NAMES, MARKETPLACE_APP_ACTIONS } from 'client/constants'
import { ChangeGroupForm, ChangeUserForm } from 'client/components/Forms/Vm'
import { Typography } from '@mui/material'
const MessageToConfirmAction = (rows) => {
const ListAppNames = ({ rows = [] }) => {
const names = rows?.map?.(({ original }) => original?.NAME)
return (
<>
<p>
<Translate word={T.Apps} />
{`: ${names.join(', ')}`}
</p>
<p>
<Translate word={T.DoYouWantProceed} />
</p>
</>
<Typography variant="inherit" component="span" display="block">
<Translate word={T.Apps} />
{`: ${names.join(', ')}`}
</Typography>
)
}
ListAppNames.propTypes = {
rows: PropTypes.arrayOf(
PropTypes.shape({
original: PropTypes.shape({
NAME: PropTypes.string,
}),
})
),
}
const SubHeader = (rows) => <ListAppNames rows={rows} />
const MessageToConfirmAction = (rows) => (
<>
<ListAppNames rows={rows} />
<Translate word={T.DoYouWantProceed} />
</>
)
MessageToConfirmAction.displayName = 'MessageToConfirmAction'
@ -67,6 +93,12 @@ const Actions = () => {
const { enqueueSuccess } = useGeneralApi()
const [exportApp] = useExportAppMutation()
const [downloadApp] = useDownloadAppMutation()
const [lock] = useLockAppMutation()
const [unlock] = useUnlockAppMutation()
const [enable] = useEnableAppMutation()
const [disable] = useDisableAppMutation()
const [changeOwnership] = useChangeAppOwnershipMutation()
const [deleteApp] = useDeleteAppMutation()
const marketplaceAppActions = useMemo(
() =>
@ -117,6 +149,142 @@ const Actions = () => {
urls.forEach((url) => window.open(url, '_blank'))
},
},
{
tooltip: T.Lock,
icon: Lock,
selected: true,
color: 'secondary',
dataCy: 'marketapp-lock',
options: [
{
accessor: MARKETPLACE_APP_ACTIONS.LOCK,
name: T.Lock,
isConfirmDialog: true,
dialogProps: {
title: T.Lock,
children: MessageToConfirmAction,
dataCy: `modal-${MARKETPLACE_APP_ACTIONS.LOCK}`,
},
onSubmit: (rows) => async () => {
const ids = rows?.map?.(({ original }) => original?.ID)
await Promise.all(ids.map((id) => lock({ id })))
},
},
{
accessor: MARKETPLACE_APP_ACTIONS.UNLOCK,
name: T.Unlock,
isConfirmDialog: true,
dialogProps: {
title: T.Unlock,
children: MessageToConfirmAction,
dataCy: `modal-${MARKETPLACE_APP_ACTIONS.UNLOCK}`,
},
onSubmit: (rows) => async () => {
const ids = rows?.map?.(({ original }) => original?.ID)
await Promise.all(ids.map((id) => unlock({ id })))
},
},
],
},
{
tooltip: T.Enable,
icon: MoreVert,
selected: true,
color: 'secondary',
dataCy: 'marketapp-enable',
options: [
{
accessor: MARKETPLACE_APP_ACTIONS.ENABLE,
name: T.Enable,
isConfirmDialog: true,
dialogProps: {
title: T.Enable,
children: MessageToConfirmAction,
dataCy: `modal-${MARKETPLACE_APP_ACTIONS.ENABLE}`,
},
onSubmit: (rows) => async () => {
const ids = rows?.map?.(({ original }) => original?.ID)
await Promise.all(ids.map((id) => enable(id)))
},
},
{
accessor: MARKETPLACE_APP_ACTIONS.DISABLE,
name: T.Disable,
isConfirmDialog: true,
dialogProps: {
title: T.Disable,
children: MessageToConfirmAction,
dataCy: `modal-${MARKETPLACE_APP_ACTIONS.DISABLE}`,
},
onSubmit: (rows) => async () => {
const ids = rows?.map?.(({ original }) => original?.ID)
await Promise.all(ids.map((id) => disable(id)))
},
},
],
},
{
tooltip: T.Ownership,
icon: Group,
selected: true,
color: 'secondary',
dataCy: 'vm-ownership',
options: [
{
accessor: MARKETPLACE_APP_ACTIONS.CHANGE_OWNER,
name: T.ChangeOwner,
dialogProps: {
title: T.ChangeOwner,
subheader: SubHeader,
dataCy: `modal-${MARKETPLACE_APP_ACTIONS.CHANGE_OWNER}`,
},
form: ChangeUserForm,
onSubmit: (rows) => async (newOwnership) => {
const ids = rows?.map?.(({ original }) => original?.ID)
await Promise.all(
ids.map((id) => changeOwnership({ id, ...newOwnership }))
)
},
},
{
accessor: MARKETPLACE_APP_ACTIONS.CHANGE_GROUP,
name: T.ChangeGroup,
dialogProps: {
title: T.ChangeGroup,
subheader: SubHeader,
dataCy: `modal-${MARKETPLACE_APP_ACTIONS.CHANGE_GROUP}`,
},
form: ChangeGroupForm,
onSubmit: (rows) => async (newOwnership) => {
const ids = rows?.map?.(({ original }) => original?.ID)
await Promise.all(
ids.map((id) => changeOwnership({ id, ...newOwnership }))
)
},
},
],
},
{
accessor: MARKETPLACE_APP_ACTIONS.DELETE,
tooltip: T.Delete,
icon: Trash,
color: 'error',
selected: { min: 1 },
options: [
{
isConfirmDialog: true,
dialogProps: {
title: T.Delete,
dataCy: `modal-${MARKETPLACE_APP_ACTIONS.DELETE}`,
children: MessageToConfirmAction,
},
onSubmit: (rows) => async () => {
const ids = rows?.map?.(({ original }) => original?.ID)
await Promise.all(ids.map((id) => deleteApp({ id })))
},
},
],
},
],
}),
[view]

View File

@ -56,6 +56,8 @@ export const MARKETPLACE_APP_ACTIONS = {
DISABLE: 'disable',
DELETE: 'delete',
EDIT_LABELS: 'edit_labels',
LOCK: 'lock',
UNLOCK: 'unlock',
// INFORMATION
RENAME: ACTIONS.RENAME,

View File

@ -484,6 +484,23 @@ const marketAppApi = oneApi.injectEndpoints({
},
invalidatesTags: [APP_POOL],
}),
deleteApp: builder.mutation({
/**
* Delete Marketplaceapp.
*
* @param {object} params - Request parameters
* @param {string} params.id - Marketplaceapp ID
* @returns {number} Marketplace app id
* @throws Fails when response isn't code 200
*/
query: (params) => {
const name = Actions.MARKETAPP_DELETE
const command = { name, ...Commands[name] }
return { params, command }
},
invalidatesTags: (_, __, { id }) => [{ type: APP, id }],
}),
downloadApp: builder.mutation({
/**
* Download a MarketPlaceApp.
@ -559,6 +576,7 @@ export const {
useImportAppMutation,
useExportAppMutation,
useDownloadAppMutation,
useDeleteAppMutation,
} = marketAppApi
export default marketAppApi

View File

@ -158,11 +158,11 @@ module.exports = {
from: resource,
default: 0,
},
userId: {
user: {
from: postBody,
default: -1,
},
groupId: {
group: {
from: postBody,
default: -1,
},