feat(appstore,workspace): add App Store upgrade progress tracking and interactive workspace processes
This commit is contained in:
+66
-9
@@ -60,6 +60,7 @@ export interface ISettingsState {
|
||||
export interface IAppStoreState {
|
||||
apps: interfaces.requests.IAppStoreApp[];
|
||||
upgradeableServices: interfaces.requests.IUpgradeableAppStoreService[];
|
||||
upgradeOperations: interfaces.requests.IAppStoreUpgradeOperation[];
|
||||
}
|
||||
|
||||
export interface IUiState {
|
||||
@@ -154,6 +155,7 @@ export const appStoreStatePart = await appState.getStatePart<IAppStoreState>(
|
||||
{
|
||||
apps: [],
|
||||
upgradeableServices: [],
|
||||
upgradeOperations: [],
|
||||
},
|
||||
'soft',
|
||||
);
|
||||
@@ -1101,6 +1103,19 @@ const upsertService = (
|
||||
return updatedServices;
|
||||
};
|
||||
|
||||
const upsertUpgradeOperation = (
|
||||
operations: interfaces.requests.IAppStoreUpgradeOperation[],
|
||||
operation: interfaces.requests.IAppStoreUpgradeOperation,
|
||||
): interfaces.requests.IAppStoreUpgradeOperation[] => {
|
||||
const existingIndex = operations.findIndex((item) => item.id === operation.id);
|
||||
const updatedOperations = existingIndex === -1
|
||||
? [operation, ...operations]
|
||||
: operations.map((item) => item.id === operation.id ? operation : item);
|
||||
return updatedOperations
|
||||
.sort((a, b) => b.startedAt - a.startedAt)
|
||||
.slice(0, 25);
|
||||
};
|
||||
|
||||
socketRouter.addTypedHandler(
|
||||
new plugins.domtools.plugins.typedrequest.TypedHandler<interfaces.requests.IReq_PushServiceUpdate>(
|
||||
'pushServiceUpdate',
|
||||
@@ -1137,6 +1152,33 @@ socketRouter.addTypedHandler(
|
||||
),
|
||||
);
|
||||
|
||||
socketRouter.addTypedHandler(
|
||||
new plugins.domtools.plugins.typedrequest.TypedHandler<interfaces.requests.IReq_PushAppStoreUpgradeProgress>(
|
||||
'pushAppStoreUpgradeProgress',
|
||||
async (dataArg) => {
|
||||
const state = appStoreStatePart.getState();
|
||||
appStoreStatePart.setState({
|
||||
...state,
|
||||
upgradeOperations: upsertUpgradeOperation(state.upgradeOperations, dataArg.operation),
|
||||
upgradeableServices: dataArg.operation.status === 'success'
|
||||
? state.upgradeableServices.filter((service) => service.serviceName !== dataArg.operation.serviceName)
|
||||
: state.upgradeableServices,
|
||||
});
|
||||
if (dataArg.operation.service) {
|
||||
const servicesState = servicesStatePart.getState();
|
||||
servicesStatePart.setState({
|
||||
...servicesState,
|
||||
services: upsertService(servicesState.services, dataArg.operation.service),
|
||||
currentService: servicesState.currentService?.name === dataArg.operation.service.name
|
||||
? dataArg.operation.service
|
||||
: servicesState.currentService,
|
||||
});
|
||||
}
|
||||
return {};
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Handle server-pushed platform service log entries
|
||||
socketRouter.addTypedHandler(
|
||||
new plugins.domtools.plugins.typedrequest.TypedHandler<interfaces.requests.IReq_PushPlatformServiceLog>(
|
||||
@@ -1258,6 +1300,22 @@ export const fetchUpgradeableAppStoreServicesAction = appStoreStatePart.createAc
|
||||
},
|
||||
);
|
||||
|
||||
export const fetchAppStoreUpgradeOperationsAction = appStoreStatePart.createAction(
|
||||
async (statePartArg) => {
|
||||
const context = getActionContext();
|
||||
try {
|
||||
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
||||
interfaces.requests.IReq_GetAppStoreUpgradeOperations
|
||||
>('/typedrequest', 'getAppStoreUpgradeOperations');
|
||||
const response = await typedRequest.fire({ identity: context.identity! });
|
||||
return { ...statePartArg.getState(), upgradeOperations: response.operations };
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch upgrade operations:', err);
|
||||
return statePartArg.getState();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export const upgradeAppStoreServiceAction = appStoreStatePart.createAction<{
|
||||
serviceName: string;
|
||||
targetVersion: string;
|
||||
@@ -1265,19 +1323,18 @@ export const upgradeAppStoreServiceAction = appStoreStatePart.createAction<{
|
||||
const context = getActionContext();
|
||||
try {
|
||||
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
||||
interfaces.requests.IReq_UpgradeAppStoreService
|
||||
>('/typedrequest', 'upgradeAppStoreService');
|
||||
await typedRequest.fire({
|
||||
interfaces.requests.IReq_StartAppStoreServiceUpgrade
|
||||
>('/typedrequest', 'startAppStoreServiceUpgrade');
|
||||
const response = await typedRequest.fire({
|
||||
identity: context.identity!,
|
||||
serviceName: dataArg.serviceName,
|
||||
targetVersion: dataArg.targetVersion,
|
||||
});
|
||||
// Re-fetch upgradeable services and services list
|
||||
const upgradeReq = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
||||
interfaces.requests.IReq_GetUpgradeableAppStoreServices
|
||||
>('/typedrequest', 'getUpgradeableAppStoreServices');
|
||||
const upgradeResp = await upgradeReq.fire({ identity: context.identity! });
|
||||
return { ...statePartArg.getState(), upgradeableServices: upgradeResp.services };
|
||||
const state = statePartArg.getState();
|
||||
return {
|
||||
...state,
|
||||
upgradeOperations: upsertUpgradeOperation(state.upgradeOperations, response.operation),
|
||||
};
|
||||
} catch (err) {
|
||||
console.error('Failed to upgrade service:', err);
|
||||
return statePartArg.getState();
|
||||
|
||||
Reference in New Issue
Block a user