Skip to content

dashboard: consolidate useMetadataQuery into useExportMetadata #4278

@dbm03

Description

@dbm03

Background

The dashboard has two parallel React Query caches for the exact same export_metadata payload:

useMetadataQuery (legacy) useExportMetadata (current)
Path database/dataGrid/hooks/useMetadataQuery/ common/hooks/useExportMetadata/
Cache key caller-supplied (in practice always 'default.metadata') [EXPORT_METADATA_QUERY_KEY, project?.subdomain]
Stale time none (default) 5 min
Refetch on focus yes (default) no
Returns one source pre-narrowed (Partial<HasuraMetadataSource> & { resourceVersion }) full ExportMetadataResponse; callers narrow with select
Endpoint POST /v1/metadata { type: 'export_metadata', version: 2 } same, via generated Orval client

Mutations that touch metadata currently have to invalidate both keys to keep the UI consistent (see RolePermissionEditorForm.tsx, StorageRolePermissionEditorForm.tsx). This is easy to forget — and any site that forgets one of the two ends up reading stale data.

Proposal

Migrate all useMetadataQuery(['default.metadata'], ...) call sites to useExportMetadata, passing a select to derive the slice they need, then delete useMetadataQuery / fetchMetadata.

Call sites to migrate

Reads:

  • database/dataGrid/components/ColumnAutocomplete/ColumnAutocomplete.tsx:104
  • database/dataGrid/components/EditPermissionsForm/EditPermissionsForm.tsx:83
  • database/dataGrid/components/CustomCheckEditor/TableComboBox.tsx:33
  • database/dataGrid/components/CustomCheckEditor/RelationshipNodeRenderer.tsx:44
  • database/dataGrid/components/CustomCheckEditor/AddNodeButton.tsx:52
  • database/dataGrid/components/CustomCheckEditor/RelationshipComboBox.tsx:49
  • storage/dataGrid/components/EditStoragePermissions/StoragePermissionsForm.tsx:48

Invalidations to drop (the EXPORT_METADATA_QUERY_KEY invalidation right next to each already covers it):

  • database/dataGrid/components/EditPermissionsForm/RolePermissionEditorForm.tsx:240
  • storage/dataGrid/components/EditStoragePermissions/StorageRolePermissionEditorForm.tsx:161, 203

Acceptance

  • useMetadataQuery, fetchMetadata, and the 'default.metadata' string are gone from the codebase.
  • All metadata reads go through useExportMetadata with a select.
  • Mutation handlers invalidate only [EXPORT_METADATA_QUERY_KEY, project?.subdomain].

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions