diff --git a/src/App.tsx b/src/App.tsx
index 7425d6d..f7b760a 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -14,17 +14,17 @@ function App() {
} />
}>
- } />
- } />
+ } />
+ } />
- } />
- } />
+ } />
+ } />
- } />
- } />
+ } />
+ } />
- } />
- } />
+ } />
+ } />
diff --git a/src/api/types.ts b/src/api/types.ts
index b4f8b4f..759b353 100644
--- a/src/api/types.ts
+++ b/src/api/types.ts
@@ -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 }>;
diff --git a/src/components/forms/DynamicForm.tsx b/src/components/forms/DynamicForm.tsx
index 1214bcf..314824e 100644
--- a/src/components/forms/DynamicForm.tsx
+++ b/src/components/forms/DynamicForm.tsx
@@ -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}
diff --git a/src/components/forms/fields/WfLookupField.tsx b/src/components/forms/fields/WfLookupField.tsx
index 91db08b..49b1937 100644
--- a/src/components/forms/fields/WfLookupField.tsx
+++ b/src/components/forms/fields/WfLookupField.tsx
@@ -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;
}
-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 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 labelText = labelParts.length > 0
- ? labelParts.join(' - ')
- : `ID: ${row.instance_id || row.id}`;
-
- return {
- value: String(row.instance_id || row.id),
- label: labelText
- };
+ 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 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}`;
+
+ 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);
});
-
- setOptions(opts);
- })
- .catch(err => {
- console.error("Failed to load wf_lookup records:", err);
- })
- .finally(() => {
- if (mounted) setLoading(false);
- });
+ }, 300);
- return () => { mounted = false; };
- }, [client, config]);
+ return () => {
+ mounted = false;
+ clearTimeout(timer);
+ };
+ }, [client, config, activityId, fieldId, formDataStr]);
return (