Skip to content

feat(client): discoverable apps notification fixed #1275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 24, 2025
160 changes: 77 additions & 83 deletions packages/client/src/pages/app/AppDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,105 +239,99 @@ export const AppDetailPage = () => {
}

const fetchAppData = async (id: string) => {
Promise.allSettled([
await getPermission();
const permission = getValues('permission');
const promises: Promise<any>[] = [
fetchAppInfo(
monolithStore,
id,
configStore.store.config.projectMetaKeys.map((a) => a.metakey),
),
fetchMainUses(monolithStore, id),
fetchDependencies(monolithStore, id),
]).then((results) =>
results.forEach((res, idx) => {
if (res.status === 'rejected') {
emitMessage(true, res.reason);
} else {
if (idx === 0) {
if (res.value.type === 'error') {
emitMessage(true, res.value.output);
} else {
setValue('appInfo', res.value.output);
const output = res.value.output;

const projectMetaKeys =
configStore.store.config.projectMetaKeys;
// Keep only relevant project keys defined for app details
const parsedMeta = projectMetaKeys
.map((k) => k.metakey)
.reduce((prev, curr) => {
// tag, domain, and etc either come in as a string or a string[], format it to correct type
const found = projectMetaKeys.find(
(obj) => obj.metakey === curr,
);

if (curr === 'tag') {
if (typeof output[curr] === 'string') {
prev[curr] = [output[curr]];
} else {
prev[curr] = output[curr];
}
} else if (
found.display_options ===
'single-typeahead' ||
found.display_options ===
'select-box' ||
found.display_options ===
'multi-typeahead'
) {
if (typeof output[curr] === 'string') {
prev[curr] = [output[curr]];
} else {
prev[curr] = output[curr];
}
];
if (permission !== 'discoverable') {
promises.push(fetchDependencies(monolithStore, id));
}
const results = await Promise.allSettled(promises);
results.forEach((res, idx) => {
if (res.status === 'rejected') {
emitMessage(true, res.reason);
} else {
if (idx === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the array always the same way? Its never structured differently? One thing that worries me about this if else statement is that if the structure ever changes it would break.

Is there another check that we can make that is a bit more stringent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AAfghahi the indexes are based on the array insertion in the promises. It will always remain the same till the array is changed

if (res.value.type === 'error') {
emitMessage(true, res.value.output);
} else {
setValue('appInfo', res.value.output);
const output = res.value.output;

const projectMetaKeys =
configStore.store.config.projectMetaKeys;
// Keep only relevant project keys defined for app details
const parsedMeta = projectMetaKeys
.map((k) => k.metakey)
.reduce((prev, curr) => {
// tag, domain, and etc either come in as a string or a string[], format it to correct type
const found = projectMetaKeys.find(
(obj) => obj.metakey === curr,
);

if (curr === 'tag') {
if (typeof output[curr] === 'string') {
prev[curr] = [output[curr]];
} else {
prev[curr] = output[curr];
}
} else if (
found.display_options ===
'single-typeahead' ||
found.display_options === 'select-box' ||
found.display_options === 'multi-typeahead'
) {
if (typeof output[curr] === 'string') {
prev[curr] = [output[curr]];
} else {
prev[curr] = output[curr];
}
} else {
prev[curr] = output[curr];
}

return prev;
}, {}) as AppDetailsFormTypes['detailsForm'];
setValue('detailsForm', parsedMeta);
setValue('tag', parsedMeta.tag);
setValue('markdown', parsedMeta.markdown);
setValue(
'detailsForm.markdown',
parsedMeta.markdown,
);
return prev;
}, {}) as AppDetailsFormTypes['detailsForm'];
setValue('detailsForm', parsedMeta);
setValue('tag', parsedMeta.tag);
setValue('markdown', parsedMeta.markdown);
setValue('detailsForm.markdown', parsedMeta.markdown);
setValues((prev) => ({
...prev,
markdown: parsedMeta.markdown || '',
}));
setValues((prev) => ({ ...prev, ...parsedMeta }));
}
} else if (idx === 1) {
if (res.value.type === 'error') {
emitMessage(true, res.value.output);
} else {
if (res.value.output !== null) {
setValue('markdown', res.value.output);
setValue('detailsForm.markdown', res.value.output);
setValues((prev) => ({
...prev,
markdown: parsedMeta.markdown || '',
markdown: res.value.output || '',
}));
setValues((prev) => ({ ...prev, ...parsedMeta }));
}
} else if (idx === 1) {
if (res.value.type === 'error') {
emitMessage(true, res.value.output);
} else {
if (res.value.output !== null) {
setValue('markdown', res.value.output);
setValue(
'detailsForm.markdown',
res.value.output,
);
setValues((prev) => ({
...prev,
markdown: res.value.output || '',
}));
}
}
} else if (idx === 2) {
if (res.value.type === 'error') {
emitMessage(true, res.value.output);
} else {
const modelled = modelDependencies(
res.value.output,
);
setValue('dependencies', modelled);
setValue('selectedDependencies', modelled);
}
}
} else if (idx === 2) {
if (res.value.type === 'error') {
emitMessage(true, res.value.output);
} else {
const modelled = modelDependencies(res.value.output);
setValue('dependencies', modelled);
setValue('selectedDependencies', modelled);
}
}
}),
);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add error checking to this as well? Does not look like we do anything if the pixel call errors out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Individual calls are tracked within the indexes and if the overall call fails, that is taken as rejected.

};

const fetchSimilarApps = () => {
Expand Down