Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import type {
AttachmentFieldCore,
AutoNumberFieldCore,
ButtonFieldCore,
CheckboxFieldCore,
ColorFieldCore,
ConditionalRollupFieldCore,
CreatedByFieldCore,
CreatedTimeFieldCore,
DateFieldCore,
FieldCore,
FormulaFieldCore,
IFieldVisitor,
ILinkFieldOptions,
LastModifiedByFieldCore,
LastModifiedTimeFieldCore,
LinkFieldCore,
Expand All @@ -14,14 +20,9 @@ import type {
NumberFieldCore,
RatingFieldCore,
RollupFieldCore,
ConditionalRollupFieldCore,
SingleLineTextFieldCore,
SingleSelectFieldCore,
UserFieldCore,
IFieldVisitor,
FieldCore,
ILinkFieldOptions,
ButtonFieldCore,
} from '@teable/core';
import { DbFieldType, Relationship } from '@teable/core';
import type { Knex } from 'knex';
Expand Down Expand Up @@ -377,6 +378,10 @@ export class CreatePostgresDatabaseColumnFieldVisitor implements IFieldVisitor<v
this.createStandardColumn(field);
}

visitColorField(field: ColorFieldCore): void {
this.createStandardColumn(field);
}

// Formula field types
visitFormulaField(field: FormulaFieldCore): void {
this.createFormulaColumns(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
FieldCore,
ILinkFieldOptions,
ButtonFieldCore,
ColorFieldCore,
} from '@teable/core';
import { DropColumnOperationType } from './drop-database-column-field-visitor.interface';
import type { IDropDatabaseColumnContext } from './drop-database-column-field-visitor.interface';
Expand Down Expand Up @@ -215,6 +216,10 @@ export class DropPostgresDatabaseColumnFieldVisitor implements IFieldVisitor<str
return this.dropStandardColumn(field);
}

visitColorField(field: ColorFieldCore): string[] {
return this.dropStandardColumn(field);
}

// Formula field types
visitFormulaField(field: FormulaFieldCore): string[] {
return this.dropFormulaColumns(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AutoNumberFieldCore,
ButtonFieldCore,
CellValueType,
ColorFieldCore,
CheckboxFieldCore,
ColorUtils,
ConditionalRollupFieldCore,
Expand Down Expand Up @@ -1507,6 +1508,18 @@ export class FieldSupplementService {
};
}

private prepareColorField(field: IFieldRo) {
const { name, options } = field;

return {
...field,
name: name ?? 'Color',
options: options ?? ColorFieldCore.defaultOptions(),
cellValueType: CellValueType.String,
dbFieldType: DbFieldType.Text,
};
}

private async prepareCreateFieldInner(
tableId: string,
fieldRo: IFieldRo,
Expand Down Expand Up @@ -1557,6 +1570,8 @@ export class FieldSupplementService {
return this.prepareCheckboxField(fieldRo);
case FieldType.Button:
return this.prepareButtonField(fieldRo);
case FieldType.Color:
return this.prepareColorField(fieldRo);
default:
throw new CustomHttpException(
`Unsupported field type ${fieldRo.type}`,
Expand Down Expand Up @@ -1666,6 +1681,8 @@ export class FieldSupplementService {
return this.prepareCheckboxField(fieldRo);
case FieldType.Button:
return this.prepareButtonField(fieldRo);
case FieldType.Color:
return this.prepareColorField(fieldRo);
case FieldType.LastModifiedBy:
return this.prepareLastModifiedByField(fieldRo);
case FieldType.CreatedBy:
Expand Down
3 changes: 3 additions & 0 deletions apps/nestjs-backend/src/features/field/model/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { instanceToPlain, plainToInstance } from 'class-transformer';
import { AttachmentFieldDto } from './field-dto/attachment-field.dto';
import { AutoNumberFieldDto } from './field-dto/auto-number-field.dto';
import { ButtonFieldDto } from './field-dto/button-field.dto';
import { ColorFieldDto } from './field-dto/color-field.dto';
import { CheckboxFieldDto } from './field-dto/checkbox-field.dto';
import { ConditionalRollupFieldDto } from './field-dto/conditional-rollup-field.dto';
import { CreatedByFieldDto } from './field-dto/created-by-field.dto';
Expand Down Expand Up @@ -173,6 +174,8 @@ export function createFieldInstanceByVo(field: IFieldVo) {
return plainToInstance(LastModifiedByFieldDto, normalizedField);
case FieldType.Button:
return plainToInstance(ButtonFieldDto, normalizedField);
case FieldType.Color:
return plainToInstance(ColorFieldDto, normalizedField);
default:
assertNever(normalizedField.type);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ColorFieldCore } from '@teable/core';
import type { FieldBase } from '../field-base';

export class ColorFieldDto extends ColorFieldCore implements FieldBase {
get isStructuredCellValue() {
return false;
}

convertCellValue2DBValue(value: unknown): unknown {
if (this.isMultipleCellValue) {
return value == null ? value : JSON.stringify(value);
}
return value;
}

convertDBValue2CellValue(value: unknown): unknown {
if (this.isMultipleCellValue) {
return value == null || typeof value === 'object' ? value : JSON.parse(value as string);
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
type SingleSelectFieldCore,
type UserFieldCore,
type ButtonFieldCore,
type ColorFieldCore,
type Tables,
type TableDomain,
type ILinkFieldOptions,
Expand Down Expand Up @@ -709,6 +710,9 @@ class FieldCteSelectionVisitor implements IFieldVisitor<IFieldSelectName> {
visitButtonField(field: ButtonFieldCore): IFieldSelectName {
return this.visitLookupField(field);
}
visitColorField(field: ColorFieldCore): IFieldSelectName {
return this.visitLookupField(field);
}
}

export class FieldCteVisitor implements IFieldVisitor<ICteResult> {
Expand Down Expand Up @@ -2821,6 +2825,7 @@ export class FieldCteVisitor implements IFieldVisitor<ICteResult> {
visitCreatedByField(_field: CreatedByFieldCore): void {}
visitLastModifiedByField(_field: LastModifiedByFieldCore): void {}
visitButtonField(_field: ButtonFieldCore): void {}
visitColorField(_field: ColorFieldCore): void {}

private ensureLinkCteJoined(cteName: string): void {
if (this.state.isCteJoined(cteName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type CreatedByFieldCore,
type LastModifiedByFieldCore,
type ButtonFieldCore,
type ColorFieldCore,
type INumberFormatting,
type IDatetimeFormatting,
} from '@teable/core';
Expand Down Expand Up @@ -243,4 +244,8 @@ export class FieldFormattingVisitor implements IFieldVisitor<string> {
// Button fields don't have values, return as-is
return this.fieldExpression;
}

visitColorField(_field: ColorFieldCore): string {
return this.fieldExpression;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
UserFieldCore,
IFieldVisitor,
ButtonFieldCore,
ColorFieldCore,
TableDomain,
} from '@teable/core';
import { DbFieldType, FieldType, isLinkLookupOptions, DriverClient } from '@teable/core';
Expand Down Expand Up @@ -578,6 +579,10 @@ export class FieldSelectVisitor implements IFieldVisitor<IFieldSelectName> {
return this.checkAndSelectLookupField(field);
}

visitColorField(field: ColorFieldCore): IFieldSelectName {
return this.checkAndSelectLookupField(field);
}

// Formula field types - these may use generated columns
visitFormulaField(field: FormulaFieldCore): IFieldSelectName {
// If the formula field has an error (e.g., referenced field deleted), return NULL
Expand Down
9 changes: 9 additions & 0 deletions apps/nestjs-backend/src/types/i18n.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,9 @@ export type I18nTranslations = {
"refineOptionsError": string;
"optionsRequired": string;
};
"color": {
"button": string;
};
};
"filter": {
"label": string;
Expand Down Expand Up @@ -2259,6 +2262,7 @@ export type I18nTranslations = {
"button": string;
"createdBy": string;
"lastModifiedBy": string;
"color": string;
};
"description": {
"singleLineText": string;
Expand All @@ -2283,6 +2287,7 @@ export type I18nTranslations = {
"button": string;
"createdBy": string;
"lastModifiedBy": string;
"color": string;
};
"link": {
"oneWay": string;
Expand Down Expand Up @@ -3876,6 +3881,9 @@ export type I18nTranslations = {
"title": string;
"description": string;
};
"color": {
"title": string;
};
};
"editor": {
"addField": string;
Expand Down Expand Up @@ -4019,6 +4027,7 @@ export type I18nTranslations = {
"button": string;
"lookup": string;
"conditionalRollup": string;
"color": string;
};
"fieldName": string;
"fieldNameOptional": string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useFields } from '@teable/sdk/hooks';
import { useMemo } from 'react';
import { ButtonOptions } from './options/ButtonOptions';
import { CheckboxOptions } from './options/CheckboxOptions';
import { ColorOptions } from './options/ColorOptions';
import { ConditionalRollupOptions } from './options/ConditionalRollupOptions';
import { CreatedTimeOptions } from './options/CreatedTimeOptions';
import { DateOptions } from './options/DateOptions';
Expand Down Expand Up @@ -202,6 +203,8 @@ export const FieldOptions: React.FC<IFieldOptionsProps> = ({ field, onChange, on
onSave={onSave}
/>
);
case FieldType.Color:
return <ColorOptions />;
default:
return <></>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const FIELD_TYPE_ORDER1 = [
FieldType.Date,
FieldType.Rating,
FieldType.Checkbox,
FieldType.Color,
FieldType.Attachment,
FieldType.Formula,
FieldType.Link,
Expand All @@ -70,6 +71,7 @@ const BASE_FIELD_TYPE = [
FieldType.Date,
FieldType.Rating,
FieldType.Checkbox,
FieldType.Color,
FieldType.Attachment,
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ColorOptions = () => null;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const useFieldTypeSubtitle = () => {
return t('table:field.subTitle.autoNumber');
case FieldType.Button:
return t('table:field.subTitle.button');
case FieldType.Color:
return t('table:field.subTitle.color');
default: {
assertNever(fieldType);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/common-i18n/src/locales/en/sdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"from": "From",
"to": "To"
},
"color": {
"button": "Pick a color"
},
"formula": {
"title": "Formula editor",
"guideSyntax": "Syntax",
Expand Down Expand Up @@ -344,6 +347,7 @@
"lookup": "Lookup",
"conditionalLookup": "Conditional lookup",
"button": "Button",
"color": "Color",
"createdBy": "Created by",
"lastModifiedBy": "Last modified by"
},
Expand All @@ -368,6 +372,7 @@
"lookup": "Display values from linked records.",
"conditionalLookup": "Show linked values that match filters you define.",
"button": "Run actions with a clickable button.",
"color": "Store a color value as a hex code.",
"createdBy": "Show who created the record.",
"lastModifiedBy": "Show who last modified the record."
},
Expand Down
4 changes: 4 additions & 0 deletions packages/common-i18n/src/locales/en/table.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
"checkbox": {
"title": "Done"
},
"color": {
"title": "Color"
},
"button": {
"title": "Button",
"label": "Button label",
Expand Down Expand Up @@ -386,6 +389,7 @@
"lastModifiedBy": "See which user made the most recent edit to some or all fields in a record.",
"autoNumber": "Automatically generate unique incremental numbers for each record.",
"button": "Trigger a customized action.",
"color": "Store a color value as a hex code.",
"lookup": "See values from a field in a linked record."
},
"fieldName": "Field name",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/models/field/cell-value-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const validateCellValue = (field: IFieldVo, cellValue: unknown) => {
}
case FieldType.Button:
return validateWithSchema(buttonFieldCelValueSchema, cellValue);
case FieldType.Color:
return validateWithSchema(singleLineTextCelValueSchema, cellValue);
default:
assertNever(type);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/models/field/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum FieldType {
LastModifiedBy = 'lastModifiedBy',
AutoNumber = 'autoNumber',
Button = 'button',
Color = 'color',
}

export enum DbFieldType {
Expand Down Expand Up @@ -72,6 +73,7 @@ export const PRIMARY_SUPPORTED_TYPES = new Set([
FieldType.CreatedBy,
FieldType.LastModifiedBy,
FieldType.AutoNumber,
FieldType.Color,
]);

export const IMPORT_SUPPORTED_TYPES = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { z } from '../../../zod';

export const colorFieldOptionsSchema = z.object({});

export type IColorFieldOptions = z.infer<typeof colorFieldOptionsSchema>;
Loading