cleanup
This commit is contained in:
@@ -124,6 +124,7 @@ function extractOptions(
|
|||||||
|
|
||||||
if (field.enumOption?.value) return resolveTemplate(field.enumOption.value, item);
|
if (field.enumOption?.value) return resolveTemplate(field.enumOption.value, item);
|
||||||
|
|
||||||
|
if (fieldName == 'payee') debugger;
|
||||||
const df = field.displayField;
|
const df = field.displayField;
|
||||||
if (!df) return null;
|
if (!df) return null;
|
||||||
|
|
||||||
@@ -294,7 +295,7 @@ export default function FilterBar({
|
|||||||
const field = fields[fieldName];
|
const field = fields[fieldName];
|
||||||
if (!field) return null;
|
if (!field) return null;
|
||||||
|
|
||||||
const needsOptions = !field.filterType || field.filterType === "autocomplete" || field.filterType === "multiselect";
|
const needsOptions = field.filterType === "autocomplete" || field.filterType === "multiselect";
|
||||||
const options = needsOptions ? extractOptions(fieldName, field, data ?? []) : [];
|
const options = needsOptions ? extractOptions(fieldName, field, data ?? []) : [];
|
||||||
const raw = draft[fieldName];
|
const raw = draft[fieldName];
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export default function ResourceView({ config, onNavigateToResource, fieldCompon
|
|||||||
const { useList, useRead, useCreate, useUpdate, useDelete, components } = useResource(config, { fieldComponents });
|
const { useList, useRead, useCreate, useUpdate, useDelete, components } = useResource(config, { fieldComponents });
|
||||||
|
|
||||||
const queryParams = React.useMemo(() => {
|
const queryParams = React.useMemo(() => {
|
||||||
if (!isServer) return { limit: 10000 };
|
if (!isServer) return { limit: 10 };
|
||||||
return {
|
return {
|
||||||
skip: paginationModel.page * paginationModel.pageSize,
|
skip: paginationModel.page * paginationModel.pageSize,
|
||||||
limit: paginationModel.pageSize,
|
limit: paginationModel.pageSize,
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ function parseSchemaFields(
|
|||||||
const fields: Record<string, ResourceField> = {};
|
const fields: Record<string, ResourceField> = {};
|
||||||
const { properties, required } = mergeProperties(schema);
|
const { properties, required } = mergeProperties(schema);
|
||||||
const overrides = configuration[resourceName]?.fields || {};
|
const overrides = configuration[resourceName]?.fields || {};
|
||||||
|
console.log('inside parseSchemaFields configuration...', configuration['accounts']['referenceOptions'])
|
||||||
|
|
||||||
for (const [key, prop] of Object.entries(properties) as [string, any]) {
|
for (const [key, prop] of Object.entries(properties) as [string, any]) {
|
||||||
// Resolve oneOf/anyOf by merging all branch properties
|
// Resolve oneOf/anyOf by merging all branch properties
|
||||||
@@ -114,24 +115,25 @@ function parseSchemaFields(
|
|||||||
if (relation) {
|
if (relation) {
|
||||||
fields[key].relation = relation;
|
fields[key].relation = relation;
|
||||||
|
|
||||||
// Propagate enumOption from target resource config, or derive from target schema
|
// Propagate enumOption from target resource config, or derive from target schema
|
||||||
const explicitEnumOption = configuration[relation]?.enumOption;
|
const explicitEnumOption = configuration[relation].referenceOptions.enumOption;
|
||||||
if (explicitEnumOption) {
|
console.log('if relation configuration...', configuration['accounts']['referenceOptions'])
|
||||||
fields[key].enumOption = explicitEnumOption;
|
if (explicitEnumOption) {
|
||||||
} else {
|
fields[key].enumOption = explicitEnumOption;
|
||||||
const targetProps = targetSchema.properties || {};
|
} else {
|
||||||
const valueField = Object.entries(targetProps).find(
|
// No explicit enumOption supplied – this is a configuration error.
|
||||||
([name, p]: [string, any]) => name !== 'id' && p.type === 'string'
|
// We abort loading so the problem is visible immediately.
|
||||||
)?.[0];
|
throw new Error(
|
||||||
fields[key].enumOption = {
|
`Missing enumOption for relation "${relation}" on field "${key}". ` +
|
||||||
key: 'id',
|
`Define referenceOptions.enumOption in the configuration for resource "${relation}".`
|
||||||
value: valueField ?? 'id',
|
);
|
||||||
};
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively parse nested objects (only if not a relation)
|
// Recursively parse nested objects (only if not a relation)
|
||||||
if (fields[key].type === "object" && resolvedProp.properties && !relation) {
|
if (fields[key].type === "object" && resolvedProp.properties && !relation) {
|
||||||
|
console.log('recursive configuration...', configuration['accounts']['referenceOptions'])
|
||||||
fields[key].schema = parseSchemaFields(resolvedProp, resourceName, schemaToResourceMap, configuration);
|
fields[key].schema = parseSchemaFields(resolvedProp, resourceName, schemaToResourceMap, configuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,6 +145,7 @@ function parseSchemaFields(
|
|||||||
* Scans paths to identify resources and their basic configuration
|
* Scans paths to identify resources and their basic configuration
|
||||||
*/
|
*/
|
||||||
export async function loadConfigFromOpenApi(baseUrl: string, configuration: Record<string, any> = {}, profileConfiguration: any = {}): Promise<AppConfig> {
|
export async function loadConfigFromOpenApi(baseUrl: string, configuration: Record<string, any> = {}, profileConfiguration: any = {}): Promise<AppConfig> {
|
||||||
|
console.log('init configuration...', configuration['accounts']['referenceOptions'])
|
||||||
// Use SwaggerParser to dereference the spec.
|
// Use SwaggerParser to dereference the spec.
|
||||||
// Dereferencing preserves object identity for $ref targets.
|
// Dereferencing preserves object identity for $ref targets.
|
||||||
const api = await SwaggerParser.dereference(
|
const api = await SwaggerParser.dereference(
|
||||||
@@ -198,6 +201,7 @@ export async function loadConfigFromOpenApi(baseUrl: string, configuration: Reco
|
|||||||
const label = name.charAt(0).toUpperCase() + name.slice(1, -1);
|
const label = name.charAt(0).toUpperCase() + name.slice(1, -1);
|
||||||
const pluralLabel = name.charAt(0).toUpperCase() + name.slice(1);
|
const pluralLabel = name.charAt(0).toUpperCase() + name.slice(1);
|
||||||
|
|
||||||
|
console.log('before parseSchemaFields configuration...', configuration['accounts']['referenceOptions'])
|
||||||
const fields = parseSchemaFields(schema, name, schemaToResourceMap, configuration);
|
const fields = parseSchemaFields(schema, name, schemaToResourceMap, configuration);
|
||||||
|
|
||||||
const resourceOverride = configuration[name] || {};
|
const resourceOverride = configuration[name] || {};
|
||||||
|
|||||||
@@ -17,7 +17,13 @@ export function getFieldOptions(field: ResourceField, relationData?: any[]): Sel
|
|||||||
|
|
||||||
if (field.relation) {
|
if (field.relation) {
|
||||||
const data = relationData ?? [];
|
const data = relationData ?? [];
|
||||||
const enumOption = field.enumOption ?? { key: 'id', value: 'name' };
|
const enumOption = field.enumOption;
|
||||||
|
if (!enumOption) {
|
||||||
|
throw new Error(
|
||||||
|
`Missing enumOption for relation "${field.relation}" on field "${field}". ` +
|
||||||
|
`Define referenceOptions.enumOption in the configuration for resource "${field.relation}".`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return data.map(item => ({
|
return data.map(item => ({
|
||||||
key: String(item[enumOption.key] ?? ''),
|
key: String(item[enumOption.key] ?? ''),
|
||||||
|
|||||||
Reference in New Issue
Block a user