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>
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route element={<ConsoleLayout />}>
|
||||
<Route path="orders" element={<OrdersPage />} />
|
||||
<Route path="orders/:instanceId" element={<OrdersPage />} />
|
||||
<Route path="/orders" element={<OrdersPage />} />
|
||||
<Route path="/orders/:instanceId" element={<OrdersPage />} />
|
||||
|
||||
<Route path="calls" element={<CallsPage />} />
|
||||
<Route path="calls/:instanceId" element={<CallsPage />} />
|
||||
<Route path="/calls" element={<CallsPage />} />
|
||||
<Route path="/calls/:instanceId" element={<CallsPage />} />
|
||||
|
||||
<Route path="stores" element={<StoresPage />} />
|
||||
<Route path="stores/:instanceId" element={<StoresPage />} />
|
||||
<Route path="/stores" element={<StoresPage />} />
|
||||
<Route path="/stores/:instanceId" element={<StoresPage />} />
|
||||
|
||||
<Route path="daily" element={<DailyLogsPage />} />
|
||||
<Route path="daily/:instanceId" element={<DailyLogsPage />} />
|
||||
<Route path="/daily" element={<DailyLogsPage />} />
|
||||
<Route path="/daily/:instanceId" element={<DailyLogsPage />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
|
||||
@ -73,6 +73,7 @@ export interface FormScreenFieldProps {
|
||||
display_columns?: Array<{ name: string }>;
|
||||
storage_columns?: Array<{ name: string }>;
|
||||
};
|
||||
wf_lookup_config?: any;
|
||||
ocr_config?: {
|
||||
template?: string;
|
||||
field_mappings?: Array<{ target_field: string; extraction_key: string }>;
|
||||
|
||||
@ -213,7 +213,8 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
required={f.mandatory}
|
||||
value={(val as string | number) ?? ''}
|
||||
client={client}
|
||||
config={f.properties?.lookup_config}
|
||||
config={f.properties?.wf_lookup_config || f.properties?.lookup_config}
|
||||
properties={f.properties}
|
||||
activityId={currentActivityId}
|
||||
fieldId={f.id}
|
||||
formData={values}
|
||||
|
||||
@ -9,64 +9,67 @@ export interface WfLookupFieldProps {
|
||||
onChange: (val: string) => void;
|
||||
client: ZinoClient;
|
||||
config: any; // wf_lookup_config
|
||||
properties?: any; // parent field properties
|
||||
activityId: string;
|
||||
fieldId: string;
|
||||
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 [loading, setLoading] = useState(true);
|
||||
|
||||
const formDataStr = JSON.stringify(formData);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
const wfUuid = config?.workflow_uuid;
|
||||
if (!wfUuid) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
client.wfLookupRecords({
|
||||
activityId,
|
||||
fieldId,
|
||||
formData,
|
||||
limit: 200
|
||||
})
|
||||
.then(res => {
|
||||
if (!mounted) return;
|
||||
// The API might return { data: [...] } or { records: [...] } or just an array
|
||||
const arr = Array.isArray(res) ? res : (res.data || res.records || []);
|
||||
const timer = setTimeout(() => {
|
||||
client.wfLookupRecords({
|
||||
activityId,
|
||||
fieldId,
|
||||
formData: JSON.parse(formDataStr),
|
||||
limit: 200
|
||||
})
|
||||
.then(res => {
|
||||
if (!mounted) return;
|
||||
// The API might return { data: [...] } or { records: [...] } or just an array
|
||||
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) => {
|
||||
// Join the display fields to form the label
|
||||
const labelParts = displayFields
|
||||
.map((df: any) => row[df.field_id])
|
||||
.filter((v: any) => v != null && v !== '');
|
||||
const opts = arr.map((row: any) => {
|
||||
// Join the display fields to form the label
|
||||
const labelParts = displayFields
|
||||
.map((df: any) => row[df.field_id])
|
||||
.filter((v: any) => v != null && v !== '');
|
||||
|
||||
const labelText = labelParts.length > 0
|
||||
? labelParts.join(' - ')
|
||||
: `ID: ${row.instance_id || row.id}`;
|
||||
const labelText = labelParts.length > 0
|
||||
? labelParts.join(', ')
|
||||
: `ID: ${row.instance_id || row.id}`;
|
||||
|
||||
return {
|
||||
value: String(row.instance_id || row.id),
|
||||
label: labelText
|
||||
};
|
||||
return {
|
||||
value: String(row.instance_id || row.id),
|
||||
label: labelText
|
||||
};
|
||||
});
|
||||
|
||||
setOptions(opts);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Failed to load wf_lookup records:", err);
|
||||
})
|
||||
.finally(() => {
|
||||
if (mounted) setLoading(false);
|
||||
});
|
||||
}, 300);
|
||||
|
||||
setOptions(opts);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Failed to load wf_lookup records:", err);
|
||||
})
|
||||
.finally(() => {
|
||||
if (mounted) setLoading(false);
|
||||
});
|
||||
|
||||
return () => { mounted = false; };
|
||||
}, [client, config]);
|
||||
return () => {
|
||||
mounted = false;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [client, config, activityId, fieldId, formDataStr]);
|
||||
|
||||
return (
|
||||
<SelectField
|
||||
|
||||
Loading…
Reference in New Issue
Block a user