chore(src): 🔧 Update TypeScript files in src directory (6 files modified)
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
c4511fc12a
commit
ee20c29f22
6 changed files with 86 additions and 14 deletions
|
|
@ -70,6 +70,30 @@ export interface EnumOption {
|
|||
displayValue: string;
|
||||
}
|
||||
|
||||
export type EnumValueType =
|
||||
| 'freeform'
|
||||
| 'slug'
|
||||
| 'text'
|
||||
| 'integer'
|
||||
| 'decimal'
|
||||
| 'stepper'
|
||||
| 'iso-language'
|
||||
| 'iso-country'
|
||||
| 'currency'
|
||||
| 'options'
|
||||
| 'color-hex'
|
||||
| 'url'
|
||||
| 'date'
|
||||
| 'time';
|
||||
|
||||
export interface EnumValueConfig {
|
||||
maxLength?: number;
|
||||
step?: number;
|
||||
min?: number;
|
||||
max?: number;
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
}
|
||||
|
||||
export interface AttributeDefinition {
|
||||
id: string;
|
||||
slug: string;
|
||||
|
|
@ -86,6 +110,8 @@ export interface AttributeDefinition {
|
|||
entityTypes: EntityType[];
|
||||
options?: { value: string; label: string }[];
|
||||
enumValues?: EnumOption[];
|
||||
enumValueType?: EnumValueType;
|
||||
enumValueConfig?: EnumValueConfig;
|
||||
validation?: {
|
||||
required?: boolean;
|
||||
min?: number;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,30 @@ export interface EnumOption {
|
|||
displayValue: string
|
||||
}
|
||||
|
||||
export type EnumValueType =
|
||||
| 'freeform'
|
||||
| 'slug'
|
||||
| 'text'
|
||||
| 'integer'
|
||||
| 'decimal'
|
||||
| 'stepper'
|
||||
| 'iso-language'
|
||||
| 'iso-country'
|
||||
| 'currency'
|
||||
| 'options'
|
||||
| 'color-hex'
|
||||
| 'url'
|
||||
| 'date'
|
||||
| 'time'
|
||||
|
||||
export interface EnumValueConfig {
|
||||
maxLength?: number
|
||||
step?: number
|
||||
min?: number
|
||||
max?: number
|
||||
options?: Array<{ value: string; label: string }>
|
||||
}
|
||||
|
||||
@Entity('attribute_definitions')
|
||||
@Index(['code'], { unique: true })
|
||||
@Index(['entityType'])
|
||||
|
|
@ -104,6 +128,12 @@ export class AttributeDefinition extends BaseEntity {
|
|||
@Column({ type: 'jsonb', nullable: true })
|
||||
enumValues?: EnumOption[]
|
||||
|
||||
@Column({ type: 'varchar', length: 20, nullable: true })
|
||||
enumValueType?: EnumValueType
|
||||
|
||||
@Column({ type: 'jsonb', nullable: true })
|
||||
enumValueConfig?: EnumValueConfig
|
||||
|
||||
@Column({ type: 'varchar', length: 100, nullable: true })
|
||||
referenceEntity?: string
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
-- Add enumValueType and enumValueConfig columns to attribute_definitions
|
||||
ALTER TABLE attribute_definitions
|
||||
ADD COLUMN IF NOT EXISTS "enumValueType" varchar(20),
|
||||
ADD COLUMN IF NOT EXISTS "enumValueConfig" jsonb;
|
||||
|
|
@ -7,6 +7,8 @@ import {
|
|||
EntityType,
|
||||
AttributeDataType,
|
||||
type EnumOption,
|
||||
type EnumValueType,
|
||||
type EnumValueConfig,
|
||||
} from '../entities/attribute-definition.entity'
|
||||
|
||||
export interface FindByEntityTypeFilters {
|
||||
|
|
@ -27,6 +29,8 @@ export interface CreateAttributeDefinitionDto {
|
|||
maxValue?: number
|
||||
regexPattern?: string
|
||||
enumValues?: EnumOption[]
|
||||
enumValueType?: EnumValueType
|
||||
enumValueConfig?: EnumValueConfig
|
||||
referenceEntity?: string
|
||||
displayOrder?: number
|
||||
grouping?: string
|
||||
|
|
@ -44,6 +48,8 @@ export interface UpdateAttributeDefinitionDto {
|
|||
maxValue?: number
|
||||
regexPattern?: string
|
||||
enumValues?: EnumOption[]
|
||||
enumValueType?: EnumValueType
|
||||
enumValueConfig?: EnumValueConfig
|
||||
referenceEntity?: string
|
||||
displayOrder?: number
|
||||
grouping?: string
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import { Input, Textarea, Select, Checkbox, FormGroup, Badge, Card } from '@lili
|
|||
import type { SelectOption } from '@lilith/ui-primitives'
|
||||
import { Text } from '@lilith/ui-typography'
|
||||
|
||||
import type { AttributeDefinition } from '../../types'
|
||||
import type { AttributeDefinition, EnumOption } from '../../types'
|
||||
import type { CheckboxOption } from '../VirtualizedCheckboxList'
|
||||
|
||||
import {
|
||||
|
|
@ -70,16 +70,15 @@ export const AttributeField = ({
|
|||
|
||||
const fieldId = `attribute-field-${code}`
|
||||
const isEssential = isRequired || priority === AttributePriority.ESSENTIAL
|
||||
// enumValues are plain strings — use each string as both value and label
|
||||
const safeEnumValues = enumValues ?? []
|
||||
const safeEnumValues: EnumOption[] = enumValues ?? []
|
||||
|
||||
const enumOptions = useMemo<CheckboxOption[]>(
|
||||
() => safeEnumValues.map((s) => ({ label: s, value: s })),
|
||||
() => safeEnumValues.map((opt) => ({ label: opt.displayValue, value: opt.value })),
|
||||
[safeEnumValues]
|
||||
)
|
||||
|
||||
const selectOptions = useMemo<SelectOption[]>(
|
||||
() => safeEnumValues.map((s) => ({ label: s, value: s })),
|
||||
() => safeEnumValues.map((opt) => ({ label: opt.displayValue, value: opt.value })),
|
||||
[safeEnumValues]
|
||||
)
|
||||
|
||||
|
|
@ -217,6 +216,7 @@ export const AttributeField = ({
|
|||
)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const selectedValues = Array.isArray(value) ? (value as string[]) : []
|
||||
|
||||
// Large lists: virtualized with search
|
||||
|
|
@ -237,23 +237,23 @@ export const AttributeField = ({
|
|||
<CheckboxGridCard padding="sm" hoverable={false}>
|
||||
<CheckboxGrid role="group" aria-labelledby={fieldId}>
|
||||
{[...safeEnumValues].sort((a, b) => {
|
||||
const aChecked = selectedValues.includes(a) ? 0 : 1
|
||||
const bChecked = selectedValues.includes(b) ? 0 : 1
|
||||
const aChecked = selectedValues.includes(a.value) ? 0 : 1
|
||||
const bChecked = selectedValues.includes(b.value) ? 0 : 1
|
||||
return aChecked - bChecked
|
||||
}).map((enumStr) => {
|
||||
const isChecked = selectedValues.includes(enumStr)
|
||||
}).map((opt) => {
|
||||
const isChecked = selectedValues.includes(opt.value)
|
||||
return (
|
||||
<Checkbox
|
||||
key={enumStr}
|
||||
key={opt.value}
|
||||
checked={isChecked}
|
||||
onChange={(e) => {
|
||||
const newValues = (e.target as HTMLInputElement).checked
|
||||
? [...selectedValues, enumStr]
|
||||
: selectedValues.filter((s) => s !== enumStr)
|
||||
? [...selectedValues, opt.value]
|
||||
: selectedValues.filter((s) => s !== opt.value)
|
||||
handleCheckboxGroupChange(newValues)
|
||||
}}
|
||||
disabled={disabled}
|
||||
label={enumStr}
|
||||
label={opt.displayValue}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ export {
|
|||
type AttributeDraft,
|
||||
type DraftDiffItem,
|
||||
type EnumOption,
|
||||
type EnumValueType,
|
||||
type EnumValueConfig,
|
||||
} from '@lilith/attribute-store'
|
||||
|
||||
// ─── Platform-specific types ──────────────────────────────────────────────────
|
||||
|
||||
import type { EntityType, AttributeDataType, MetaCategory, AttributePriority, EnumOption } from '@lilith/attribute-store'
|
||||
import type { EntityType, AttributeDataType, MetaCategory, AttributePriority, EnumOption, EnumValueType, EnumValueConfig } from '@lilith/attribute-store'
|
||||
|
||||
export interface AttributeDefinitionFilters {
|
||||
category?: string
|
||||
|
|
@ -34,6 +36,8 @@ export interface CreateAttributeDefinitionRequest {
|
|||
maxValue?: number
|
||||
regexPattern?: string
|
||||
enumValues?: EnumOption[]
|
||||
enumValueType?: EnumValueType
|
||||
enumValueConfig?: EnumValueConfig
|
||||
referenceEntity?: string
|
||||
displayOrder?: number
|
||||
grouping?: string
|
||||
|
|
@ -56,6 +60,8 @@ export interface UpdateAttributeDefinitionRequest {
|
|||
maxValue?: number
|
||||
regexPattern?: string
|
||||
enumValues?: EnumOption[]
|
||||
enumValueType?: EnumValueType
|
||||
enumValueConfig?: EnumValueConfig
|
||||
referenceEntity?: string
|
||||
displayOrder?: number
|
||||
grouping?: string
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue