jamespot-front-business 1.1.30 → 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/cjs.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var toolkit = require('@reduxjs/toolkit');
6
6
  var redux = require('redux');
7
7
  var jamespot = require('jamespot-user-api');
8
+ var uuid = require('uuid');
8
9
 
9
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
11
 
@@ -1927,20 +1928,7 @@ function InstalledAppStudioAdapter(serverApp, serverApps) {
1927
1928
  const studioApp = {
1928
1929
  idApp: serverApp.idApp,
1929
1930
  status: _formatStatus(serverApp),
1930
- manifest: {
1931
- appShortName: serverApp.name,
1932
- appName: serverApp.label,
1933
- description: serverApp.description,
1934
- author: serverApp.author,
1935
- cssColor: appTypeServer.cssColor,
1936
- cssClass: { label: appTypeServer.cssClass, value: appTypeServer.cssClass },
1937
- version: version,
1938
- dateCreation: dateCreation,
1939
- checkAccess: serverApp.checkAccess,
1940
- attrExposed: serverApp.attrExposed,
1941
- viewSolr: serverApp.view,
1942
- typeLabel: appTypeServer.typeLabel,
1943
- },
1931
+ manifest: Object.assign({ appShortName: serverApp.name, appName: serverApp.label, description: serverApp.description, author: serverApp.author, cssColor: appTypeServer.cssColor, cssClass: { label: appTypeServer.cssClass, value: appTypeServer.cssClass }, version: version, dateCreation: dateCreation, checkAccess: serverApp.checkAccess, attrExposed: serverApp.attrExposed, viewSolr: serverApp.view, typeLabel: appTypeServer.typeLabel }, (serverApp.articlesCount && { articlesCount: serverApp.articlesCount })),
1944
1932
  };
1945
1933
  const inWorkAppVersion = _findAssociatedDraft(serverApp.idApp, serverApps);
1946
1934
  if (!inWorkAppVersion)
@@ -1991,29 +1979,92 @@ function serverAppsToStudioApps(serverApps) {
1991
1979
  return studioApps;
1992
1980
  }
1993
1981
 
1982
+ function cloneStudioAppFromExistingApp(existingApp, author) {
1983
+ const newApp = existingApp.inWorkVersion
1984
+ ? JSON.parse(JSON.stringify(existingApp.inWorkVersion))
1985
+ : JSON.parse(JSON.stringify(existingApp));
1986
+ const newAppId = uuid.v4();
1987
+ const newAppName = `${existingApp.manifest.appName} Copie`;
1988
+ newApp.idApp = newAppId;
1989
+ newApp.status = APP_STATUS_TYPE.DRAFT;
1990
+ newApp.manifest = Object.assign(Object.assign({}, newApp.manifest), { appName: newAppName, appShortName: newAppName, author: author || '', dateCreation: new Date().toISOString(), version: 0.1, articlesCount: 0 });
1991
+ return [newApp, newAppId];
1992
+ }
1993
+
1994
1994
  const initialState = {
1995
1995
  studioAppsList: [],
1996
1996
  loadingStudioAppsList: 'idle',
1997
+ deleteStudioAppStatus: 'idle',
1998
+ suspendStudioAppStatus: 'idle',
1999
+ restartStudioAppStatus: 'idle',
2000
+ cloneStudioAppStatus: 'idle',
1997
2001
  };
1998
- const fetchStudioAppsList = toolkit.createAsyncThunk('studio/appsList', (_, { extra }) => __awaiter(void 0, void 0, void 0, function* () {
2002
+ const fetchStudioAppsList = toolkit.createAsyncThunk('studio/appsList', (_, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
1999
2003
  const jApi = extra.jApi;
2000
- return yield new Promise((resolve, rejectWithValue) => {
2001
- jApi.application
2002
- .list()
2003
- .then((res) => __awaiter(void 0, void 0, void 0, function* () {
2004
- const coreApps = yield Promise.all(res.result.map((app) => __awaiter(void 0, void 0, void 0, function* () { return (yield jApi.application.get(app.idApp, app.status)).result; })));
2005
- resolve(coreApps);
2006
- }))
2007
- .catch((e) => {
2008
- var _a, _b;
2009
- rejectWithValue({ error: (_a = e.error) !== null && _a !== void 0 ? _a : 1, errorMsg: (_b = e.errorMsg) !== null && _b !== void 0 ? _b : 'Error retrieving applications' });
2010
- });
2011
- });
2004
+ try {
2005
+ const { result } = yield jApi.application.list();
2006
+ return yield Promise.all(result.map((app) => __awaiter(void 0, void 0, void 0, function* () {
2007
+ const coreApp = (yield jApi.application.get(app.idApp, app.status)).result;
2008
+ const articlesCount = (yield jApi.article.count(app.idApp)).result;
2009
+ return Object.assign(Object.assign({}, coreApp), { articlesCount });
2010
+ })));
2011
+ }
2012
+ catch (_) {
2013
+ return rejectWithValue({ error: 1, errorMsg: 'Error retrieving applications' });
2014
+ }
2015
+ }));
2016
+ const deleteStudioApp = toolkit.createAsyncThunk('studio/deleteApp', ({ idApp, status }, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
2017
+ const jApi = extra.jApi;
2018
+ try {
2019
+ return yield jApi.application.delete(idApp, status);
2020
+ }
2021
+ catch (_) {
2022
+ return rejectWithValue({ error: 1, errorMsg: 'Error deleting application' });
2023
+ }
2024
+ }));
2025
+ const suspendStudioApp = toolkit.createAsyncThunk('studio/suspendStudioApp', ({ idApp }, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
2026
+ const jApi = extra.jApi;
2027
+ try {
2028
+ yield jApi.application.suspend(idApp);
2029
+ }
2030
+ catch (_) {
2031
+ throw rejectWithValue({ error: 1, errorMsg: 'Error suspending application' });
2032
+ }
2033
+ }));
2034
+ const restartStudioApp = toolkit.createAsyncThunk('studio/restartStudioApp', ({ idApp }, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
2035
+ const jApi = extra.jApi;
2036
+ try {
2037
+ yield jApi.application.restart(idApp);
2038
+ }
2039
+ catch (_) {
2040
+ throw rejectWithValue({ error: 1, errorMsg: 'Error restarting application' });
2041
+ }
2042
+ }));
2043
+ const cloneStudioApp = toolkit.createAsyncThunk('studio/cloneStudioApp', ({ idApp }, { extra, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
2044
+ var _a;
2045
+ const jApi = extra.jApi;
2046
+ const existingStudioApp = getState().studio.studioAppsList.studioAppsList.find((app) => app.idApp === idApp);
2047
+ if (!existingStudioApp)
2048
+ return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
2049
+ const currentUser = (_a = getState().userCurrent) === null || _a === void 0 ? void 0 : _a.uri;
2050
+ const [clonedStudioApp, newAppId] = cloneStudioAppFromExistingApp(existingStudioApp, currentUser);
2051
+ const clonedStudioAppReady = JSON.stringify(clonedStudioApp);
2052
+ try {
2053
+ yield jApi.application.save(newAppId, clonedStudioAppReady, 'saved');
2054
+ return clonedStudioApp;
2055
+ }
2056
+ catch (_) {
2057
+ return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
2058
+ }
2012
2059
  }));
2013
2060
  const StudioAppsListSlice = toolkit.createSlice({
2014
2061
  name: 'studioAppsList',
2015
2062
  initialState,
2016
- reducers: {},
2063
+ reducers: {
2064
+ setAppsList: (state, action) => {
2065
+ state.studioAppsList = action.payload;
2066
+ },
2067
+ },
2017
2068
  extraReducers: (builder) => {
2018
2069
  builder
2019
2070
  .addCase(fetchStudioAppsList.pending, (state) => {
@@ -2021,13 +2072,94 @@ const StudioAppsListSlice = toolkit.createSlice({
2021
2072
  state.loadingStudioAppsList = 'pending';
2022
2073
  })
2023
2074
  .addCase(fetchStudioAppsList.fulfilled, (state, action) => {
2024
- if (state.loadingStudioAppsList === 'pending')
2075
+ if (state.loadingStudioAppsList === 'pending') {
2025
2076
  state.loadingStudioAppsList = 'idle';
2077
+ }
2026
2078
  state.studioAppsList = serverAppsToStudioApps(action.payload);
2027
2079
  })
2028
2080
  .addCase(fetchStudioAppsList.rejected, (state) => {
2029
2081
  if (state.loadingStudioAppsList === 'pending')
2030
2082
  state.loadingStudioAppsList = 'idle';
2083
+ })
2084
+ .addCase(deleteStudioApp.pending, (state) => {
2085
+ if (state.deleteStudioAppStatus === 'idle')
2086
+ state.deleteStudioAppStatus = 'pending';
2087
+ })
2088
+ .addCase(deleteStudioApp.fulfilled, (state, action) => {
2089
+ if (state.deleteStudioAppStatus === 'pending') {
2090
+ state.deleteStudioAppStatus = 'idle';
2091
+ }
2092
+ state.studioAppsList = state.studioAppsList.reduce((acc, app) => {
2093
+ const { idApp, status } = action.meta.arg;
2094
+ if (app.idApp === idApp && app.status === status)
2095
+ return acc;
2096
+ if (app.inWorkVersion &&
2097
+ app.inWorkVersion.idApp === idApp &&
2098
+ app.inWorkVersion.status === status) {
2099
+ delete app.inWorkVersion;
2100
+ }
2101
+ return [...acc, app];
2102
+ }, []);
2103
+ })
2104
+ .addCase(deleteStudioApp.rejected, (state) => {
2105
+ if (state.deleteStudioAppStatus === 'pending')
2106
+ state.deleteStudioAppStatus = 'idle';
2107
+ })
2108
+ .addCase(suspendStudioApp.pending, (state) => {
2109
+ if (state.suspendStudioAppStatus === 'idle')
2110
+ state.suspendStudioAppStatus = 'pending';
2111
+ })
2112
+ .addCase(suspendStudioApp.fulfilled, (state, action) => {
2113
+ if (state.suspendStudioAppStatus === 'pending') {
2114
+ state.suspendStudioAppStatus = 'idle';
2115
+ }
2116
+ state.studioAppsList = state.studioAppsList.map((app) => {
2117
+ const { idApp } = action.meta.arg;
2118
+ if (app.idApp === idApp) {
2119
+ app.status = APP_STATUS_TYPE.SUSPENDED;
2120
+ return app;
2121
+ }
2122
+ return app;
2123
+ });
2124
+ })
2125
+ .addCase(suspendStudioApp.rejected, (state) => {
2126
+ if (state.suspendStudioAppStatus === 'pending')
2127
+ state.suspendStudioAppStatus = 'idle';
2128
+ })
2129
+ .addCase(restartStudioApp.pending, (state) => {
2130
+ if (state.restartStudioAppStatus === 'idle')
2131
+ state.restartStudioAppStatus = 'pending';
2132
+ })
2133
+ .addCase(restartStudioApp.fulfilled, (state, action) => {
2134
+ if (state.restartStudioAppStatus === 'pending') {
2135
+ state.restartStudioAppStatus = 'idle';
2136
+ }
2137
+ state.studioAppsList = state.studioAppsList.map((app) => {
2138
+ const { idApp } = action.meta.arg;
2139
+ if (app.idApp === idApp) {
2140
+ app.status = APP_STATUS_TYPE.INSTALLED;
2141
+ return app;
2142
+ }
2143
+ return app;
2144
+ });
2145
+ })
2146
+ .addCase(restartStudioApp.rejected, (state) => {
2147
+ if (state.restartStudioAppStatus === 'pending')
2148
+ state.restartStudioAppStatus = 'idle';
2149
+ })
2150
+ .addCase(cloneStudioApp.pending, (state) => {
2151
+ if (state.cloneStudioAppStatus === 'idle')
2152
+ state.cloneStudioAppStatus = 'pending';
2153
+ })
2154
+ .addCase(cloneStudioApp.fulfilled, (state, action) => {
2155
+ if (state.cloneStudioAppStatus === 'pending') {
2156
+ state.cloneStudioAppStatus = 'idle';
2157
+ }
2158
+ state.studioAppsList = [...state.studioAppsList, action.payload];
2159
+ })
2160
+ .addCase(cloneStudioApp.rejected, (state) => {
2161
+ if (state.cloneStudioAppStatus === 'pending')
2162
+ state.cloneStudioAppStatus = 'idle';
2031
2163
  });
2032
2164
  },
2033
2165
  });
@@ -2044,9 +2176,11 @@ const studioSlice = {
2044
2176
  };
2045
2177
  const studio = {
2046
2178
  slice: studioSlice,
2047
- actions: {
2048
- fetchStudioAppsList,
2049
- },
2179
+ actions: Object.assign(Object.assign({}, StudioAppsListSlice.actions), { fetchStudioAppsList,
2180
+ deleteStudioApp,
2181
+ suspendStudioApp,
2182
+ restartStudioApp,
2183
+ cloneStudioApp }),
2050
2184
  selectors: {
2051
2185
  selectStudioAppsList,
2052
2186
  },