Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(settings): reconcile an uncertain save; offer UTC; check zones by list

M3gA-Mind28c8fe32e422
diff --git a/app/src/components/TimezoneSelect.test.tsx b/app/src/components/TimezoneSelect.test.tsx
index f4eecfae05..006137b34c 100644
--- a/app/src/components/TimezoneSelect.test.tsx
+++ b/app/src/components/TimezoneSelect.test.tsx
@@ -71,13 +71,13 @@ describe('TimezoneSelect', () => {
expect(select.value).toBe('Europe/Berlin');
});
- it('a saved value that is not an Area/Location zone shows as following the device', async () => {
- getMock.mockResolvedValue(settings('EST'));
+ it('a saved value that is not an offered zone shows as following the device', async () => {
+ getMock.mockResolvedValue(settings('Not/AZone'));
render();
const select = (await screen.findByTestId('timezone-select')) as HTMLSelectElement;
await waitFor(() => expect(select.disabled).toBe(false));
expect(select.value).toBe('');
- expect(screen.queryByRole('option', { name: 'EST' })).toBeNull();
+ expect(screen.queryByRole('option', { name: 'Not/AZone' })).toBeNull();
});
it('shows the old zone until the save succeeds', async () => {
@@ -114,4 +114,23 @@ describe('TimezoneSelect', () => {
expect(await screen.findByTestId('timezone-error')).toBeTruthy();
expect((screen.getByTestId('timezone-select') as HTMLSelectElement).disabled).toBe(true);
});
+ it('offers UTC', async () => {
+ getMock.mockResolvedValue(settings(null));
+ render();
+ await screen.findByTestId('timezone-select');
+ expect(screen.getByRole('option', { name: 'UTC' })).toBeTruthy();
+ });
+
+ it('a save that failed after core stored it shows the stored zone, without an error', async () => {
+ getMock
+ .mockResolvedValueOnce(settings('Europe/Berlin'))
+ .mockResolvedValueOnce(settings('Asia/Tokyo'));
+ updateMock.mockRejectedValue(new Error('response lost'));
+ render();
+ const select = (await screen.findByTestId('timezone-select')) as HTMLSelectElement;
+ await waitFor(() => expect(select.value).toBe('Europe/Berlin'));
+ fireEvent.change(select, { target: { value: 'Asia/Tokyo' } });
+ await waitFor(() => expect(select.value).toBe('Asia/Tokyo'));
+ expect(screen.queryByTestId('timezone-error')).toBeNull();
+ });
});
diff --git a/app/src/components/TimezoneSelect.tsx b/app/src/components/TimezoneSelect.tsx
index 53584b8ce2..aec449d166 100644
--- a/app/src/components/TimezoneSelect.tsx
+++ b/app/src/components/TimezoneSelect.tsx
@@ -11,18 +11,20 @@ import { SELECT_CLASS } from './LanguageSelect';
/** The option that follows the device's zone instead of a chosen one. */
const FOLLOW_DEVICE = '';
-function isAreaZone(zone: string | null | undefined): zone is string {
- return !!zone && (zone === 'UTC' || zone.includes('/'));
-}
-
+/** Every zone the picker offers: UTC, then the runtime's IANA zones. */
function ianaZones(): string[] {
try {
- return Intl.supportedValuesOf('timeZone');
+ return ['UTC', ...Intl.supportedValuesOf('timeZone')];
} catch {
- return [];
+ return ['UTC'];
}
}
+/** Whether a saved value is a zone the picker can offer. */
+function isOfferedZone(zone: string | null | undefined): zone is string {
+ return !!zone && ianaZones().includes(zone);
+}
+
interface TimezoneSelectProps {
/** Accessible label for the underlying <select>. */
ariaLabel?: string;
@@ -54,13 +56,10 @@ const TimezoneSelect = ({ ariaLabel }: TimezoneSelectProps) => {
};
}, []);
- // Only an Area/Location zone (or UTC) is ever offered; a saved value that is
- // not one shows as "follow the device", which is what core resolves it to.
- const chosen = isAreaZone(settings?.timezone) ? settings?.timezone : null;
- const zones = useMemo(() => {
- const listed = ianaZones();
- return chosen && !listed.includes(chosen) ? [chosen, ...listed] : listed;
- }, [chosen]);
+ // A saved value that is not an offered zone shows as "follow the device",
+ // which is what core resolves it to.
+ const chosen = isOfferedZone(settings?.timezone) ? settings?.timezone : null;
+ const zones = useMemo(() => ianaZones(), []);
const change = async (value: string) => {
const timezone = value === FOLLOW_DEVICE ? null : value;
@@ -75,7 +74,16 @@ const TimezoneSelect = ({ ariaLabel }: TimezoneSelectProps) => {
current ? { ...current, timezone, effective: timezone ?? current.device ?? 'UTC' } : current
);
} catch {
- setFailed(true);
+ // The save may still have been stored (a lost response, say): show
+ // what core actually holds, and report a failure only if it is not
+ // the pick. If core cannot be read either, report the failure.
+ try {
+ const stored = (await openhumanGetUserTimezone()).result;
+ setSettings(stored);
+ setFailed(stored.timezone !== timezone);
+ } catch {
+ setFailed(true);
+ }
} finally {
setSaving(false);
}