diff --git a/src/fireedge/src/client/features/One/hooks.js b/src/fireedge/src/client/features/One/hooks.js index 1824036aba..8a27a22e3c 100644 --- a/src/fireedge/src/client/features/One/hooks.js +++ b/src/fireedge/src/client/features/One/hooks.js @@ -10,7 +10,9 @@ export * from 'client/features/One/cluster/hooks' export * from 'client/features/One/datastore/hooks' export * from 'client/features/One/group/hooks' export * from 'client/features/One/host/hooks' -export * from 'client/features/One/marketApp/hooks' +export * from 'client/features/One/image/hooks' +export * from 'client/features/One/marketplace/hooks' +export * from 'client/features/One/marketplaceApp/hooks' export * from 'client/features/One/provider/hooks' export * from 'client/features/One/provision/hooks' export * from 'client/features/One/user/hooks' diff --git a/src/fireedge/src/client/features/One/image/actions.js b/src/fireedge/src/client/features/One/image/actions.js new file mode 100644 index 0000000000..c7854f9263 --- /dev/null +++ b/src/fireedge/src/client/features/One/image/actions.js @@ -0,0 +1,10 @@ +import { createAction } from 'client/features/One/utils' +import { imageService } from 'client/features/One/image/services' + +export const getImage = createAction('image', imageService.getImage) + +export const getImages = createAction( + 'image/pool', + imageService.getImages, + response => ({ images: response }) +) diff --git a/src/fireedge/src/client/features/One/image/hooks.js b/src/fireedge/src/client/features/One/image/hooks.js new file mode 100644 index 0000000000..4159d18669 --- /dev/null +++ b/src/fireedge/src/client/features/One/image/hooks.js @@ -0,0 +1,23 @@ +import { useCallback } from 'react' +import { useDispatch, useSelector } from 'react-redux' +import { unwrapResult } from '@reduxjs/toolkit' + +import * as actions from 'client/features/One/image/actions' + +export const useImage = () => ( + useSelector(state => state.one.images) +) + +export const useImageApi = () => { + const dispatch = useDispatch() + + const unwrapDispatch = useCallback( + action => dispatch(action).then(unwrapResult) + , [dispatch] + ) + + return { + getImage: id => unwrapDispatch(actions.getImage({ id })), + getImages: () => unwrapDispatch(actions.getImages()) + } +} diff --git a/src/fireedge/src/client/features/One/image/services.js b/src/fireedge/src/client/features/One/image/services.js new file mode 100644 index 0000000000..027097ffc7 --- /dev/null +++ b/src/fireedge/src/client/features/One/image/services.js @@ -0,0 +1,25 @@ +import { Actions, Commands } from 'server/utils/constants/commands/image' +import { httpCodes } from 'server/utils/constants' +import { requestParams, RestClient } from 'client/utils' +import { poolRequest } from 'client/features/One/utils' + +export const imageService = ({ + getImage: ({ filter, id }) => { + const name = Actions.IMAGE_INFO + const { url, options } = requestParams( + { filter, id }, + { name, ...Commands[name] } + ) + + return RestClient.get(url, options).then(res => { + if (!res?.id || res?.id !== httpCodes.ok.id) throw res + + return res?.data?.IMAGE ?? {} + }) + }, + getImages: data => { + const name = Actions.IMAGE_POOL_INFO + const command = { name, ...Commands[name] } + return poolRequest(data, command, 'IMAGE') + } +}) diff --git a/src/fireedge/src/client/features/One/marketApp/actions.js b/src/fireedge/src/client/features/One/marketApp/actions.js deleted file mode 100644 index 9d26eb001f..0000000000 --- a/src/fireedge/src/client/features/One/marketApp/actions.js +++ /dev/null @@ -1,10 +0,0 @@ -import { createAction } from 'client/features/One/utils' -import { marketAppService } from 'client/features/One/marketApp/services' - -export const getMarketApp = createAction('app', marketAppService.getMarketApp) - -export const getMarketApps = createAction( - 'app/pool', - marketAppService.getMarketApps, - response => ({ apps: response }) -) diff --git a/src/fireedge/src/client/features/One/marketplace/actions.js b/src/fireedge/src/client/features/One/marketplace/actions.js new file mode 100644 index 0000000000..365f7bdffd --- /dev/null +++ b/src/fireedge/src/client/features/One/marketplace/actions.js @@ -0,0 +1,10 @@ +import { createAction } from 'client/features/One/utils' +import { marketplaceService } from 'client/features/One/marketplace/services' + +export const getMarketplace = createAction('marketplace', marketplaceService.getMarketplace) + +export const getMarketplaces = createAction( + 'marketplace/pool', + marketplaceService.getMarketplaces, + response => ({ marketplaces: response }) +) diff --git a/src/fireedge/src/client/features/One/marketplace/hooks.js b/src/fireedge/src/client/features/One/marketplace/hooks.js new file mode 100644 index 0000000000..7a4b81ed00 --- /dev/null +++ b/src/fireedge/src/client/features/One/marketplace/hooks.js @@ -0,0 +1,23 @@ +import { useCallback } from 'react' +import { useDispatch, useSelector } from 'react-redux' +import { unwrapResult } from '@reduxjs/toolkit' + +import * as actions from 'client/features/One/marketplace/actions' + +export const useMarketplace = () => ( + useSelector(state => state.one.marketplaces) +) + +export const useMarketplaceApi = () => { + const dispatch = useDispatch() + + const unwrapDispatch = useCallback( + action => dispatch(action).then(unwrapResult) + , [dispatch] + ) + + return { + getMarketplace: id => unwrapDispatch(actions.getMarketplace({ id })), + getMarketplaces: () => unwrapDispatch(actions.getMarketplaces()) + } +} diff --git a/src/fireedge/src/client/features/One/marketplace/services.js b/src/fireedge/src/client/features/One/marketplace/services.js new file mode 100644 index 0000000000..a8cf8504f6 --- /dev/null +++ b/src/fireedge/src/client/features/One/marketplace/services.js @@ -0,0 +1,25 @@ +import { Actions, Commands } from 'server/utils/constants/commands/market' +import { httpCodes } from 'server/utils/constants' +import { requestParams, RestClient } from 'client/utils' +import { poolRequest } from 'client/features/One/utils' + +export const marketplaceService = ({ + getMarketplace: ({ filter, id }) => { + const name = Actions.MARKET_INFO + const { url, options } = requestParams( + { filter, id }, + { name, ...Commands[name] } + ) + + return RestClient.get(url, options).then(res => { + if (!res?.id || res?.id !== httpCodes.ok.id) throw res + + return res?.data?.MARKETPLACE ?? {} + }) + }, + getMarketplaces: data => { + const name = Actions.MARKET_POOL_INFO + const command = { name, ...Commands[name] } + return poolRequest(data, command, 'MARKETPLACE') + } +}) diff --git a/src/fireedge/src/client/features/One/marketplaceApp/actions.js b/src/fireedge/src/client/features/One/marketplaceApp/actions.js new file mode 100644 index 0000000000..3d37fcc5d6 --- /dev/null +++ b/src/fireedge/src/client/features/One/marketplaceApp/actions.js @@ -0,0 +1,13 @@ +import { createAction } from 'client/features/One/utils' +import { marketplaceAppService } from 'client/features/One/marketplaceApp/services' + +export const getMarketplaceApp = createAction( + 'app', + marketplaceAppService.getMarketplaceApp +) + +export const getMarketplaceApps = createAction( + 'app/pool', + marketplaceAppService.getMarketplaceApps, + response => ({ apps: response }) +) diff --git a/src/fireedge/src/client/features/One/marketApp/hooks.js b/src/fireedge/src/client/features/One/marketplaceApp/hooks.js similarity index 52% rename from src/fireedge/src/client/features/One/marketApp/hooks.js rename to src/fireedge/src/client/features/One/marketplaceApp/hooks.js index 3424ff00f0..1fc8d0aba5 100644 --- a/src/fireedge/src/client/features/One/marketApp/hooks.js +++ b/src/fireedge/src/client/features/One/marketplaceApp/hooks.js @@ -2,13 +2,13 @@ import { useCallback } from 'react' import { useDispatch, useSelector } from 'react-redux' import { unwrapResult } from '@reduxjs/toolkit' -import * as actions from 'client/features/One/marketApp/actions' +import * as actions from 'client/features/One/marketplaceApp/actions' -export const useMarketApp = () => ( +export const useMarketplaceApp = () => ( useSelector(state => state.one.apps) ) -export const useMarketAppApi = () => { +export const useMarketplaceAppApi = () => { const dispatch = useDispatch() const unwrapDispatch = useCallback( @@ -17,7 +17,7 @@ export const useMarketAppApi = () => { ) return { - getMarketApp: id => unwrapDispatch(actions.getMarketApp({ id })), - getMarketApps: () => unwrapDispatch(actions.getMarketApps()) + getMarketplaceApp: id => unwrapDispatch(actions.getMarketplaceApp({ id })), + getMarketplaceApps: () => unwrapDispatch(actions.getMarketplaceApps()) } } diff --git a/src/fireedge/src/client/features/One/marketApp/services.js b/src/fireedge/src/client/features/One/marketplaceApp/services.js similarity index 86% rename from src/fireedge/src/client/features/One/marketApp/services.js rename to src/fireedge/src/client/features/One/marketplaceApp/services.js index 14f959fed9..242c3105e5 100644 --- a/src/fireedge/src/client/features/One/marketApp/services.js +++ b/src/fireedge/src/client/features/One/marketplaceApp/services.js @@ -3,8 +3,8 @@ import { httpCodes } from 'server/utils/constants' import { requestParams, RestClient } from 'client/utils' import { poolRequest } from 'client/features/One/utils' -export const marketAppService = ({ - getMarketApp: ({ filter, id }) => { +export const marketplaceAppService = ({ + getMarketplaceApp: ({ filter, id }) => { const name = Actions.MARKETAPP_INFO const { url, options } = requestParams( { filter, id }, @@ -17,7 +17,7 @@ export const marketAppService = ({ return res?.data?.MARKETAPP ?? {} }) }, - getMarketApps: data => { + getMarketplaceApps: data => { const name = Actions.MARKETAPP_POOL_INFO const command = { name, ...Commands[name] } return poolRequest(data, command, 'MARKETPLACEAPP') diff --git a/src/fireedge/src/client/features/One/slice.js b/src/fireedge/src/client/features/One/slice.js index 124138d5e6..7c76072c31 100644 --- a/src/fireedge/src/client/features/One/slice.js +++ b/src/fireedge/src/client/features/One/slice.js @@ -5,30 +5,30 @@ import { socketEventState } from 'client/features/One/socket/actions' const initial = { requests: {}, - vms: [], - templates: [], + acl: [], applications: [], applicationsTemplates: [], + apps: [], + clusters: [], datastores: [], + files: [], + groups: [], + hosts: [], + images: [], + marketplaces: [], + providers: [], + provisions: [], + provisionsTemplates: [], + securityGroups: [], + templates: [], + users: [], + vdc: [], virtualRouters: [], vmGroups: [], - images: [], - files: [], - marketplaces: [], - apps: [], + vms: [], vNetworks: [], vNetworksTemplates: [], - securityGroups: [], - clusters: [], - hosts: [], - zones: [], - users: [], - groups: [], - vdc: [], - acl: [], - provisionsTemplates: [], - providers: [], - provisions: [] + zones: [] } const { actions, reducer } = createSlice({