import { ArrayColumnType } from './columns'; import { ColumnType } from './graphql-global-types'; export interface IReference { id: string; visibleName?: string | null; } export interface ISubTable { id: string; visibleName?: string | null; } export interface IAttachment { fileId: string; fileName: string; fileType: string; fileKey: string; fileSize: number; largeThumbUrl: string; mediumThumbUrl: string; smallThumbUrl: string; url: string; } type StatusId = string; type OptionId = string; type OptionIdArray = string[]; type GroupIdArray = string[]; export type AbsentCellValue = null | undefined; type CellValueWithoutLookup = T extends | ColumnType.TEXT | ColumnType.PHONE | ColumnType.EMAIL | ColumnType.UNIQUE_ID | ColumnType.DATETIME | ColumnType.LONG_TEXT | ColumnType.ROLLUP | ColumnType.CREATED_AT | ColumnType.CREATED_BY ? string : T extends ColumnType.FORMULA ? string | number : T extends ColumnType.SELECT ? OptionId : T extends ColumnType.STATUS ? StatusId : T extends | ColumnType.NUMBER | ColumnType.CURRENCY | ColumnType.RATING | ColumnType.AUTO_NUMBER ? number : T extends ColumnType.CHECKBOX ? boolean : T extends ColumnType.COLLABORATOR ? GroupIdArray : T extends ColumnType.MULTI_SELECT ? OptionIdArray : T extends ColumnType.MULTI_ATTACHMENT ? IAttachment[] : T extends ColumnType.RECORD_REFERENCE ? IReference[] : T extends ColumnType.SUBTABLE ? ISubTable[] : never; /** * This is the type of the lookup cell value representation which we receive * from the backend and store in mobx. It looks like this: * * = string[] | number[] | ... * * unfortunately a union of array types isn't a valid target for array methods * in typescript so you can't do: * * (foo as LookupCellValueUnion).map(...); */ type LookupCellValueUnion = { [Property in T]: CellValueWithoutLookup extends any[] ? CellValueWithoutLookup : CellValueWithoutLookup[]; }[T]; /** * This is an alternative to the type of the lookup cell value representation which we receive * from the backend and store in mobx. It looks like this: * * = (string | number | ...)[] * * and therefore, is a valid target for array methods such as Array.prototype.map() */ export type LookupCellValue = LookupCellValueUnion extends (infer U)[] ? U[] : never; export type CellValue = T extends ColumnType.LOOKUP ? LookupCellValue : CellValueWithoutLookup; export type ArrayTypeCellValue = CellValue; export type MaybeAbsentCellValue = | CellValue | AbsentCellValue; export interface ICellData { [columnId: string]: MaybeAbsentCellValue; }