jamespot-front-business 1.1.31 → 1.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createEntityAdapter, createSlice, createAsyncThunk, combineReducers } from '@reduxjs/toolkit';
2
2
  import { combineReducers as combineReducers$1 } from 'redux';
3
3
  import jamespot, { jEnsure, formatImgUrl, UserLevel, StudioApplicationStatus } from 'jamespot-user-api';
4
+ import { v4 } from 'uuid';
4
5
 
5
6
  const adapter$1 = createEntityAdapter({
6
7
  selectId: (app) => app.name,
@@ -1970,43 +1971,83 @@ function serverAppsToStudioApps(serverApps) {
1970
1971
  return studioApps;
1971
1972
  }
1972
1973
 
1974
+ function cloneStudioAppFromExistingApp(existingApp, author) {
1975
+ const newApp = existingApp.inWorkVersion
1976
+ ? JSON.parse(JSON.stringify(existingApp.inWorkVersion))
1977
+ : JSON.parse(JSON.stringify(existingApp));
1978
+ const newAppId = v4();
1979
+ const newAppName = `${existingApp.manifest.appName} Copie`;
1980
+ newApp.idApp = newAppId;
1981
+ newApp.status = APP_STATUS_TYPE.DRAFT;
1982
+ newApp.manifest = Object.assign(Object.assign({}, newApp.manifest), { appName: newAppName, appShortName: newAppName, author: author || '', dateCreation: new Date().toISOString(), version: 0.1, articlesCount: 0 });
1983
+ return [newApp, newAppId];
1984
+ }
1985
+
1973
1986
  const initialState = {
1974
1987
  studioAppsList: [],
1975
1988
  loadingStudioAppsList: 'idle',
1976
1989
  deleteStudioAppStatus: 'idle',
1990
+ suspendStudioAppStatus: 'idle',
1991
+ restartStudioAppStatus: 'idle',
1992
+ cloneStudioAppStatus: 'idle',
1977
1993
  };
1978
- const fetchStudioAppsList = createAsyncThunk('studio/appsList', (_, { extra }) => __awaiter(void 0, void 0, void 0, function* () {
1994
+ const fetchStudioAppsList = createAsyncThunk('studio/appsList', (_, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
1979
1995
  const jApi = extra.jApi;
1980
- return yield new Promise((resolve, rejectWithValue) => {
1981
- jApi.application
1982
- .list()
1983
- .then((res) => __awaiter(void 0, void 0, void 0, function* () {
1984
- const coreApps = yield Promise.all(res.result.map((app) => __awaiter(void 0, void 0, void 0, function* () {
1985
- const coreApp = (yield jApi.application.get(app.idApp, app.status)).result;
1986
- const articlesCount = (yield jApi.article.count(app.idApp)).result;
1987
- return Object.assign(Object.assign({}, coreApp), { articlesCount });
1988
- })));
1989
- resolve(coreApps);
1990
- }))
1991
- .catch((e) => {
1992
- var _a, _b;
1993
- rejectWithValue({ error: (_a = e.error) !== null && _a !== void 0 ? _a : 1, errorMsg: (_b = e.errorMsg) !== null && _b !== void 0 ? _b : 'Error retrieving applications' });
1994
- });
1995
- });
1996
+ try {
1997
+ const { result } = yield jApi.application.list();
1998
+ return yield Promise.all(result.map((app) => __awaiter(void 0, void 0, void 0, function* () {
1999
+ const coreApp = (yield jApi.application.get(app.idApp, app.status)).result;
2000
+ const articlesCount = (yield jApi.article.count(app.idApp)).result;
2001
+ return Object.assign(Object.assign({}, coreApp), { articlesCount });
2002
+ })));
2003
+ }
2004
+ catch (_) {
2005
+ return rejectWithValue({ error: 1, errorMsg: 'Error retrieving applications' });
2006
+ }
1996
2007
  }));
1997
- const deleteStudioApp = createAsyncThunk('studio/deleteApp', ({ idApp, status }, { extra }) => __awaiter(void 0, void 0, void 0, function* () {
2008
+ const deleteStudioApp = createAsyncThunk('studio/deleteApp', ({ idApp, status }, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
1998
2009
  const jApi = extra.jApi;
1999
- return yield new Promise((resolve, rejectWithValue) => {
2000
- jApi.application
2001
- .delete(idApp, status)
2002
- .then((res) => {
2003
- resolve(res);
2004
- })
2005
- .catch((e) => {
2006
- var _a, _b;
2007
- rejectWithValue({ error: (_a = e.error) !== null && _a !== void 0 ? _a : 1, errorMsg: (_b = e.errorMsg) !== null && _b !== void 0 ? _b : 'Error deleting application' });
2008
- });
2009
- });
2010
+ try {
2011
+ return yield jApi.application.delete(idApp, status);
2012
+ }
2013
+ catch (_) {
2014
+ return rejectWithValue({ error: 1, errorMsg: 'Error deleting application' });
2015
+ }
2016
+ }));
2017
+ const suspendStudioApp = createAsyncThunk('studio/suspendStudioApp', ({ idApp }, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
2018
+ const jApi = extra.jApi;
2019
+ try {
2020
+ yield jApi.application.suspend(idApp);
2021
+ }
2022
+ catch (_) {
2023
+ throw rejectWithValue({ error: 1, errorMsg: 'Error suspending application' });
2024
+ }
2025
+ }));
2026
+ const restartStudioApp = createAsyncThunk('studio/restartStudioApp', ({ idApp }, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
2027
+ const jApi = extra.jApi;
2028
+ try {
2029
+ yield jApi.application.restart(idApp);
2030
+ }
2031
+ catch (_) {
2032
+ throw rejectWithValue({ error: 1, errorMsg: 'Error restarting application' });
2033
+ }
2034
+ }));
2035
+ const cloneStudioApp = createAsyncThunk('studio/cloneStudioApp', ({ idApp }, { extra, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
2036
+ var _a;
2037
+ const jApi = extra.jApi;
2038
+ const existingStudioApp = getState().studio.studioAppsList.studioAppsList.find((app) => app.idApp === idApp);
2039
+ if (!existingStudioApp)
2040
+ return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
2041
+ const currentUser = (_a = getState().userCurrent) === null || _a === void 0 ? void 0 : _a.uri;
2042
+ const [clonedStudioApp, newAppId] = cloneStudioAppFromExistingApp(existingStudioApp, currentUser);
2043
+ const clonedStudioAppReady = JSON.stringify(clonedStudioApp);
2044
+ try {
2045
+ yield jApi.application.save(newAppId, clonedStudioAppReady, 'saved');
2046
+ return clonedStudioApp;
2047
+ }
2048
+ catch (_) {
2049
+ return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
2050
+ }
2010
2051
  }));
2011
2052
  const StudioAppsListSlice = createSlice({
2012
2053
  name: 'studioAppsList',
@@ -2040,11 +2081,77 @@ const StudioAppsListSlice = createSlice({
2040
2081
  if (state.deleteStudioAppStatus === 'pending') {
2041
2082
  state.deleteStudioAppStatus = 'idle';
2042
2083
  }
2043
- state.studioAppsList = state.studioAppsList.filter((app) => app.idApp !== action.meta.arg.idApp && app.status !== action.meta.arg.status);
2084
+ state.studioAppsList = state.studioAppsList.reduce((acc, app) => {
2085
+ const { idApp, status } = action.meta.arg;
2086
+ if (app.idApp === idApp && app.status === status)
2087
+ return acc;
2088
+ if (app.inWorkVersion &&
2089
+ app.inWorkVersion.idApp === idApp &&
2090
+ app.inWorkVersion.status === status) {
2091
+ delete app.inWorkVersion;
2092
+ }
2093
+ return [...acc, app];
2094
+ }, []);
2044
2095
  })
2045
2096
  .addCase(deleteStudioApp.rejected, (state) => {
2046
2097
  if (state.deleteStudioAppStatus === 'pending')
2047
2098
  state.deleteStudioAppStatus = 'idle';
2099
+ })
2100
+ .addCase(suspendStudioApp.pending, (state) => {
2101
+ if (state.suspendStudioAppStatus === 'idle')
2102
+ state.suspendStudioAppStatus = 'pending';
2103
+ })
2104
+ .addCase(suspendStudioApp.fulfilled, (state, action) => {
2105
+ if (state.suspendStudioAppStatus === 'pending') {
2106
+ state.suspendStudioAppStatus = 'idle';
2107
+ }
2108
+ state.studioAppsList = state.studioAppsList.map((app) => {
2109
+ const { idApp } = action.meta.arg;
2110
+ if (app.idApp === idApp) {
2111
+ app.status = APP_STATUS_TYPE.SUSPENDED;
2112
+ return app;
2113
+ }
2114
+ return app;
2115
+ });
2116
+ })
2117
+ .addCase(suspendStudioApp.rejected, (state) => {
2118
+ if (state.suspendStudioAppStatus === 'pending')
2119
+ state.suspendStudioAppStatus = 'idle';
2120
+ })
2121
+ .addCase(restartStudioApp.pending, (state) => {
2122
+ if (state.restartStudioAppStatus === 'idle')
2123
+ state.restartStudioAppStatus = 'pending';
2124
+ })
2125
+ .addCase(restartStudioApp.fulfilled, (state, action) => {
2126
+ if (state.restartStudioAppStatus === 'pending') {
2127
+ state.restartStudioAppStatus = 'idle';
2128
+ }
2129
+ state.studioAppsList = state.studioAppsList.map((app) => {
2130
+ const { idApp } = action.meta.arg;
2131
+ if (app.idApp === idApp) {
2132
+ app.status = APP_STATUS_TYPE.INSTALLED;
2133
+ return app;
2134
+ }
2135
+ return app;
2136
+ });
2137
+ })
2138
+ .addCase(restartStudioApp.rejected, (state) => {
2139
+ if (state.restartStudioAppStatus === 'pending')
2140
+ state.restartStudioAppStatus = 'idle';
2141
+ })
2142
+ .addCase(cloneStudioApp.pending, (state) => {
2143
+ if (state.cloneStudioAppStatus === 'idle')
2144
+ state.cloneStudioAppStatus = 'pending';
2145
+ })
2146
+ .addCase(cloneStudioApp.fulfilled, (state, action) => {
2147
+ if (state.cloneStudioAppStatus === 'pending') {
2148
+ state.cloneStudioAppStatus = 'idle';
2149
+ }
2150
+ state.studioAppsList = [...state.studioAppsList, action.payload];
2151
+ })
2152
+ .addCase(cloneStudioApp.rejected, (state) => {
2153
+ if (state.cloneStudioAppStatus === 'pending')
2154
+ state.cloneStudioAppStatus = 'idle';
2048
2155
  });
2049
2156
  },
2050
2157
  });
@@ -2062,7 +2169,10 @@ const studioSlice = {
2062
2169
  const studio = {
2063
2170
  slice: studioSlice,
2064
2171
  actions: Object.assign(Object.assign({}, StudioAppsListSlice.actions), { fetchStudioAppsList,
2065
- deleteStudioApp }),
2172
+ deleteStudioApp,
2173
+ suspendStudioApp,
2174
+ restartStudioApp,
2175
+ cloneStudioApp }),
2066
2176
  selectors: {
2067
2177
  selectStudioAppsList,
2068
2178
  },