Skip to content

Provide public facing hooks for custom fields and views#503

Merged
benmerckx merged 4 commits into
v2from
v2-hooks
May 26, 2026
Merged

Provide public facing hooks for custom fields and views#503
benmerckx merged 4 commits into
v2from
v2-hooks

Conversation

@benmerckx
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds public, dashboard-scoped hooks intended for custom fields/views to access the active entry, graph, user/policy, and to run graph-backed queries with Suspense-friendly caching.

Changes:

  • Exposes new public hooks (useEntry, useGraph, useUser, usePolicy, useGraphQuery) and exports them from alinea/dashboard.
  • Introduces DashboardEntryData.currentEntry to provide the selected entry version as a plain Entry record.
  • Adds tests for useEntry/useGraphQuery behavior and updates dev examples + the legacy useEntryEditor compatibility hook.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/dashboard/store/hooks.tsx Adds public hooks and implements useGraphQuery caching logic.
src/dashboard/store/hooks.test.tsx New tests covering useEntry and useGraphQuery refresh behavior.
src/dashboard/store/Dashboard.ts Adds currentEntry selection atom and adjusts entry translation selection typing.
src/dashboard/hook/UseEntryEditor.ts Updates deprecated compatibility hook to use the new useEntry shape.
src/dashboard.ts Re-exports new public hooks/types from the package entrypoint.
apps/dev/src/schema/example/CustomViewExample.view.tsx Demonstrates new hooks in a custom view example.
apps/dev/src/schema/example/CustomFieldExample.tsx Enables the custom position field example in the dev schema.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/dashboard/store/hooks.tsx Outdated
Comment on lines +299 to +327
let cacheEntry: GraphQueryCacheEntry<Result>
const resource = atom(async get => {
get(dashboard.sha)
const graph = get(dashboard.db)
const config = get(dashboard.config)
const policy = get(dashboard.policy)
const user = (await get(dashboard.user)) ?? null
return cacheEntry.query({
config,
entry: cacheEntry.entry,
graph,
policy,
user
})
})
const state = unwrap(
atom(async get => ({data: await get(resource)})),
previous => previous
)
cached = {
entry,
query,
atom: atom(get => {
const current = get(state)
if (current) return current.data
return get(resource)
})
}
cacheEntry = cached
Comment thread src/dashboard/store/hooks.tsx Outdated
Comment on lines +23 to +28
const nullEntryAtom = atom<EntryRecord<Record<string, unknown>> | null>(null)
const graphQueryCache = new WeakMap<
Dashboard,
Map<string, GraphQueryCacheEntry<unknown>>
>()

@benmerckx benmerckx merged commit df2c64a into v2 May 26, 2026
1 check passed
@benmerckx benmerckx deleted the v2-hooks branch May 26, 2026 09:05
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