Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions apps/app/src/react-app/domains/settings/state/extensions-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ export function createExtensionsStore(options: {
let refreshCloudOrgSkillsInFlight = false;
let refreshCloudOrgSkillHubsInFlight = false;
let refreshCloudOrgMarketplacesInFlight = false;
let refreshCloudOrgSkillsInFlightKey = "";
let refreshCloudOrgSkillHubsInFlightKey = "";
let refreshCloudOrgMarketplacesInFlightKey = "";
let refreshSkillsAborted = false;
let refreshPluginsAborted = false;
let refreshHubSkillsAborted = false;
Expand Down Expand Up @@ -884,6 +887,11 @@ export function createExtensionsStore(options: {
cloudOrgMarketplacesLoadKey = "";
};

const getCurrentCloudOrgLoadKey = () => {
const orgId = readDenSettings().activeOrgId?.trim() ?? "";
return `${getWorkspaceContextKey()}::${orgId}`;
};

const touch = () => {
refreshSnapshot();
emitChange();
Expand Down Expand Up @@ -1023,9 +1031,10 @@ export function createExtensionsStore(options: {
await refreshImportedCloudSkills();
return;
}
if (refreshCloudOrgSkillsInFlight) return;
if (refreshCloudOrgSkillsInFlight && refreshCloudOrgSkillsInFlightKey === loadKey) return;

refreshCloudOrgSkillsInFlight = true;
refreshCloudOrgSkillsInFlightKey = loadKey;
refreshCloudOrgSkillsAborted = false;

try {
Expand All @@ -1046,7 +1055,7 @@ export function createExtensionsStore(options: {

const client = createDenClient({ baseUrl: settings.baseUrl, apiBaseUrl: settings.apiBaseUrl, token });
const catalog = await fetchDenOrgSkillsCatalog(client, orgId);
if (refreshCloudOrgSkillsAborted) return;
if (refreshCloudOrgSkillsAborted || getCurrentCloudOrgLoadKey() !== loadKey) return;
mutateState((current) => ({
...current,
cloudOrgSkills: catalog,
Expand All @@ -1057,15 +1066,18 @@ export function createExtensionsStore(options: {
cloudOrgSkillsLoadKey = loadKey;
await refreshImportedCloudSkills();
} catch (error) {
if (refreshCloudOrgSkillsAborted) return;
if (refreshCloudOrgSkillsAborted || getCurrentCloudOrgLoadKey() !== loadKey) return;
mutateState((current) => ({
...current,
cloudOrgSkills: [],
cloudOrgSkillsStatus:
error instanceof Error ? error.message : t("skills.cloud_org_load_failed"),
}));
} finally {
refreshCloudOrgSkillsInFlight = false;
if (refreshCloudOrgSkillsInFlightKey === loadKey) {
refreshCloudOrgSkillsInFlight = false;
refreshCloudOrgSkillsInFlightKey = "";
}
}
}

Expand All @@ -1084,9 +1096,10 @@ export function createExtensionsStore(options: {
await refreshImportedCloudSkillHubs();
return;
}
if (refreshCloudOrgSkillHubsInFlight) return;
if (refreshCloudOrgSkillHubsInFlight && refreshCloudOrgSkillHubsInFlightKey === loadKey) return;

refreshCloudOrgSkillHubsInFlight = true;
refreshCloudOrgSkillHubsInFlightKey = loadKey;
refreshCloudOrgSkillHubsAborted = false;

try {
Expand All @@ -1106,7 +1119,7 @@ export function createExtensionsStore(options: {

const client = createDenClient({ baseUrl: settings.baseUrl, apiBaseUrl: settings.apiBaseUrl, token });
const hubs = await client.listOrgSkillHubs(orgId);
if (refreshCloudOrgSkillHubsAborted) return;
if (refreshCloudOrgSkillHubsAborted || getCurrentCloudOrgLoadKey() !== loadKey) return;
mutateState((current) => ({
...current,
cloudOrgSkillHubs: hubs,
Expand All @@ -1116,15 +1129,18 @@ export function createExtensionsStore(options: {
cloudOrgSkillHubsLoadKey = loadKey;
await refreshImportedCloudSkillHubs();
} catch (error) {
if (refreshCloudOrgSkillHubsAborted) return;
if (refreshCloudOrgSkillHubsAborted || getCurrentCloudOrgLoadKey() !== loadKey) return;
mutateState((current) => ({
...current,
cloudOrgSkillHubs: [],
cloudOrgSkillHubsStatus:
error instanceof Error ? error.message : "Failed to load organization skill hubs.",
}));
} finally {
refreshCloudOrgSkillHubsInFlight = false;
if (refreshCloudOrgSkillHubsInFlightKey === loadKey) {
refreshCloudOrgSkillHubsInFlight = false;
refreshCloudOrgSkillHubsInFlightKey = "";
}
}
}

Expand All @@ -1143,9 +1159,10 @@ export function createExtensionsStore(options: {
await refreshImportedCloudPlugins();
return;
}
if (refreshCloudOrgMarketplacesInFlight) return;
if (refreshCloudOrgMarketplacesInFlight && refreshCloudOrgMarketplacesInFlightKey === loadKey) return;

refreshCloudOrgMarketplacesInFlight = true;
refreshCloudOrgMarketplacesInFlightKey = loadKey;
refreshCloudOrgMarketplacesAborted = false;

try {
Expand All @@ -1168,7 +1185,7 @@ export function createExtensionsStore(options: {
const resolved = await Promise.all(
marketplaces.map((marketplace) => client.getOrgMarketplaceResolved(orgId, marketplace.id)),
);
if (refreshCloudOrgMarketplacesAborted) return;
if (refreshCloudOrgMarketplacesAborted || getCurrentCloudOrgLoadKey() !== loadKey) return;
mutateState((current) => ({
...current,
cloudOrgMarketplaces: resolved,
Expand All @@ -1178,15 +1195,18 @@ export function createExtensionsStore(options: {
cloudOrgMarketplacesLoadKey = loadKey;
await refreshImportedCloudPlugins();
} catch (error) {
if (refreshCloudOrgMarketplacesAborted) return;
if (refreshCloudOrgMarketplacesAborted || getCurrentCloudOrgLoadKey() !== loadKey) return;
mutateState((current) => ({
...current,
cloudOrgMarketplaces: [],
cloudOrgMarketplacesStatus:
error instanceof Error ? error.message : "Failed to load organization marketplaces.",
}));
} finally {
refreshCloudOrgMarketplacesInFlight = false;
if (refreshCloudOrgMarketplacesInFlightKey === loadKey) {
refreshCloudOrgMarketplacesInFlight = false;
refreshCloudOrgMarketplacesInFlightKey = "";
}
}
}

Expand Down
Loading