fix:workflow lookup not loading options resolved

This commit is contained in:
suryac 2026-07-08 17:45:03 +05:30
parent eea74e3626
commit 686f5e8acd
4 changed files with 58 additions and 53 deletions

View File

@ -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>

View File

@ -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 }>;

View File

@ -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}

View File

@ -9,28 +9,27 @@ 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);
const timer = setTimeout(() => {
client.wfLookupRecords({
activityId,
fieldId,
formData,
formData: JSON.parse(formDataStr),
limit: 200
})
.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
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
@ -47,7 +46,7 @@ export function WfLookupField({ label, required, value, onChange, client, config
.filter((v: any) => v != null && v !== '');
const labelText = labelParts.length > 0
? labelParts.join(' - ')
? labelParts.join(', ')
: `ID: ${row.instance_id || row.id}`;
return {
@ -64,9 +63,13 @@ export function WfLookupField({ label, required, value, onChange, client, config
.finally(() => {
if (mounted) setLoading(false);
});
}, 300);
return () => { mounted = false; };
}, [client, config]);
return () => {
mounted = false;
clearTimeout(timer);
};
}, [client, config, activityId, fieldId, formDataStr]);
return (
<SelectField