### Summary of Changes:
1. **Spec-Driven Enums**:
- Updated `openapi_loader.ts` to collect all standalone enum schemas (e.g., `FetchRequestStatus`) into the `AppConfig.enums` map.
- Implemented `mergeProperties` and `oneOf`/`anyOf` resolution in `openapi_loader.ts` to ensure complex schemas like `FetchRequest` (using `allOf`) and `source` (using `oneOf`) are correctly parsed.
2. **Customizable Labeling**:
- Added `enumOption` (template-based) and `enumLabels` (mapping-based) to the config and field types.
- Implemented `resolveTemplate` in `utils/options.ts` to handle placeholders like `'{name} {number}'` or plain field names.
3. **UI Integration**:
- **`FormField.tsx`**: Updated relation and enum selects to use `getFieldOptions()` for correct key/value pairs and labels. Added value normalization to extract keys from API objects.
- **`EnhancedTable.tsx`**: Updated `valueOptions` to use key/value pairs for `singleSelect` and updated `FieldRenderer` to show the human-readable label for enums.
- **`FilterBar.tsx`**: Updated `extractOptions` to use spec-driven labels for enum filters.
- **`ResourceView.tsx`**: Centralized filter matching logic into a `getDisplayString` helper, ensuring filter comparisons use the same templates as the UI labels.
4. **App Fixes**:
- `FetchRequests.tsx` and `FetchRequestDetail.tsx` now derive status and format options from the OpenAPI spec via `useConfig()` instead of using hardcoded arrays.
Reviewed-on: #10
Co-authored-by: Vishesh 'ironeagle' Bangotra <aetoskia@gmail.com>
Co-committed-by: Vishesh 'ironeagle' Bangotra <aetoskia@gmail.com>
66 lines
1.3 KiB
TypeScript
66 lines
1.3 KiB
TypeScript
export type FieldType =
|
|
| 'string'
|
|
| 'number'
|
|
| 'boolean'
|
|
| 'date'
|
|
| 'datetime'
|
|
| 'markdown'
|
|
| 'enum'
|
|
| 'image'
|
|
| 'object'
|
|
| 'array';
|
|
|
|
export interface SelectOption {
|
|
key: string;
|
|
value: string;
|
|
}
|
|
|
|
export interface EnumOption {
|
|
key: string;
|
|
value: string;
|
|
}
|
|
|
|
export interface ResourceField {
|
|
type: FieldType;
|
|
label: string;
|
|
required?: boolean;
|
|
options?: string[];
|
|
readOnly?: boolean;
|
|
schema?: Record<string, ResourceField>;
|
|
displayField?: string | string[];
|
|
formatter?: (value: any) => string;
|
|
relation?: string;
|
|
filterType?: "autocomplete" | "multiselect" | "number-range" | "date-range";
|
|
enumOption?: EnumOption;
|
|
enumLabels?: Record<string, string>;
|
|
}
|
|
|
|
export type ResourceMode = "server" | "client";
|
|
|
|
export interface ResourceConfig {
|
|
name: string;
|
|
label: string;
|
|
pluralLabel: string;
|
|
endpoint: string;
|
|
primaryKey: string;
|
|
fields: Record<string, ResourceField>;
|
|
pagination?: boolean;
|
|
hidden?: boolean;
|
|
filterOptions?: {
|
|
mode?: ResourceMode;
|
|
fields?: string[];
|
|
};
|
|
enumOption?: EnumOption;
|
|
}
|
|
|
|
export interface AppConfig {
|
|
baseUrl: string;
|
|
authBaseUrl: string;
|
|
resources: ResourceConfig[];
|
|
enums: Record<string, string[]>;
|
|
profile?: {
|
|
resource: string;
|
|
extraFields?: Record<string, any>;
|
|
};
|
|
}
|