From 7446f23b3abc30d7c53f2eaa951742371c071171 Mon Sep 17 00:00:00 2001 From: Herbert Eiselt Date: Thu, 28 Feb 2019 15:23:42 +0100 Subject: UX extensions UX Maintenance client and further changes Change-Id: I7643661d17db5fc3d3f94b58cb42ed0be558c64f Issue-ID: SDNC-583 Signed-off-by: Herbert Eiselt --- .../src/actions/mountedNetworkElementsActions.ts | 47 ++++++++++++++-------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts') diff --git a/sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts b/sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts index e342f6314..1cf528aa7 100644 --- a/sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts +++ b/sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts @@ -21,7 +21,7 @@ export class AllMountedNetworkElementsLoadedAction extends BaseAction { } /** Represents an action causing the store to update all mounted network elements. */ -export class AddMountedNetworkElement extends BaseAction { +export class AddOrUpdateMountedNetworkElement extends BaseAction { constructor(public mountedNetworkElement: MountedNetworkElementType | null, public error?: string) { super(); } @@ -47,43 +47,58 @@ export class UpdateRequiredMountedNetworkElement extends BaseAction { } /** - * An actioncrator for a async thunk action to add an allready mounted element to the state of this app. - * Note: Use this action to add created object notified by the websocket. + * Represents an action crator for a async thunk action to add an allready mounted element to the state of this app. + * Note: Use this action to add created object notified by the websocket. */ export const addMountedNetworkElementAsyncActionCreator = (mountId: string) => async (dispatch: Dispatch) => { - connectService.getMountedNetworkElementByMountId(mountId).then(mountedNetworkElement => { - mountedNetworkElement && dispatch(new AddMountedNetworkElement(mountedNetworkElement)); + return connectService.getMountedNetworkElementByMountId(mountId).then(mountedNetworkElement => { + mountedNetworkElement && dispatch(new AddOrUpdateMountedNetworkElement(mountedNetworkElement)); }).catch(error => { - dispatch(new AddMountedNetworkElement(null, error)); + dispatch(new AddOrUpdateMountedNetworkElement(null, error)); + }); +}; + +export const updateMountedNetworkElementAsyncActionCreator = (mountId: string) => async (dispatch: Dispatch) => { + return connectService.getMountedNetworkElementByMountId(mountId).then(mountedNetworkElement => { + if (mountedNetworkElement) { + dispatch(new AddOrUpdateMountedNetworkElement(mountedNetworkElement)); + } else { + dispatch(new RemoveMountedNetworkElement(mountId)); + } + }).catch(error => { + dispatch(new AddOrUpdateMountedNetworkElement(null, error)); }); }; /** Represents an async thunk action to load all mounted network elements. */ export const loadAllMountedNetworkElementsAsync = (dispatch: Dispatch) => { dispatch(new LoadAllMountedNetworkElementsAction()); - connectService.getMountedNetworkElementsList().then(mountedNetworkElements => { + return connectService.getMountedNetworkElementsList().then(mountedNetworkElements => { mountedNetworkElements && dispatch(new AllMountedNetworkElementsLoadedAction(mountedNetworkElements)); }).catch(error => { dispatch(new AllMountedNetworkElementsLoadedAction(null, error)); }); }; -/** Represents an async thunk action to load all mounted network elements. */ -export const mountNetworkElementActionCreatorAsync = (networkElement: RequiredNetworkElementType) => (dispatch: Dispatch) => { - connectService.mountNetworkElement(networkElement).then((success) => { - success && dispatch(new AddSnackbarNotification({ message: `Requesting mount [${ networkElement.mountId }]`, options: { variant: 'info' } })) - || dispatch(new AddSnackbarNotification({ message: `Failed to mount [${ networkElement.mountId }]`, options: { variant: 'warning' } })); +/** Represents an action crator for a async thunk action to mount a network element. */ +export const mountNetworkElementAsyncActionCreator = (networkElement: RequiredNetworkElementType) => (dispatch: Dispatch) => { + return connectService.mountNetworkElement(networkElement).then((success) => { + success && ( + dispatch(addMountedNetworkElementAsyncActionCreator(networkElement.mountId)) && + dispatch(new AddSnackbarNotification({ message: `Requesting mount [${networkElement.mountId}]`, options: { variant: 'info' } })) + ) || dispatch(new AddSnackbarNotification({ message: `Failed to mount [${ networkElement.mountId }]`, options: { variant: 'warning' } })); }).catch(error => { - dispatch(new AddMountedNetworkElement(null, error)); + dispatch(new AddOrUpdateMountedNetworkElement(null, error)); }); }; -export const unmountNetworkElementActionCreatorAsync = (mountId: string) => (dispatch: Dispatch) => { - connectService.unmountNetworkElement(mountId).then((success) => { +/** Represents an action crator for a async thunk action to unmount a network element. */ +export const unmountNetworkElementAsyncActionCreator = (mountId: string) => (dispatch: Dispatch) => { + return connectService.unmountNetworkElement(mountId).then((success) => { success && dispatch(new AddSnackbarNotification({ message: `Requesting unmount [${ mountId }]`, options: { variant: 'info' } })) || dispatch(new AddSnackbarNotification({ message: `Failed to unmount [${ mountId }]`, options: { variant: 'warning' } })); }).catch(error => { - dispatch(new AddMountedNetworkElement(null, error)); + dispatch(new AddOrUpdateMountedNetworkElement(null, error)); }); }; -- cgit 1.2.3-korg