make sidebar notification failures more resilient

This commit is contained in:
miloschwartz
2026-06-24 15:55:12 -04:00
parent b18a41e4aa
commit 2b38658ea6

View File

@@ -8,6 +8,7 @@ import {
type ProductUpdate, type ProductUpdate,
productUpdatesQueries productUpdatesQueries
} from "@app/lib/queries"; } from "@app/lib/queries";
import { build } from "@server/build";
import { useQueries } from "@tanstack/react-query"; import { useQueries } from "@tanstack/react-query";
import { import {
ArrowRight, ArrowRight,
@@ -39,22 +40,42 @@ export default function ProductUpdates({
}) { }) {
const { env } = useEnvContext(); const { env } = useEnvContext();
const productUpdatesEnabled = env.app.notifications.product_updates;
const versionCheckEnabled =
env.app.notifications.new_releases && build !== "saas";
const data = useQueries({ const data = useQueries({
queries: [ queries: [
productUpdatesQueries.list( productUpdatesQueries.list(productUpdatesEnabled, env.app.version),
env.app.notifications.product_updates,
env.app.version
),
productUpdatesQueries.latestVersion( productUpdatesQueries.latestVersion(
env.app.notifications.new_releases env.app.notifications.new_releases
) )
], ],
combine(result) { combine(result) {
if (result[0].isLoading || result[1].isLoading) return null; const [updatesQuery, versionQuery] = result;
return {
updates: result[0].data?.data ?? [], const updatesSettled =
latestVersion: result[1].data !productUpdatesEnabled ||
}; updatesQuery.isFetched ||
updatesQuery.isError;
const versionSettled =
!versionCheckEnabled ||
versionQuery.isFetched ||
versionQuery.isError;
if (!updatesSettled || !versionSettled) return null;
const updates = updatesQuery.isError
? []
: Array.isArray(updatesQuery.data?.data)
? updatesQuery.data.data
: [];
const latestVersion = versionQuery.isError
? undefined
: versionQuery.data;
return { updates, latestVersion };
} }
}); });
const t = useTranslations(); const t = useTranslations();
@@ -76,19 +97,30 @@ export default function ProductUpdates({
if (!data) return null; if (!data) return null;
const latestVersion = data?.latestVersion?.data?.pangolin.latestVersion; const versionResponse = data.latestVersion?.data;
const latestVersion = versionResponse?.pangolin?.latestVersion;
const currentVersion = env.app.version; const currentVersion = env.app.version;
const showNewVersionPopup = Boolean( let showNewVersionPopup = false;
if (
latestVersion && latestVersion &&
valid(latestVersion) && valid(latestVersion) &&
valid(currentVersion) && valid(currentVersion) &&
ignoredVersionUpdate !== latestVersion && ignoredVersionUpdate !== latestVersion
gt(latestVersion, currentVersion) ) {
); try {
showNewVersionPopup = gt(latestVersion, currentVersion);
} catch {
showNewVersionPopup = false;
}
}
const readUpdateIds = Array.isArray(productUpdatesRead)
? productUpdatesRead
: [];
const filteredUpdates = data.updates.filter( const filteredUpdates = data.updates.filter(
(update) => !productUpdatesRead.includes(update.id) (update) => !readUpdateIds.includes(update.id)
); );
if (filteredUpdates.length === 0 && !showNewVersionPopup) { if (filteredUpdates.length === 0 && !showNewVersionPopup) {
@@ -133,17 +165,14 @@ export default function ProductUpdates({
show={filteredUpdates.length > 0} show={filteredUpdates.length > 0}
onDimissAll={() => onDimissAll={() =>
setProductUpdatesRead([ setProductUpdatesRead([
...productUpdatesRead, ...readUpdateIds,
...filteredUpdates.map( ...filteredUpdates.map(
(update) => update.id (update) => update.id
) )
]) ])
} }
onDimiss={(id) => onDimiss={(id) =>
setProductUpdatesRead([ setProductUpdatesRead([...readUpdateIds, id])
...productUpdatesRead,
id
])
} }
/> />
</div> </div>
@@ -151,11 +180,9 @@ export default function ProductUpdates({
</div> </div>
<NewVersionAvailable <NewVersionAvailable
version={data.latestVersion?.data} version={versionResponse}
onDimiss={() => { onDimiss={() => {
setIgnoredVersionUpdate( setIgnoredVersionUpdate(latestVersion ?? null);
data.latestVersion?.data?.pangolin.latestVersion ?? null
);
}} }}
show={showNewVersionPopup} show={showNewVersionPopup}
/> />
@@ -346,6 +373,10 @@ function NewVersionAvailable({
} }
}, [show]); }, [show]);
if (!version?.pangolin?.latestVersion) {
return null;
}
return ( return (
<Transition show={open}> <Transition show={open}>
{version && ( {version && (