-
Notifications
You must be signed in to change notification settings - Fork 2
[ENG-844] Add color setting for relation types #429
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
This pull request has been ignored for the connected project Preview Branches by Supabase. |
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughAdds a color property to DiscourseRelationType across types, constants, and UI. Updates RelationshipTypeSettings to capture, validate, and store color per relation type, defaulting to "black" for new entries. DEFAULT_RELATION_TYPES now specify color values. handleRelationTypeChange made synchronous. Save validation now requires color. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as User
participant UI as RelationshipTypeSettings
participant S as Local State
U->>UI: Change color for a relation type
UI->>S: handleRelationTypeChange(index,"color",value) (sync update)
Note right of S: State now includes color per type (default "black" for new)
U->>UI: Click "Add relation type"
UI->>S: Append {id,label,complement,color:"black"}
U->>UI: Click "Save"
UI->>UI: Validate id, label, complement, color
alt Any missing field
UI-->>U: Show validation error
else All fields present
UI->>S: Persist updated relation types
UI-->>U: Confirm saved
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. 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: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
apps/obsidian/src/components/RelationshipTypeSettings.tsx (2)
79-85
: Validate hex format and trim text fields before save.Prevents whitespace-only labels/complements and rejects non-hex colors that slipped in from legacy data.
const handleSave = async (): Promise<void> => { - for (const relType of relationTypes) { - if (!relType.id || !relType.label || !relType.complement || !relType.color) { + const HEX_COLOR_RE = /^#[0-9A-Fa-f]{6}$/; + for (const relType of relationTypes) { + const label = relType.label?.trim(); + const complement = relType.complement?.trim(); + const color = relType.color || "#000000"; + if (!relType.id || !label || !complement || !color) { new Notice("All fields are required for relation types."); return; } + if (!HEX_COLOR_RE.test(color)) { + new Notice("Color must be a 6-digit hex (e.g., #22C55E)."); + return; + } }Optionally also enforce case-insensitive uniqueness using the trimmed values.
10-12
: Initialize state with normalized colors (migration-in-place).Backfill missing/invalid colors when seeding state so the form renders valid values for legacy settings.
Add near state initialization:
- const [relationTypes, setRelationTypes] = useState<DiscourseRelationType[]>( - () => plugin.settings.relationTypes ?? [], - ); + const [relationTypes, setRelationTypes] = useState<DiscourseRelationType[]>( + () => (plugin.settings.relationTypes ?? []).map(rt => ({ + ...rt, + color: /^#[0-9A-Fa-f]{6}$/.test(rt.color ?? "") ? rt.color! : "#000000", + })), + );This avoids React controlled/uncontrolled warnings and keeps the color input valid from the start.
🧹 Nitpick comments (2)
apps/obsidian/src/components/RelationshipTypeSettings.tsx (2)
107-110
: Prefer stable keys over array indices.Use
relationType.id
to avoid key-mismatch issues on reorder/insert.- <div key={index} className="setting-item"> + <div key={relationType.id || index} className="setting-item">
22-23
: Unify ID prefixes for readability (optional).Elsewhere uses
generateUid("relation")
; here it’s"rel"
. Align unless there’s a reason to diverge.- const newId = generateUid("rel"); + const newId = generateUid("relation");(Same change in
handleAddRelationType
.)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/obsidian/src/components/RelationshipTypeSettings.tsx
(4 hunks)apps/obsidian/src/constants.ts
(1 hunks)apps/obsidian/src/types.ts
(1 hunks)
🔇 Additional comments (2)
apps/obsidian/src/types.ts (1)
17-18
: I’ve initiated searches to locate whererelationTypes
are loaded/saved and if default/color backfills occur in the plugin code.apps/obsidian/src/components/RelationshipTypeSettings.tsx (1)
15-20
: Sync handler change LGTM.Good move making
handleRelationTypeChange
synchronous.
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.
👍
Could changes requested, then good to merge.
* add color setting * address PR reviews * address PR commens
* add color setting * address PR reviews * address PR commens
* [ENG-495] Tldraw obsidian setup (#285) * cleaned * sm * address PR comments * [ENG-598] Data persistence for tldraw (#303) * data persistence to the file * error handling * address PR comments * address some PR comments * address other PR comments * address PR comments * [ENG-624] TLDraw Obsidian asset store (#326) * current state * works now * clean up * address PR comments * address PR reviews * cleanup * fix styling issues * address PR comments * correct styles * [ENG-599] Discourse node shape (#341) * current state * works now * clean up * address PR comments * address PR reviews * fix styling issues * latest progress * update new shape * shape defined * address PR comments * sm address PR review * current progress * reorg * address other PR comments * clean * simplify flow * address PR comments * [ENG-604] Create node flow (#387) * eng-604: create node flow * pwd * [ENG-658] Add existing node flow (#389) * eng-658-add-existing-nodes-flow * address PR comments * small changes * [ENG-601] Create settings for canvas and attachment default folder (#338) * add new settings * small add * ENG-600: Discourse Relation shape definition (#408) * ENG-605: Add new relation flow (#411) * [ENG-603] Add existing relations (#412) https://www.loom.com/share/3641f2a642714b0d849262344e8c6ee5?sid=0614c657-e541-4bfd-92df-9b1aa60945b6 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a Relations overlay on the canvas that shows a “Relations” button when a discourse node is selected. - Introduced a Relations panel to view and manage relations for the selected node, including adding or removing links, with clear loading/error states. - Overlay appears above the canvas without disrupting existing tools. - Chores - Consolidated relation-type lookup into shared utilities and updated imports. No user-facing changes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> * [ENG-844] Add color setting for relation types (#429) * add color setting * address PR reviews * address PR commens * fix icons * ENG-812 Update of database cli tools (#401) * eng-812 : Update database cli tools: supabase, vercel, cucumber. * newer cucumber constrains node * [ENG-495] Tldraw obsidian setup (#285) * cleaned * sm * address PR comments * [ENG-598] Data persistence for tldraw (#303) * data persistence to the file * error handling * address PR comments * address some PR comments * address other PR comments * address PR comments * switch to pnpm * delete wrong rebase file * fix pnpm lock * fix type checks * address all the PR comments * delete redundant files * fix types * shift click to open file on the right split (#485) * address PR comments * final lint cleanup --------- Co-authored-by: Marc-Antoine Parent <[email protected]>
Summary by CodeRabbit