-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(tables): harden timezone and expiration handling #7291
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
Open
j15z
wants to merge
11
commits into
staging
Choose a base branch
from
fix/ttl-and-timezone-fixes
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
53ea8f2
fix(timezone): preserve low-year wall clocks
j15z feabe4d
fix(timezone): fall back from invalid saved zones
j15z 50ea9de
fix(tables): report rejected TTL imports
j15z f524db4
fix(timezone): reject empty zone identifiers
j15z b7e5635
fix(tables): dispatch row delete triggers asynchronously
j15z 0d1686e
fix(tables): cap rows to delete snapshot budget
j15z 2300445
fix(tables): signal partial TTL cleanup changes
j15z d1bae69
fix(tables): wait for timezone before date edits
j15z 66766bc
fix(tables): preserve blank TTL values
j15z 5551be8
fix(tables): guard date edits against invalid timezones
j15z 59c6d99
fix(tables): address timezone and delete review findings
j15z File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
apps/sim/app/workspace/[workspaceId]/settings/components/general/timezone-picker.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| AUTO_TIMEZONE_OPTION_VALUE, | ||
| getTimezonePickerPresentation, | ||
| INVALID_TIMEZONE_OPTION_VALUE, | ||
| timezonePreferenceFromPickerValue, | ||
| } from '@/app/workspace/[workspaceId]/settings/components/general/timezone-picker' | ||
|
|
||
| const timezoneOptions = [{ label: 'Los Angeles', value: 'America/Los_Angeles' }] | ||
|
|
||
| describe('getTimezonePickerPresentation', () => { | ||
| it('shows an unset preference as an explicit browser-managed option', () => { | ||
| expect(getTimezonePickerPresentation(null, 'America/Los_Angeles', timezoneOptions)).toEqual({ | ||
| value: AUTO_TIMEZONE_OPTION_VALUE, | ||
| options: [ | ||
| { label: 'Auto: America/Los_Angeles', value: AUTO_TIMEZONE_OPTION_VALUE }, | ||
| ...timezoneOptions, | ||
| ], | ||
| }) | ||
| }) | ||
|
|
||
| it('keeps a valid saved timezone selected independently of Auto', () => { | ||
| expect( | ||
| getTimezonePickerPresentation('America/Los_Angeles', 'America/Los_Angeles', timezoneOptions) | ||
| .value | ||
| ).toBe('America/Los_Angeles') | ||
| }) | ||
|
|
||
| it('adds a valid saved timezone that is absent from the curated options', () => { | ||
| expect(getTimezonePickerPresentation('Etc/GMT+5', 'UTC', timezoneOptions)).toEqual({ | ||
| value: 'Etc/GMT+5', | ||
| options: [ | ||
| { label: 'Auto: UTC', value: AUTO_TIMEZONE_OPTION_VALUE }, | ||
| { label: 'Etc/GMT+5', value: 'Etc/GMT+5' }, | ||
| ...timezoneOptions, | ||
| ], | ||
| }) | ||
| }) | ||
|
|
||
| it('surfaces an invalid saved timezone without making it selectable', () => { | ||
| expect(getTimezonePickerPresentation('Mars/Olympus', 'UTC', timezoneOptions)).toEqual({ | ||
| value: INVALID_TIMEZONE_OPTION_VALUE, | ||
| options: [ | ||
| { label: 'Auto: UTC', value: AUTO_TIMEZONE_OPTION_VALUE }, | ||
| { | ||
| label: 'Invalid: Mars/Olympus', | ||
| value: INVALID_TIMEZONE_OPTION_VALUE, | ||
| disabled: true, | ||
| }, | ||
| ...timezoneOptions, | ||
| ], | ||
| }) | ||
| }) | ||
|
|
||
| it('persists Auto as an unset preference', () => { | ||
| expect(timezonePreferenceFromPickerValue(AUTO_TIMEZONE_OPTION_VALUE)).toBeNull() | ||
| expect(timezonePreferenceFromPickerValue('Asia/Tokyo')).toBe('Asia/Tokyo') | ||
| expect(timezonePreferenceFromPickerValue(INVALID_TIMEZONE_OPTION_VALUE)).toBeUndefined() | ||
| }) | ||
| }) |
59 changes: 59 additions & 0 deletions
59
apps/sim/app/workspace/[workspaceId]/settings/components/general/timezone-picker.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import type { ComboboxOption } from '@sim/emcn' | ||
| import { isValidTimezone, sanitizeTimezoneForDisplay } from '@/lib/core/utils/timezone' | ||
|
|
||
| export const AUTO_TIMEZONE_OPTION_VALUE = '__auto_timezone__' | ||
| export const INVALID_TIMEZONE_OPTION_VALUE = '__invalid_timezone__' | ||
|
|
||
| interface TimezonePickerPresentation { | ||
| value: string | ||
| options: ComboboxOption[] | ||
| } | ||
|
|
||
| /** Builds the picker state without making an unset browser fallback look persisted. */ | ||
| export function getTimezonePickerPresentation( | ||
| savedTimezone: string | null, | ||
| browserTimezone: string, | ||
| timezoneOptions: readonly ComboboxOption[] | ||
| ): TimezonePickerPresentation { | ||
| const hasInvalidTimezone = savedTimezone !== null && !isValidTimezone(savedTimezone) | ||
| const unlistedTimezone = | ||
| savedTimezone !== null && | ||
| !hasInvalidTimezone && | ||
| !timezoneOptions.some((option) => option.value === savedTimezone) | ||
| ? savedTimezone | ||
| : null | ||
| const safeInvalidTimezone = | ||
| savedTimezone === null ? '' : sanitizeTimezoneForDisplay(savedTimezone) | ||
|
|
||
| return { | ||
| value: hasInvalidTimezone | ||
| ? INVALID_TIMEZONE_OPTION_VALUE | ||
| : (savedTimezone ?? AUTO_TIMEZONE_OPTION_VALUE), | ||
| options: [ | ||
| { label: `Auto: ${browserTimezone}`, value: AUTO_TIMEZONE_OPTION_VALUE }, | ||
| ...(hasInvalidTimezone | ||
| ? [ | ||
| { | ||
| label: `Invalid: ${safeInvalidTimezone || '(empty)'}`, | ||
| value: INVALID_TIMEZONE_OPTION_VALUE, | ||
| disabled: true, | ||
| }, | ||
| ] | ||
| : []), | ||
| ...(unlistedTimezone | ||
| ? [ | ||
| { | ||
| label: sanitizeTimezoneForDisplay(unlistedTimezone), | ||
| value: unlistedTimezone, | ||
| }, | ||
| ] | ||
| : []), | ||
| ...timezoneOptions, | ||
| ], | ||
| } | ||
| } | ||
|
|
||
| export function timezonePreferenceFromPickerValue(value: string): string | null | undefined { | ||
| if (value === INVALID_TIMEZONE_OPTION_VALUE) return undefined | ||
| return value === AUTO_TIMEZONE_OPTION_VALUE ? null : value | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.