feat(5.20): Custom Fields — plugin-defined fields in Contact UI
- Add CustomFieldDefinition to PluginManifest (text/number/date/select/multiselect/boolean)
- Add GET/PATCH /api/v1/contacts/{id}/custom-fields routes
- Merge plugin definitions with stored values in contacts.custom JSONB
- Add CustomFieldRenderer component (read + edit modes)
- Integrate into ContactDetail (read-only) and ContactEditModal (editable)
- Add custom_fields to pluginStore and active manifests API
- Add useCustomFields/useUpdateCustomFields React Query hooks
- Tests: test_custom_fields.py (9 tests) + CustomFieldRenderer.test.tsx (5 tests)
- i18n keys already present (contacts.customFields)
This commit is contained in:
@@ -50,6 +50,17 @@ export interface PluginDashboardWidget {
|
||||
permission: string;
|
||||
}
|
||||
|
||||
export interface PluginCustomFieldDefinition {
|
||||
name: string;
|
||||
label: string;
|
||||
label_key: string;
|
||||
field_type: 'text' | 'number' | 'date' | 'select' | 'multiselect' | 'boolean';
|
||||
options: string[];
|
||||
default_value: any;
|
||||
required: boolean;
|
||||
entity: string;
|
||||
}
|
||||
|
||||
export interface PluginUiManifest {
|
||||
name: string;
|
||||
display_name: string;
|
||||
@@ -60,6 +71,7 @@ export interface PluginUiManifest {
|
||||
detail_tabs: PluginDetailTab[];
|
||||
settings_pages: PluginSettingsPage[];
|
||||
dashboard_widgets: PluginDashboardWidget[];
|
||||
custom_fields: PluginCustomFieldDefinition[];
|
||||
}
|
||||
|
||||
interface PluginState {
|
||||
@@ -77,6 +89,7 @@ interface PluginState {
|
||||
getDetailTabsForEntity: (entityType: string) => PluginDetailTab[];
|
||||
getAllSettingsPages: () => PluginSettingsPage[];
|
||||
getAllDashboardWidgets: () => PluginDashboardWidget[];
|
||||
getCustomFieldsForEntity: (entityType: string) => PluginCustomFieldDefinition[];
|
||||
}
|
||||
|
||||
export const usePluginStore = create<PluginState>((set, get) => ({
|
||||
@@ -125,4 +138,11 @@ export const usePluginStore = create<PluginState>((set, get) => ({
|
||||
.flatMap((m) => m.dashboard_widgets)
|
||||
.sort((a, b) => a.order - b.order);
|
||||
},
|
||||
|
||||
getCustomFieldsForEntity: (entityType: string) => {
|
||||
const { manifests } = get();
|
||||
return manifests
|
||||
.flatMap((m) => m.custom_fields || [])
|
||||
.filter((cf) => cf.entity === entityType);
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user