eng-273 feat(crm): add entity view adapter registry#384
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 9 minutes and 50 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (10)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Reviewer's GuideIntroduces a centralized CRM entity view adapter registry and dedicated UI adapters for system objects, enriching adapter contracts with layout defaults, field overrides, and computed fields, then wires those contracts into view schema generation, admin record sidebar rendering, audit log aggregation tests, and system-object tests. Sequence diagram for getViewSchema using entity view adapter registrysequenceDiagram
participant Client
participant crm_viewQueries as crm_viewQueries_getViewSchema
participant DB as Database
participant AdapterRegistry as resolveEntityViewAdapterContract
participant ViewSchemaEngine as View_schema_helpers
Client->>crm_viewQueries: getViewSchema(viewId)
crm_viewQueries->>DB: load viewDef, objectDef, fieldDefs, viewFields
DB-->>crm_viewQueries: viewDef, objectDef, fieldDefs, viewFields
crm_viewQueries->>AdapterRegistry: resolveEntityViewAdapterContract(currentLayout, fieldDefs, objectDef, objectDef._id)
AdapterRegistry->>AdapterRegistry: resolveEntityViewDefinition(objectDef)
AdapterRegistry->>AdapterRegistry: buildSupportedLayouts(currentLayout, fieldDefs)
AdapterRegistry->>AdapterRegistry: buildLayoutDefaults(definition, fieldDefs)
AdapterRegistry->>AdapterRegistry: normalizeOverrides(definition.fieldOverrides, fieldDefs)
AdapterRegistry-->>crm_viewQueries: adapterContract
crm_viewQueries->>ViewSchemaEngine: buildFieldOverridesByName(adapterContract)
ViewSchemaEngine-->>crm_viewQueries: fieldOverridesByName
crm_viewQueries->>ViewSchemaEngine: buildSchemaOrderHints(adapterContract, viewDef.isDefault)
ViewSchemaEngine-->>crm_viewQueries: schemaOrderHints
loop Columns
crm_viewQueries->>ViewSchemaEngine: applyFieldOverridesToColumn(column, viewDef.viewType, schemaOrderHints, override)
ViewSchemaEngine->>ViewSchemaEngine: resolveSchemaDisplayOrder(...)
ViewSchemaEngine-->>crm_viewQueries: adjustedColumn
end
loop PersistedFields
crm_viewQueries->>ViewSchemaEngine: applyFieldOverridesToDefinition(viewDef.viewType, field, schemaOrderHints, override)
ViewSchemaEngine-->>crm_viewQueries: adjustedField
end
crm_viewQueries->>ViewSchemaEngine: toComputedNormalizedFieldDefinition(computedField, displayOrder, objectDef._id)
ViewSchemaEngine-->>crm_viewQueries: computedFieldDefinition
crm_viewQueries->>ViewSchemaEngine: compareSchemaItemsByDisplayOrder(left, right)
ViewSchemaEngine-->>crm_viewQueries: sortOrder
crm_viewQueries-->>Client: { adapterContract, columns, fields, viewType }
Sequence diagram for Admin record sidebar using dedicated detail adapterssequenceDiagram
actor AdminUser
participant AdminRecordDetailSurface as AdminRecordDetailSurface
participant AdapterResolver as resolveRecordSidebarEntityAdapter
participant DetailsTab as DetailsTab
participant DedicatedAdapter as RecordSidebarEntityAdapter
participant FieldGrid as renderPrioritizedFieldGrid
AdminUser->>AdminRecordDetailSurface: open record sidebar(reference)
AdminRecordDetailSurface->>AdminRecordDetailSurface: load objectDef, entity, record, fieldDefs
AdminRecordDetailSurface->>AdapterResolver: resolveRecordSidebarEntityAdapter(entityType, objectDef, overrides)
AdapterResolver->>AdapterResolver: getAdminEntityForObjectDef(objectDef)
AdapterResolver->>AdapterResolver: lookup dedicated adapter by entityType
AdapterResolver->>AdapterResolver: merge dedicated adapter with overrides
AdapterResolver-->>AdminRecordDetailSurface: adapter
AdminRecordDetailSurface->>DetailsTab: render(adapter, entity, fieldDefs, objectDef, record, recordId)
alt Adapter provides dedicated details view
DetailsTab->>DedicatedAdapter: renderDetailsTab(entity, fieldDefs, objectDef, record, recordId)
DedicatedAdapter->>FieldGrid: renderPrioritizedFieldGrid(fieldDefs, priorityFieldNames, record)
FieldGrid-->>DedicatedAdapter: ReactNode detailsContent
DedicatedAdapter-->>DetailsTab: detailsContent
DetailsTab-->>AdminRecordDetailSurface: dedicated detailsContent
else No dedicated adapter
DetailsTab->>DetailsTab: compute visibleFields from fieldDefs and record
DetailsTab-->>AdminRecordDetailSurface: generic details grid
end
AdminRecordDetailSurface-->>AdminUser: sidebar with dedicated or generic details tab
Class diagram for CRM entity view adapter contracts and registryclassDiagram
class EntityViewComputedFieldContract {
+string description
+string expressionKey
+string fieldName
+string fieldType
+boolean isVisibleByDefault
+string label
+FieldRendererHint rendererHint
+string[] sourceFieldNames
}
class EntityViewDetailContract {
+string mode
+string surfaceKey
}
class EntityViewFieldOverrideContract {
+string fieldName
+ViewLayout[] hiddenInLayouts
+boolean isVisibleByDefault
+string label
+number preferredDisplayOrder
}
class EntityViewLayoutDefaultsContract {
+string calendarDateFieldName
+string kanbanFieldName
+string[] preferredVisibleFieldNames
}
class EntityViewAdapterContract {
+EntityViewComputedFieldContract[] computedFields
+EntityViewDetailContract detail
+string detailSurfaceKey
+string entityType
+EntityViewFieldOverrideContract[] fieldOverrides
+EntityViewLayoutDefaultsContract layoutDefaults
+Id_objectDefs objectDefId
+string statusFieldName
+ViewLayout[] supportedLayouts
+string titleFieldName
+string variant
}
class EntityViewAdapterDefinition {
+string[] aliases
+EntityViewComputedFieldContract[] computedFields
+EntityViewDetailContract detail
+string entityType
+EntityViewFieldOverrideContract[] fieldOverrides
+EntityViewLayoutDefaultsContract layoutDefaults
+string[] statusFieldCandidates
+string[] titleFieldCandidates
}
class FieldDef {
+string _id
+string name
+string label
+string fieldType
+boolean isVisibleByDefault
+number displayOrder
+LayoutEligibility layoutEligibility
}
class ObjectDef {
+Id_objectDefs _id
+string name
+string singularLabel
+string pluralLabel
+string nativeTable
}
class NormalizedFieldDefinition {
+AggregationMetadata aggregation
+ComputedMetadata computed
+string description
+number displayOrder
+EditabilityMetadata editability
+Id_fieldDefs fieldDefId
+string fieldSource
+string fieldType
+boolean isActive
+boolean isRequired
+boolean isUnique
+boolean isVisibleByDefault
+string label
+LayoutEligibility layoutEligibility
+string name
+boolean nativeReadOnly
+string normalizedFieldKind
+Id_objectDefs objectDefId
+any options
+any relation
+FieldRendererHint rendererHint
}
EntityViewAdapterContract "*" o-- "1" EntityViewDetailContract : detail
EntityViewAdapterContract "*" o-- "*" EntityViewComputedFieldContract : computedFields
EntityViewAdapterContract "*" o-- "*" EntityViewFieldOverrideContract : fieldOverrides
EntityViewAdapterContract "*" o-- "1" EntityViewLayoutDefaultsContract : layoutDefaults
EntityViewAdapterContract "1" --> "1" ObjectDef : objectDefId
EntityViewAdapterDefinition "1" o-- "1" EntityViewDetailContract : detail
EntityViewAdapterDefinition "*" o-- "*" EntityViewComputedFieldContract : computedFields
EntityViewAdapterDefinition "*" o-- "*" EntityViewFieldOverrideContract : fieldOverrides
EntityViewAdapterDefinition "1" o-- "1" EntityViewLayoutDefaultsContract : layoutDefaults
NormalizedFieldDefinition "*" --> "1" FieldDef : fieldDefId
NormalizedFieldDefinition "*" --> "1" ObjectDef : objectDefId
class EntityViewAdapterRegistry {
+Map_string_EntityViewAdapterDefinition ENTITY_VIEW_ADAPTERS_BY_ALIAS
+EntityViewAdapterContract resolveEntityViewAdapterContract(currentLayout, fieldDefs, objectDef, objectDefId)
+ViewLayout[] buildSupportedLayouts(currentLayout, fieldDefs)
+EntityViewLayoutDefaultsContract buildLayoutDefaults(definition, fieldDefs)
+EntityViewAdapterDefinition resolveEntityViewDefinition(objectDef)
+string resolveFallbackEntityType(objectDef)
+EntityViewFieldOverrideContract[] normalizeOverrides(overrides, fieldDefs)
}
EntityViewAdapterRegistry ..> EntityViewAdapterDefinition : uses
EntityViewAdapterRegistry ..> EntityViewAdapterContract : builds
EntityViewAdapterRegistry ..> FieldDef : reads
EntityViewAdapterRegistry ..> ObjectDef : reads
EntityViewAdapterRegistry ..> EntityViewLayoutDefaultsContract : builds
EntityViewAdapterRegistry ..> EntityViewFieldOverrideContract : builds
EntityViewAdapterRegistry ..> EntityViewComputedFieldContract : exposes
class ViewSchemaEngine {
+Map_string_EntityViewFieldOverrideContract buildFieldOverridesByName(adapterContract)
+Map_string_number buildSchemaOrderHints(adapterContract, viewIsDefault)
+number resolveSchemaDisplayOrder(baseDisplayOrder, fieldName, orderHints, override)
+ViewSchemaColumn applyFieldOverridesToColumn(column, currentLayout, orderHints, override)
+NormalizedFieldDefinition applyFieldOverridesToDefinition(currentLayout, field, orderHints, override)
+NormalizedFieldDefinition toComputedNormalizedFieldDefinition(computedField, displayOrder, objectDefId)
+number compareSchemaItemsByDisplayOrder(leftDisplayOrder, leftName, rightDisplayOrder, rightName)
}
ViewSchemaEngine ..> EntityViewAdapterContract : consumes
ViewSchemaEngine ..> EntityViewFieldOverrideContract : consumes
ViewSchemaEngine ..> EntityViewComputedFieldContract : consumes
ViewSchemaEngine ..> NormalizedFieldDefinition : produces
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Sorry @Connorbelez, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
There was a problem hiding this comment.
Pull request overview
Adds a registry-driven “entity view adapter” layer to CRM view schema generation and the admin record sidebar, so system/native objects can supply dedicated metadata (layout defaults, field overrides, computed fields) and dedicated detail rendering behavior.
Changes:
- Introduces a Convex-side CRM entity adapter registry and uses it in
getViewSchemato apply adapter-derived layout defaults, field overrides, and adapter-computed fields (withfieldSourcetracking). - Adds a client-side admin record sidebar adapter resolver + dedicated detail renderers with priority-ordered fields per entity type.
- Updates/extends tests (CRM view engine + admin shell) and adjusts Convex test component registration to include aggregate components used by audit views.
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/admin/admin-shell.test.ts | Adds tests for dedicated sidebar adapter resolution, override preservation, and priority-order field rendering. |
| src/components/admin/shell/RecordSidebar.tsx | Switches sidebar adapter selection to registry-based resolver; supports adapter-provided Details tab rendering. |
| src/components/admin/shell/entity-view-adapters.tsx | New dedicated sidebar adapter registry + resolver and prioritized field rendering helper. |
| package.json | Adds @fast-check/vitest dev dependency. |
| bun.lock | Locks new dev dependency and transitive deps. |
| convex/test/registerAuditLogComponent.ts | Registers aggregate components alongside audit-log component for tests. |
| convex/crm/viewQueries.ts | Integrates entity adapter contract into schema generation; applies overrides, adds computed fields, and tracks field source. |
| convex/crm/types.ts | Extends adapter contract model; adds computed field/override/layout defaults contracts; adds fieldSource and optional fieldDefId. |
| convex/crm/entityAdapterRegistry.ts | New Convex-side registry to derive adapter contracts from object defs/field defs. |
| convex/crm/tests/viewEngine.test.ts | Extends schema assertions for adapter metadata, overrides, computed fields; updates audit action expectation; adds borrower native record field assertions. |
| convex/_generated/api.d.ts | Updates generated API typings to include new module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5482b67 to
c474ff8
Compare
Merge activity
|
feat(crm): add entity view adapter registry responding to feedback ## Summary by Sourcery Introduce a registry-driven entity view adapter system for CRM views and admin UI, enabling dedicated adapters, field overrides, and computed fields for system objects while updating tests and audit logging components accordingly. New Features: - Add a centralized CRM entity view adapter registry that derives adapter contracts, layout defaults, field overrides, and computed fields from object definitions and layouts. - Extend view schema generation to include adapter-computed fields and apply adapter-driven field overrides and ordering to both schema fields and columns. - Introduce dedicated admin record sidebar adapters that render detail fields in a configurable priority order per entity type and support consumer overrides. - Expose new adapter-related metadata on CRM view schemas, including variant, detail surface configuration, layout defaults, and field source tracking for fields. Bug Fixes: - Adjust audit log tests to assert the correct action name when updating CRM records. - Ensure system object record queries surface native borrower fields consistently in unified records. Enhancements: - Track field source (persisted vs adapter-computed) in normalized field definitions across CRM views. - Refine the entity view adapter contract model with explicit detail, layout defaults, field override, and computed field subcontracts. - Improve admin shell tests and helpers to validate dedicated adapter resolution and field ordering behavior in the sidebar details view. Build: - Register the Convex aggregate component alongside the audit log component in tests to support aggregation-based audit views. Tests: - Add comprehensive tests for system object view schemas, verifying dedicated adapter metadata, field overrides, and computed field behavior for mortgages and borrowers. - Extend admin shell tests to cover dedicated sidebar adapter resolution, override preservation, and prioritized detail field rendering.

feat(crm): add entity view adapter registry
responding to feedback
Summary by Sourcery
Introduce a registry-driven entity view adapter system for CRM views and admin UI, enabling dedicated adapters, field overrides, and computed fields for system objects while updating tests and audit logging components accordingly.
New Features:
Bug Fixes:
Enhancements:
Build:
Tests: