feat: kanban, calendar and group-by table layouts for dashboard view widgets (#22963)
## Context Dashboard view widgets previously only rendered flat tables. This PR ships the full feature: **Table with group-by**, **Kanban**, and **Calendar** layouts for dashboard view widgets — server API + frontend, end-to-end. (Originally staged as a 4-PR stack — #22966, #22967, #22968 — consolidated here per review.) ## Server / API - **View typing.** Adds `KANBAN_WIDGET` and `CALENDAR_WIDGET` to `ViewType` (following the `TABLE_WIDGET` precedent) so widget-backing views keep their layout in `view.type` while staying excluded from record-index pickers. Shared `getViewLayoutFromViewType()` maps widget types to their base layout; `isWidgetViewType()` centralizes the exclusions that were previously hardcoded per-site. - **Migrations.** Two fast instance commands (**2.23**): `ALTER TYPE core.view_type_enum ADD VALUE` for both values, and a widened `CHK_VIEW_CALENDAR_INTEGRITY` constraint covering `CALENDAR_WIDGET` (entity `@Check` updated for fresh installs). - **Validation.** `FlatViewValidatorService` keys kanban/calendar validation on the mapped layout, so widget views get the same invariants as index views (kanban needs a groupable group-by field; calendar needs a date field + layout). Calendar widget views default to month; a non-month (DAY/WEEK) layout is rejected at the API level **unless** the `IS_CALENDAR_WEEK_VIEW_ENABLED` feature flag is enabled for the workspace — the same flag that gates day/week on index calendars. - **API.** `upsertViewWidget` (LAYOUTS permission) accepts a nested `view` settings input (`type`, `mainGroupByFieldMetadataId`, `shouldHideEmptyGroups`, kanban aggregate/column-width, calendar layout/fields). Routes through the standard update path, so `viewGroups` auto-generate from SELECT options exactly like index views. Only widget view types accepted; only `RECORD_TABLE` widgets can change view settings. - **AI tools.** `create-complete-dashboard` + `create_view` now use/allow the `*_WIDGET` types (previously they created plain `TABLE` views that leak into index pickers). ## Frontend **Settings panel.** The **Source** (object) row comes first, since which layouts are available depends on it. The **Layout** row below is a working dropdown (Table / Kanban / Calendar); layouts the source object can't support are **disabled with a hint** ("Needs a Select field" / "Needs a Date field") rather than hidden. Group-by row (select fields; searchable) with a **Hide empty groups** toggle while grouped; **Date field** row replaces Group by while Calendar is active, and — when the `IS_CALENDAR_WEEK_VIEW_ENABLED` flag is on — a **Calendar view** row (Day / Week / Month) appears beside it; **Limit** row hidden while grouped (only the flat virtualized loader enforces it). Kanban keeps its group-by locked (no `None` option). **Instant edit-mode preview.** Draft snapshots carry `viewGroups`; picking a group-by synthesizes them client-side (`buildDraftViewGroupsForFieldMetadataItem`, mirroring the server's generation), so grouped tables/boards preview immediately before dashboard save. On save, `upsertViewWidget` responses hand back the server-generated groups, which replace the client-generated ones in the persisted snapshot. **Renderers.** `RecordTableWidgetRendererContent` branches on the backing view's layout: `RecordBoardWidget` (wraps the standard `RecordBoardContainer`) and `RecordCalendarWidget` (mounts the existing `RecordCalendar`, which renders month / day / week) inside the same per-widget provider sandbox the table uses. **Read-only semantics.** Two flags with distinct scopes, each documented on its state: - `isRecordBoardViewSettingsReadOnlyComponentState` — locks the board chrome that edits view settings (add group, column reorder/resize/menu, aggregates); **card drag still updates records** under object permissions. - `isRecordCalendarReadOnlyComponentState` — widget calendars are read-only by default (no drag, no add-new, no in-calendar layout switch); cards open the side panel. The one exception, behind `IS_CALENDAR_WEEK_VIEW_ENABLED`: a **live (non edit-mode) day/week** widget calendar allows drag-to-reschedule and record creation under object permissions. Month calendars and edit-mode previews stay read-only. **Calendar state componentization.** The calendar module's three settings move from global atoms to component states keyed on `RecordCalendarComponentInstanceContext` (same pattern as record-board), so several calendar widgets and an index-page calendar can coexist without leaking state. All readers resolve the ambient instance; calendar unit tests updated. **Multi-instance fixes that also fix index pages:** record drag states were written against a different instance than every reader resolves (now use the ambient instance); the board sticky-header DOM id is namespaced per board; dragged board cards portal to `document.body` while dragging so react-grid-layout's transforms can't offset the clone from the pointer. ## Scope (v1) - Widget calendars are month-only and read-only by default. With `IS_CALENDAR_WEEK_VIEW_ENABLED` enabled, day/week layouts become selectable (UI + API) and live day/week widget calendars support drag-to-reschedule and record creation under object permissions. - Widget group-by offers SELECT fields only (server auto-generates groups from options; widgets have no per-record add-group flow). ## Tests - Integration: `upsert-view-widget-view-settings.integration-spec.ts` (9 tests — group auto-creation, invalid type/field rejections, non-month calendar widget rejected while the week/day flag is off and accepted once it's enabled, combined settings+fields call); pre-existing `upsert-view-widget` suite (20) green. - Front: new suites for draft view-group generation and snapshot clone/build utils; calendar suites componentized; full `twenty-front` jest, typecheck, oxlint green; `twenty-server` typecheck + lint green. - Browser-verified end-to-end (real dev server + seeded workspace): configure → live edit-mode preview → save → reload for all three layouts; measured drag with pointer inside the card; index-page calendar re-verified (with the week/day flag enabled). https://claude.ai/code/session_01E5N87kwwZWhDtEQaP72cMf
This commit is contained in:
+37
-6
@@ -1,7 +1,13 @@
|
||||
import { msg, t } from '@lingui/core/macro';
|
||||
import { type ALL_METADATA_NAME } from 'twenty-shared/metadata';
|
||||
import { FieldMetadataType, RelationType, ViewType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
FeatureFlagKey,
|
||||
FieldMetadataType,
|
||||
RelationType,
|
||||
ViewCalendarLayout,
|
||||
ViewType,
|
||||
} from 'twenty-shared/types';
|
||||
import { getViewLayoutFromViewType, isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { findFlatEntityByUniversalIdentifier } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-universal-identifier.util';
|
||||
import { isMorphOrRelationUniversalFlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/utils/is-morph-or-relation-flat-field-metadata.util';
|
||||
@@ -23,11 +29,13 @@ export class FlatViewValidatorService {
|
||||
private validateCalendarFields({
|
||||
flatView,
|
||||
flatFieldMetadataMaps,
|
||||
isCalendarWeekViewEnabled,
|
||||
}: {
|
||||
flatView: UniversalFlatView;
|
||||
flatFieldMetadataMaps: AllUniversalFlatEntityMaps['flatFieldMetadataMaps'];
|
||||
isCalendarWeekViewEnabled: boolean;
|
||||
}): FlatEntityValidationError[] {
|
||||
if (flatView.type !== ViewType.CALENDAR) {
|
||||
if (getViewLayoutFromViewType(flatView.type) !== ViewType.CALENDAR) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -41,6 +49,22 @@ export class FlatViewValidatorService {
|
||||
});
|
||||
}
|
||||
|
||||
// Widget calendars only allow non-month layouts when the day/week
|
||||
// calendar feature is enabled; while it is off the month grid stays a
|
||||
// data invariant rather than a UI-only convention.
|
||||
if (
|
||||
flatView.type === ViewType.CALENDAR_WIDGET &&
|
||||
!isCalendarWeekViewEnabled &&
|
||||
isDefined(flatView.calendarLayout) &&
|
||||
flatView.calendarLayout !== ViewCalendarLayout.MONTH
|
||||
) {
|
||||
errors.push({
|
||||
code: ViewExceptionCode.INVALID_VIEW_DATA,
|
||||
message: t`Calendar widget views only support the month layout`,
|
||||
userFriendlyMessage: msg`Calendar widget views only support the month layout`,
|
||||
});
|
||||
}
|
||||
|
||||
if (!isDefined(flatView.calendarFieldMetadataUniversalIdentifier)) {
|
||||
errors.push({
|
||||
code: ViewExceptionCode.INVALID_VIEW_DATA,
|
||||
@@ -185,6 +209,7 @@ export class FlatViewValidatorService {
|
||||
flatViewMaps: optimisticFlatViewMaps,
|
||||
flatFieldMetadataMaps,
|
||||
},
|
||||
additionalCacheDataMaps: { featureFlagsMap },
|
||||
}: FlatEntityUpdateValidationArgs<
|
||||
typeof ALL_METADATA_NAME.view
|
||||
>): FailedFlatEntityValidation<'view', 'update'> {
|
||||
@@ -240,8 +265,8 @@ export class FlatViewValidatorService {
|
||||
}
|
||||
|
||||
const viewBecomesKanban =
|
||||
updatedFlatView.type === ViewType.KANBAN &&
|
||||
existingFlatView.type !== ViewType.KANBAN;
|
||||
getViewLayoutFromViewType(updatedFlatView.type) === ViewType.KANBAN &&
|
||||
getViewLayoutFromViewType(existingFlatView.type) !== ViewType.KANBAN;
|
||||
|
||||
if (viewBecomesKanban) {
|
||||
if (
|
||||
@@ -318,6 +343,8 @@ export class FlatViewValidatorService {
|
||||
...this.validateCalendarFields({
|
||||
flatView: updatedFlatView,
|
||||
flatFieldMetadataMaps,
|
||||
isCalendarWeekViewEnabled:
|
||||
featureFlagsMap[FeatureFlagKey.IS_CALENDAR_WEEK_VIEW_ENABLED],
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -392,6 +419,7 @@ export class FlatViewValidatorService {
|
||||
flatFieldMetadataMaps,
|
||||
flatObjectMetadataMaps,
|
||||
},
|
||||
additionalCacheDataMaps: { featureFlagsMap },
|
||||
}: UniversalFlatEntityValidationArgs<
|
||||
typeof ALL_METADATA_NAME.view
|
||||
>): FailedFlatEntityValidation<'view', 'create'> {
|
||||
@@ -450,7 +478,8 @@ export class FlatViewValidatorService {
|
||||
});
|
||||
}
|
||||
|
||||
const isKanban = flatViewToValidate.type === ViewType.KANBAN;
|
||||
const isKanban =
|
||||
getViewLayoutFromViewType(flatViewToValidate.type) === ViewType.KANBAN;
|
||||
|
||||
if (isKanban) {
|
||||
if (
|
||||
@@ -496,6 +525,8 @@ export class FlatViewValidatorService {
|
||||
...this.validateCalendarFields({
|
||||
flatView: flatViewToValidate,
|
||||
flatFieldMetadataMaps,
|
||||
isCalendarWeekViewEnabled:
|
||||
featureFlagsMap[FeatureFlagKey.IS_CALENDAR_WEEK_VIEW_ENABLED],
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user