Skip to content

The open alternative to Salesforce, designed for AI.

4.4 KB
Raw Blame
import {
  Field,
  HideField,
  Int,
  ObjectType,
  registerEnumType,
} from '@nestjs/graphql';
import {
  AggregateOperations,
  ViewCalendarLayout,
  ViewOpenRecordIn,
  ViewType,
  ViewVisibility,
  ViewKey,
} from 'twenty-shared/types';

import { type AuthoredOverrides } from 'src/engine/metadata-modules/overrides/types/authored-overrides.type';
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
import { ViewFieldGroupDTO } from 'src/engine/metadata-modules/view-field-group/dtos/view-field-group.dto';
import { type ViewOverrides } from 'src/engine/metadata-modules/view/entities/view.entity';
import { ViewFieldDTO } from 'src/engine/metadata-modules/view-field/dtos/view-field.dto';
import { ViewFilterGroupDTO } from 'src/engine/metadata-modules/view-filter-group/dtos/view-filter-group.dto';
import { ViewFilterDTO } from 'src/engine/metadata-modules/view-filter/dtos/view-filter.dto';
import { ViewGroupDTO } from 'src/engine/metadata-modules/view-group/dtos/view-group.dto';
import { ViewSortDTO } from 'src/engine/metadata-modules/view-sort/dtos/view-sort.dto';
import { VIEW_OPEN_RECORD_IN_DEPRECATION } from 'src/engine/metadata-modules/view/constants/view-open-record-in-deprecation.constant';

registerEnumType(ViewOpenRecordIn, { name: 'ViewOpenRecordIn' });
registerEnumType(ViewType, { name: 'ViewType' });
registerEnumType(ViewKey, { name: 'ViewKey' });
registerEnumType(ViewCalendarLayout, { name: 'ViewCalendarLayout' });
registerEnumType(ViewVisibility, { name: 'ViewVisibility' });

@ObjectType('View')
export class ViewDTO {
  @Field(() => UUIDScalarType)
  id: string;

  @Field(() => UUIDScalarType, { nullable: false })
  universalIdentifier: string;

  @Field(() => UUIDScalarType, { nullable: false })
  applicationId: string;

  @Field({ nullable: false })
  isSystemSideEffect: boolean;

  @Field({ nullable: false })
  name: string;

  @Field(() => UUIDScalarType, { nullable: false })
  objectMetadataId: string;

  @Field(() => ViewType, { nullable: false, defaultValue: ViewType.TABLE })
  type: ViewType;

  @Field(() => ViewKey, { nullable: true, defaultValue: ViewKey.INDEX })
  key: ViewKey | null;

  @Field({ nullable: false })
  icon: string;

  @Field({ nullable: false, defaultValue: 0 })
  position: number;

  @Field({ nullable: false, defaultValue: false })
  isCompact: boolean;

  @Field(() => ViewOpenRecordIn, {
    nullable: false,
    defaultValue: ViewOpenRecordIn.SIDE_PANEL,
    deprecationReason: VIEW_OPEN_RECORD_IN_DEPRECATION,
  })
  openRecordIn: ViewOpenRecordIn;

  @Field(() => AggregateOperations, { nullable: true })
  kanbanAggregateOperation?: AggregateOperations | null;

  @Field(() => UUIDScalarType, { nullable: true })
  kanbanAggregateOperationFieldMetadataId?: string | null;

  @Field(() => UUIDScalarType, { nullable: true })
  mainGroupByFieldMetadataId?: string | null;

  @Field({ nullable: false, defaultValue: false })
  shouldHideEmptyGroups: boolean;

  @Field(() => Int, { nullable: true })
  kanbanColumnWidth?: number | null;

  // Nullable since cached views can predate the column and Int! fails the query
  @Field(() => Int, { nullable: true })
  groupLoadLimit?: number | null;

  @Field(() => UUIDScalarType, { nullable: true })
  calendarFieldMetadataId?: string | null;

  @Field(() => UUIDScalarType, { nullable: true })
  calendarEndFieldMetadataId?: string | null;

  @Field(() => UUIDScalarType, { nullable: false })
  workspaceId: string;

  @Field(() => String, { nullable: true })
  anyFieldFilterValue?: string | null;

  @Field(() => ViewCalendarLayout, { nullable: true })
  calendarLayout: ViewCalendarLayout | null;

  @Field()
  createdAt: Date;

  @Field()
  updatedAt: Date;

  @Field(() => Date, { nullable: true })
  deletedAt?: Date | null;

  @Field(() => [ViewFieldDTO])
  viewFields?: ViewFieldDTO[];

  @Field(() => [ViewFilterDTO])
  viewFilters?: ViewFilterDTO[];

  @Field(() => [ViewFilterGroupDTO])
  viewFilterGroups?: ViewFilterGroupDTO[];

  @Field(() => [ViewSortDTO])
  viewSorts?: ViewSortDTO[];

  @Field(() => [ViewGroupDTO])
  viewGroups?: ViewGroupDTO[];

  @Field(() => [ViewFieldGroupDTO])
  viewFieldGroups?: ViewFieldGroupDTO[];

  @Field(() => ViewVisibility, {
    nullable: false,
  })
  visibility: ViewVisibility;

  @Field(() => UUIDScalarType, { nullable: true })
  createdByUserWorkspaceId?: string | null;

  @Field(() => Boolean, { nullable: false })
  isActive: boolean;

  @HideField()
  overrides?: AuthoredOverrides<ViewOverrides> | null;
}