Skip to content

Commit

Permalink
Regression: Apps provider not handling apps lists correctly (#28264)
Browse files Browse the repository at this point in the history
  • Loading branch information
rique223 authored Mar 4, 2023
1 parent 5e6015e commit 0e969e9
Showing 1 changed file with 99 additions and 49 deletions.
148 changes: 99 additions & 49 deletions apps/meteor/client/views/marketplace/AppsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ const AppsProvider: FC = ({ children }) => {
handleAPIError(error);
}

const [, installedApps, privateApps] = getCurrentData();

if (marketplaceApp !== undefined) {
const { status, version, licenseValidation } = installedApp;
const record = {
Expand All @@ -346,15 +348,21 @@ const AppsProvider: FC = ({ children }) => {
marketplaceVersion: marketplaceApp.app.version,
};

const [, installedApps] = getCurrentData();

dispatchMarketplaceApps({
type: 'update',
app: record,
reload: fetch,
});

if (installedApps.value) {
if (installedApps.value.apps.some((app) => app.id === appId)) {
dispatchInstalledApps({
type: 'update',
app: record,
reload: fetch,
});
return;
}
dispatchInstalledApps({
type: 'success',
apps: [...installedApps.value.apps, record],
Expand All @@ -372,86 +380,128 @@ const AppsProvider: FC = ({ children }) => {
return;
}

if (privateApp) {
dispatchPrivateApps({ type: 'update', app: privateApp, reload: fetch });
if (privateApp !== undefined) {
const { status, version } = privateApp;

const record = {
...privateApp,
success: true,
installed: true,
status,
version,
};

if (privateApps.value) {
if (privateApps.value.apps.some((app) => app.id === appId)) {
dispatchPrivateApps({
type: 'update',
app: record,
reload: fetch,
});
return;
}
dispatchPrivateApps({
type: 'success',
apps: [...privateApps.value.apps, record],
reload: fetch,
});
return;
}

dispatchPrivateApps({ type: 'success', apps: [record], reload: fetch });
return;
}

// TODO: Reevaluate the necessity of this dispatch
dispatchInstalledApps({ type: 'update', app: installedApp, reload: fetch });
};
const listeners = {
APP_ADDED: handleAppAddedOrUpdated,
APP_UPDATED: handleAppAddedOrUpdated,
APP_REMOVED: (appId: string): void => {
const [updatedData] = getCurrentData();
const app = updatedData.value?.apps.find(({ id }: { id: string }) => id === appId);

dispatchInstalledApps({
type: 'delete',
appId,
reload: fetch,
});
const updatedData = getCurrentData();

if (!app) {
return;
}
// TODO: This forEach is not ideal, it will be improved in the future during the refactor of this provider;
updatedData.forEach((appsList) => {
const app = appsList.value?.apps.find(({ id }: { id: string }) => id === appId);

if (app.private) {
dispatchPrivateApps({
dispatchInstalledApps({
type: 'delete',
appId,
reload: fetch,
});
}

dispatchMarketplaceApps({
type: 'update',
reload: fetch,
app: {
...app,
version: app?.marketplaceVersion,
installed: false,
marketplaceVersion: app?.marketplaceVersion,
},
if (!app) {
return;
}

if (app.private) {
dispatchPrivateApps({
type: 'delete',
appId,
reload: fetch,
});
}

dispatchMarketplaceApps({
type: 'update',
reload: fetch,
app: {
...app,
version: app?.marketplaceVersion,
installed: false,
marketplaceVersion: app?.marketplaceVersion,
},
});
});

invalidateAppsCountQuery();
},
APP_STATUS_CHANGE: ({ appId, status }: { appId: string; status: AppStatus }): void => {
const [updatedData] = getCurrentData();
const app = updatedData.value?.apps.find(({ id }: { id: string }) => id === appId);
if (!app) {
const updatedData = getCurrentData();

if (!Array.isArray(updatedData)) {
return;
}

app.status = status;
// TODO: This forEach is not ideal, it will be improved in the future during the refactor of this provider;
updatedData.forEach((appsList) => {
const app = appsList.value?.apps.find(({ id }: { id: string }) => id === appId);

dispatchInstalledApps({
type: 'update',
app: {
...app,
status,
},
reload: fetch,
});
if (!app) {
return;
}

if (app.private) {
dispatchPrivateApps({
app.status = status;

dispatchInstalledApps({
type: 'update',
app: {
...app,
status,
},
reload: fetch,
});
}

dispatchMarketplaceApps({
type: 'update',
app: {
...app,
status,
},
reload: fetch,
if (app.private) {
dispatchPrivateApps({
type: 'update',
app: {
...app,
status,
},
reload: fetch,
});
}

dispatchMarketplaceApps({
type: 'update',
app: {
...app,
status,
},
reload: fetch,
});
});

invalidateAppsCountQuery();
Expand Down

0 comments on commit 0e969e9

Please sign in to comment.