Files
khata-ui/react-openapi/src/types.ts
Vishesh 'ironeagle' Bangotra e8faafae7d feat(reports): render generate-report form from OpenAPI spec
Replace hand-written GenerateReportPanel inputs with a generic loop over
extractFields("ReportQuery") + FormFieldRenderer; submit via
useResource("reports").create with server-side validation only.

react-openapi additions (all additive):
- lift items.enum into FieldConfig.enumValues for array-of-enum props
- extract schema `default` into FieldConfig.defaultValue
- new MultiEnumField renderer dispatched for isArray && enumValues
- FKFieldConfig.value: bind option values to a target property instead
  of the primary key (account names); sanitize-payload skips resolveFk
  when set
- new useFkFieldOptions hook encapsulating FK option loading/prefetch
- export extractFields, useFkFieldOptions, MultiEnumField

Drop now-unused granularityOptions/groupDimOptions helpers.
2026-08-21 15:45:23 +05:30

142 lines
3.1 KiB
TypeScript

export type FilterMode = "client" | "server";
export interface ResourceConfiguration {
filterOptions?: {
mode?: FilterMode;
};
/** Map of field name → uiType override (e.g. { amount: "currency" }). */
fieldTypes?: Record<string, string>;
}
export interface ProfileComponents {
create?: React.ComponentType<any>;
edit?: React.ComponentType<any>;
view?: React.ComponentType<any>;
}
export interface SpecConfiguration {
specUrl: string;
baseApiUrl?: string;
title?: string;
getToken?: () => string | null;
resourceConfig?: Record<string, ResourceConfiguration>;
profileComponents?: ProfileComponents;
}
/** Auth server config extracted from securitySchemes extensions. */
export interface AuthConfig {
serverUrl: string;
loginPath: string;
registerPath: string;
logoutPath: string;
mePath: string;
introspectPath: string;
}
/** Represents a single operation marked with `x-profile: true` in the spec. */
export interface ProfileOperation {
path: string;
method: string;
operationId: string;
summary?: string;
}
export interface ValidationMessage {
type: "error" | "warning" | "info";
message: string;
}
export interface ResourceRelationship {
fieldName: string;
config: FKFieldConfig;
targetSchemaName: string;
}
export interface ResourceConfig {
name: string;
schemaName: string;
displayName: string;
path: string;
primaryKey: string;
displayFormat: string;
listColumns: string[];
fields: FieldConfig[];
orderedFields: FieldConfig[];
operations: {
list: boolean;
get: boolean;
create: boolean;
update: boolean;
patch: boolean;
delete: boolean;
};
updateMethod: "put" | "patch";
pagination: {
limitParam: string;
offsetParam: string;
defaultLimit: number;
} | null;
relationships: ResourceRelationship[];
streaming?: boolean;
parent?: { resource: string; pathParam: string };
subResources?: string[];
}
export interface FKFieldConfig {
resource: string;
prefetch: boolean;
/** Target property used as the wire value (defaults to the target's primary key). */
value?: string;
}
export interface OneOfOption {
value: string;
label: string;
fields: FieldConfig[];
}
export interface FieldConfig {
name: string;
label: string;
description: string;
type: string;
format?: string;
order: number;
hidden: { form?: boolean; list?: boolean; detail?: boolean };
filterable: boolean;
sortable: boolean;
readOnly: boolean;
required: boolean;
enumValues?: string[];
/** Schema-level `default` used to seed create-form state. */
defaultValue?: any;
fk?: FKFieldConfig;
uiType?: string;
uploadUrl?: string;
upload?: { type: string; url: string };
refSchema?: string;
inlineDisplayFormat?: string;
isArray: boolean;
oneOfOptions?: OneOfOption[];
discriminatorProperty?: string;
autocomplete?: "text" | "token" | "email" | "phone";
}
export interface OpenApiSpec {
openapi: string;
info: {
title: string;
version: string;
};
servers?: { url: string }[];
components?: {
schemas?: Record<string, any>;
};
paths?: Record<string, any>;
}
export interface ParsedListResponse {
total?: number;
items?: any[];
}