aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts')
-rw-r--r--sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts47
1 files changed, 31 insertions, 16 deletions
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));
});
};