-
Notifications
You must be signed in to change notification settings - Fork 187
refactor: update handleDefaultState logic for required fields in line… #2382
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
Conversation
…, point, and polygon components
ConsoleProject ID: Sites (2)
Note Cursor pagination performs better than offset pagination when loading further pages. |
WalkthroughUpdates in three Svelte components adjust reactive handling of the Required flag for spatial columns. In line.svelte and polygon.svelte, handleDefaultState is now invoked only when $required is true, preventing automatic default restoration when $required becomes false. In point.svelte, the same conditional invocation is applied, and a new reactive effect synchronizes defaultChecked with whether data.default is non-null. No exported/public APIs were changed. Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/polygon.svelte (1)
83-92
: Bug: deleting breaks ring closure and can throw on undefined ring.ring may be undefined; current code removes the closing coordinate (last index) and doesn’t re-close the ring, yielding invalid polygons. Fix by guarding, removing the last real point, and re-closing; drop the ring if it would fall below the minimal 4-point ring.
- function deleteCoordinate(ringIndex: number) { - const ring = data.default?.at(ringIndex); - - ring.splice(ring.length - 1, 1); - if (ring.length === 0) { - data.default.splice(ringIndex, 1); - } - - data.default = [...(data.default || [])]; - } + function deleteCoordinate(ringIndex: number) { + const ring = data.default?.at(ringIndex); + if (!ring) return; + + // Minimal valid ring: 4 points with last equal to first + if (ring.length <= 4) { + data.default?.splice(ringIndex, 1); + } else { + // Remove last real point (second-to-last index) and re-close the ring + ring.splice(ring.length - 2, 1); + ring[ring.length - 1] = [...ring[0]]; + } + data.default = [...(data.default || [])]; + }
🧹 Nitpick comments (3)
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/line.svelte (1)
87-92
: Call on required=true only: good change; add defaultChecked sync to avoid UI drift on programmatic changes.If $required flips true from upstream, data.default is cleared but defaultChecked may stay true. Mirror point.svelte by syncing defaultChecked from data.default.
$effect(() => { data.required = $required; if ($required) { handleDefaultState(true); } }); + + // Keep the toggle in sync with actual default presence + $effect(() => { + defaultChecked = data.default !== null; + });src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/polygon.svelte (1)
98-103
: Add defaultChecked sync for consistency with point.svelte.Keep the Default toggle reflecting actual data.default when $required changes programmatically.
$effect(() => { data.required = $required; if ($required) { handleDefaultState(true); } }); + + $effect(() => { + defaultChecked = data.default !== null; + });src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/point.svelte (1)
80-82
: Nice: reactive sync of defaultChecked.Prevents UI drift; please replicate this in line/polygon for consistency.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/line.svelte
(1 hunks)src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/point.svelte
(1 hunks)src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/polygon.svelte
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: e2e
🔇 Additional comments (4)
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/polygon.svelte (2)
100-102
: Call on required=true only: good change.Prevents unintended restoration when Required is unchecked. Matches intent of the PR.
111-114
: Redundant else branch — remove or align across components.File: src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/polygon.svelte (lines 111–114)
on:change={(e) => { if (e.detail) defaultChecked = false; else data.default = null; }}
When Required toggles off this handler nulls data.default; Line/Point do not. Either remove the else branch for neutrality or implement the same nulling behavior in the Line and Point components so behavior is consistent.
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/point.svelte (1)
75-78
: Call on required=true only: good change.Matches desired behavior; no restoration when Required is unchecked.
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/line.svelte (1)
100-103
: Minor parity nit: align Required on-change behavior with polygon/point.When Required toggles off, also set data.default = null (like polygon) so all three components behave identically.
File: src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/line.svelte (around lines 100–103). Automated search failed (rg/grep error); unable to confirm handlers—manually verify and apply the change above.
…, point, and polygon components
What does this PR do?
(Provide a description of what this PR does.)
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
(Write your answer here.)
Summary by CodeRabbit