Skip to content

ENG-1187: Prod: Implement get and set for block prop based settings#669

Merged
sid597 merged 3 commits intomainfrom
eng-1187-implement-get-and-set-setttings-as-block-properties-prod
Feb 6, 2026
Merged

ENG-1187: Prod: Implement get and set for block prop based settings#669
sid597 merged 3 commits intomainfrom
eng-1187-implement-get-and-set-setttings-as-block-properties-prod

Conversation

@sid597
Copy link
Collaborator

@sid597 sid597 commented Jan 5, 2026

https://www.loom.com/share/3c07a184d5d740a59410ee49d1fead0c

Summary by CodeRabbit

  • New Features
    • Expanded settings management: unified handling for feature flags, global, personal, and node-specific settings with stronger validation and safer nested reads/writes.
  • Changes
    • Relations data moved from index-based lists to keyed maps for more reliable access and iteration.
    • Added caching and cache invalidation for discourse nodes/relations to improve performance and robustness.
    • Added lightweight stubs/hooks to support left-sidebar personal settings initialization.

✏️ Tip: You can customize this high-level summary in your review settings.


Open with Devin

@linear
Copy link

linear bot commented Jan 5, 2026

@supabase
Copy link

supabase bot commented Jan 5, 2026

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@sid597 sid597 marked this pull request as ready for review January 5, 2026 08:58
@sid597
Copy link
Collaborator Author

sid597 commented Jan 5, 2026

@CodeRabbit ai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 5, 2026

@sid597: I'll perform a full review of this PR now.


🧠 Learnings used
Learnt from: sid597
Repo: DiscourseGraphs/discourse-graph PR: 630
File: apps/roam/src/utils/settingsUsingBlockProps.ts:64-66
Timestamp: 2025-12-22T05:43:09.803Z
Learning: In `apps/roam/src/utils/settingsUsingBlockProps.ts`, the `setBlockPropBasedSettings` function expects callers to ensure that the `value` parameter matches the expected type for the given `keys` path. Type validation is handled at the caller side rather than within the utility function.
✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 5, 2026

📝 Walkthrough

Walkthrough

Adds a new Roam settings accessors module with typed, nested get/set utilities, schema validation, caching and invalidation; converts Relations from arrays to record objects in schemas and defaults; and wires the new accessors into init with stub calls for Left Sidebar personal sections.

Changes

Cohort / File(s) Summary
New Settings Accessors
apps/roam/src/components/settings/utils/accessors.ts
New file exporting ~30 helpers for reading/writing nested Roam block props by UID or settings-page keys: block-level getters/setters, feature-flag/global/personal/discourse-node accessors, caching/invalidation, path-safe deep updates, Zod validation, and small Left Sidebar stub demos.
Init wiring & stubs
apps/roam/src/components/settings/utils/init.ts
Replaced direct Roam query with getAllDiscourseNodes() from the new accessors; added imports for stub helpers and calls to stubSetLeftSidebarPersonalSections and deferred stubGetLeftSidebarPersonalSections. Minor control-flow refactor.
Relations default shape
apps/roam/src/components/settings/data/defaultRelationsBlockProps.ts
Changed export from an array of DiscourseRelationSettings[] to an object keyed by relation ids ({ informs: {...}, supports: {...}, opposes: {...} }), altering iteration/access patterns.
Example schema defaults
apps/roam/src/components/settings/utils/zodSchema.example.ts
Updated example GlobalSettings.Relations from an array to a keyed object (Record<string, Relation>) and defaultGlobalSettings.Relations from [] to {}.
Zod schema updates & top-level keys
apps/roam/src/components/settings/utils/zodSchema.ts
GlobalSettings.Relations changed from z.array(...) to z.record(z.string(), ...) with default cast to record; added and exported TOP_LEVEL_BLOCK_PROP_KEYS constant and updated getTopLevelBlockPropsConfig to use those keys.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Accessors as Accessors Module
    participant Zod as Zod Schema
    participant Roam as Roam Blocks DB
    participant Cache as Local Cache

    Client->>Accessors: getGlobalSetting(keys)
    Accessors->>Cache: check cache for page/block props
    alt cache hit
        Cache-->>Accessors: cached value
    else cache miss
        Accessors->>Roam: read block by page/title/uid
        Roam-->>Accessors: block props (raw)
        Accessors->>Zod: validate/parse props
        Zod-->>Accessors: parsed/typed settings
        Accessors->>Cache: store parsed value
    end
    Accessors-->>Client: return typed setting

    Client->>Accessors: setGlobalSetting(keys, value)
    Accessors->>Zod: validate value against schema
    Zod-->>Accessors: validated payload
    Accessors->>Roam: write/update nested block props
    Roam-->>Accessors: write confirmation
    Accessors->>Cache: invalidate/update cache
    Accessors-->>Client: success
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: implementing get and set functionality for block property-based settings, which aligns with the comprehensive new accessor module and integration work across the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from 1ebeb69 to 22de4b1 Compare January 7, 2026 18:38
@sid597 sid597 force-pushed the eng-1189-prod-init-schema branch 2 times, most recently from e30930e to 0ca99fc Compare January 8, 2026 05:18
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from 22de4b1 to 9464473 Compare January 8, 2026 05:18
@sid597 sid597 force-pushed the eng-1189-prod-init-schema branch from 0ca99fc to 7ea650f Compare January 11, 2026 06:31
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from 9464473 to 3d7e4c7 Compare January 11, 2026 06:31
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from 3d7e4c7 to fb87a45 Compare January 11, 2026 19:54
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from fb87a45 to 3fbeb9f Compare January 12, 2026 15:26
@sid597 sid597 force-pushed the eng-1189-prod-init-schema branch from 0365026 to 76d487b Compare January 12, 2026 15:26
@sid597 sid597 force-pushed the eng-1189-prod-init-schema branch from 76d487b to 3c7d025 Compare January 17, 2026 18:16
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from 3fbeb9f to 6cf85ea Compare January 17, 2026 18:16
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from c43eb11 to 67cb84e Compare January 23, 2026 15:01
@sid597 sid597 changed the base branch from graphite-base/669 to eng-1189-prod-init-schema January 23, 2026 15:01
@sid597 sid597 requested a review from mdroidian January 23, 2026 15:35
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View issue and 4 additional flags in Devin Review.

Open in Devin Review

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start.

Main items to address:

  • Key-path semantics: Several functions accept keys: string[], but the meaning of keys differs by function (sometimes it’s a traversal path, sometimes the first element is treated as a lookup key, etc.). Please make this explicit at the call site—either by splitting functions (e.g., setAtPath vs setRoot / getFromSettingsBlock vs getByUid) or by renaming parameters (path vs settingsKeys) and adding docstrings/examples.

  • Type safety for keys: Callers currently have to manually know the valid keys for each schema. Can we make this more Zod/TypeScript-safe (e.g., typed path helpers, exported key constants, or a small set of typed getters/setters per settings domain) to avoid stringly-typed access?

  • Type assertions: There are a number of as ... assertions. Please reduce these where possible by tightening types and/or adding type guards. If an assertion is truly necessary, add a short comment explaining why it is required, and why it is safe.

  • Export surface: It’s unclear which exports are intended as public API vs internal helpers. Please audit exports and keep only the functions intended for callers outside accessors.ts (or move internal helpers to non-exported scope).

  • Error reporting: Any console.warn that indicates a user-impacting or unexpected state should go through internalError() so we can track it and surface appropriate messaging.

}, settings) as T | undefined;
};

let discourseNodesCache: DiscourseNodeSettings[] | null = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the thought behind having a cache just for discourse node settings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean we should have the caching for other settings as well? Its for discourse node because we have to run a query and thats expensive so we cache it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which query are you referring to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 466 in function getAllDiscourseNodes()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAllDiscourseNodes() (just a handlefull of pages based on a simple string match) shouldn't be a heavy query, let's not cache it

Copy link
Contributor

@sid597 Also make sure you format with prettier

@sid597
Copy link
Collaborator Author

sid597 commented Jan 28, 2026

Did the following changes:

  • use _INF-rel, _SUP-rel etc as the key for default relations
  • reduce usage of as .... to bare minimum
  • use internalError
  • Add schema validation on setters, so each call to setGlobalSetting, setPersonalSetting, first validates the schema and then sets the value. We already do this on read but now also on set. Before this review I was going with , do the validation on the component side itself e.g FlagPanel component first checks the value its setting and only then we set the value the cons of that is iff a user calls the underneath function of setGlobalSetting with any wrong value type
  • removed all the exports that are not sure of if needed later.
  • Inside geAllDiscourseNodes function use fast.q and get block props in same call instead of mutliple calls

@sid597 sid597 changed the base branch from eng-1189-prod-init-schema to graphite-base/669 January 28, 2026 09:53
@sid597 sid597 force-pushed the graphite-base/669 branch from 8a707cf to c0ca4ef Compare January 28, 2026 09:53
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from 67cb84e to 177a47d Compare January 28, 2026 09:53
@sid597 sid597 changed the base branch from graphite-base/669 to main January 28, 2026 09:53
@sid597 sid597 requested a review from mdroidian January 28, 2026 09:54
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View issue and 5 additional flags in Devin Review.

Open in Devin Review

@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from 177a47d to b40fcdc Compare January 28, 2026 18:08
Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments to address then I'd like to walk through this with you 1:1. Also check the merge conflict.

@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from b40fcdc to e11e431 Compare February 2, 2026 09:21
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch 2 times, most recently from 0cf76d1 to c95a994 Compare February 5, 2026 15:12
@sid597 sid597 force-pushed the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch from c95a994 to 132d1c5 Compare February 5, 2026 16:50
@sid597 sid597 requested a review from mdroidian February 5, 2026 16:51
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 5 additional findings in Devin Review.

Open in Devin Review

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just remove the caches for now (shouldn't need them, so let's not make it more complex than we need to). We'll add them back in if we find a need for them.

Then there's a few more comments to address.

}, settings) as T | undefined;
};

let discourseNodesCache: DiscourseNodeSettings[] | null = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAllDiscourseNodes() (just a handlefull of pages based on a simple string match) shouldn't be a heavy query, let's not cache it

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'll approve this, but tag me before merging if there are any issues with implementing the requests.

@sid597 sid597 merged commit a35a194 into main Feb 6, 2026
6 checks passed
@sid597 sid597 deleted the eng-1187-implement-get-and-set-setttings-as-block-properties-prod branch February 6, 2026 12:08
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 6 additional findings in Devin Review.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants