fix:workflow lookup not loading options resolved
This commit is contained in:
parent
eea74e3626
commit
686f5e8acd
16
src/App.tsx
16
src/App.tsx
@ -14,17 +14,17 @@ function App() {
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/login" element={<LoginPage />} />
|
<Route path="/login" element={<LoginPage />} />
|
||||||
<Route element={<ConsoleLayout />}>
|
<Route element={<ConsoleLayout />}>
|
||||||
<Route path="orders" element={<OrdersPage />} />
|
<Route path="/orders" element={<OrdersPage />} />
|
||||||
<Route path="orders/:instanceId" element={<OrdersPage />} />
|
<Route path="/orders/:instanceId" element={<OrdersPage />} />
|
||||||
|
|
||||||
<Route path="calls" element={<CallsPage />} />
|
<Route path="/calls" element={<CallsPage />} />
|
||||||
<Route path="calls/:instanceId" element={<CallsPage />} />
|
<Route path="/calls/:instanceId" element={<CallsPage />} />
|
||||||
|
|
||||||
<Route path="stores" element={<StoresPage />} />
|
<Route path="/stores" element={<StoresPage />} />
|
||||||
<Route path="stores/:instanceId" element={<StoresPage />} />
|
<Route path="/stores/:instanceId" element={<StoresPage />} />
|
||||||
|
|
||||||
<Route path="daily" element={<DailyLogsPage />} />
|
<Route path="/daily" element={<DailyLogsPage />} />
|
||||||
<Route path="daily/:instanceId" element={<DailyLogsPage />} />
|
<Route path="/daily/:instanceId" element={<DailyLogsPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
|
|||||||
@ -73,6 +73,7 @@ export interface FormScreenFieldProps {
|
|||||||
display_columns?: Array<{ name: string }>;
|
display_columns?: Array<{ name: string }>;
|
||||||
storage_columns?: Array<{ name: string }>;
|
storage_columns?: Array<{ name: string }>;
|
||||||
};
|
};
|
||||||
|
wf_lookup_config?: any;
|
||||||
ocr_config?: {
|
ocr_config?: {
|
||||||
template?: string;
|
template?: string;
|
||||||
field_mappings?: Array<{ target_field: string; extraction_key: string }>;
|
field_mappings?: Array<{ target_field: string; extraction_key: string }>;
|
||||||
|
|||||||
@ -213,7 +213,8 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
required={f.mandatory}
|
required={f.mandatory}
|
||||||
value={(val as string | number) ?? ''}
|
value={(val as string | number) ?? ''}
|
||||||
client={client}
|
client={client}
|
||||||
config={f.properties?.lookup_config}
|
config={f.properties?.wf_lookup_config || f.properties?.lookup_config}
|
||||||
|
properties={f.properties}
|
||||||
activityId={currentActivityId}
|
activityId={currentActivityId}
|
||||||
fieldId={f.id}
|
fieldId={f.id}
|
||||||
formData={values}
|
formData={values}
|
||||||
|
|||||||
@ -9,28 +9,27 @@ export interface WfLookupFieldProps {
|
|||||||
onChange: (val: string) => void;
|
onChange: (val: string) => void;
|
||||||
client: ZinoClient;
|
client: ZinoClient;
|
||||||
config: any; // wf_lookup_config
|
config: any; // wf_lookup_config
|
||||||
|
properties?: any; // parent field properties
|
||||||
activityId: string;
|
activityId: string;
|
||||||
fieldId: string;
|
fieldId: string;
|
||||||
formData: Record<string, unknown>;
|
formData: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WfLookupField({ label, required, value, onChange, client, config, activityId, fieldId, formData }: WfLookupFieldProps) {
|
export function WfLookupField({ label, required, value, onChange, client, config, properties, activityId, fieldId, formData }: WfLookupFieldProps) {
|
||||||
const [options, setOptions] = useState<{ label: string; value: string }[]>([]);
|
const [options, setOptions] = useState<{ label: string; value: string }[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
const formDataStr = JSON.stringify(formData);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let mounted = true;
|
let mounted = true;
|
||||||
const wfUuid = config?.workflow_uuid;
|
|
||||||
if (!wfUuid) {
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
const timer = setTimeout(() => {
|
||||||
client.wfLookupRecords({
|
client.wfLookupRecords({
|
||||||
activityId,
|
activityId,
|
||||||
fieldId,
|
fieldId,
|
||||||
formData,
|
formData: JSON.parse(formDataStr),
|
||||||
limit: 200
|
limit: 200
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
@ -38,7 +37,7 @@ export function WfLookupField({ label, required, value, onChange, client, config
|
|||||||
// The API might return { data: [...] } or { records: [...] } or just an array
|
// The API might return { data: [...] } or { records: [...] } or just an array
|
||||||
const arr = Array.isArray(res) ? res : (res.data || res.records || []);
|
const arr = Array.isArray(res) ? res : (res.data || res.records || []);
|
||||||
|
|
||||||
const displayFields = config.display_fields || [];
|
const displayFields = config?.display_fields || [];
|
||||||
|
|
||||||
const opts = arr.map((row: any) => {
|
const opts = arr.map((row: any) => {
|
||||||
// Join the display fields to form the label
|
// Join the display fields to form the label
|
||||||
@ -47,7 +46,7 @@ export function WfLookupField({ label, required, value, onChange, client, config
|
|||||||
.filter((v: any) => v != null && v !== '');
|
.filter((v: any) => v != null && v !== '');
|
||||||
|
|
||||||
const labelText = labelParts.length > 0
|
const labelText = labelParts.length > 0
|
||||||
? labelParts.join(' - ')
|
? labelParts.join(', ')
|
||||||
: `ID: ${row.instance_id || row.id}`;
|
: `ID: ${row.instance_id || row.id}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -64,9 +63,13 @@ export function WfLookupField({ label, required, value, onChange, client, config
|
|||||||
.finally(() => {
|
.finally(() => {
|
||||||
if (mounted) setLoading(false);
|
if (mounted) setLoading(false);
|
||||||
});
|
});
|
||||||
|
}, 300);
|
||||||
|
|
||||||
return () => { mounted = false; };
|
return () => {
|
||||||
}, [client, config]);
|
mounted = false;
|
||||||
|
clearTimeout(timer);
|
||||||
|
};
|
||||||
|
}, [client, config, activityId, fieldId, formDataStr]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SelectField
|
<SelectField
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user