From 0da102098eb416ecfb81bf5613c2d21ccb520a3a Mon Sep 17 00:00:00 2001 From: Yashas C Date: Thu, 5 Nov 2026 07:32:09 +0000 Subject: [PATCH] Fix lists and record details: use the app-scoped view endpoints --- src/api.ts | 40 ++++++++++++++++++++++++++++++++++++++++ src/pages/ListPage.tsx | 5 +++-- src/pages/RecordPage.tsx | 6 +++--- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/api.ts b/src/api.ts index b2ae7e9..30d48ea 100644 --- a/src/api.ts +++ b/src/api.ts @@ -17,3 +17,43 @@ export function performStep(client: ZinoClient, workflowId: string, instanceId: data, }) } + +// ---- Views ---- +// In an app-bound frontend the runtime reads a record view with POST +// /view/recordview {rv_template_uid, search_query} and a detail view with +// GET /view/detailview/{dv uid}?instance_id=… (the SDK's query-string +// versions are for the unscoped host and answer "Method Not Allowed" here). +import type { Column, DetailViewResponse, TabularViewResponse } from './zino-sdk' + +interface RawField { field_key: string; output_label: string; data_type: string; is_filter?: boolean; is_search?: boolean } +interface RawView { config?: { fields?: RawField[] }; data?: unknown; pagination?: { page: number; limit: number; total_count: number; total_pages: number } } + +export async function getRecordView( + client: ZinoClient, rvUid: string, p: { page: number; limit: number; search?: string }, +): Promise { + const raw = await client.request('POST', '/view/recordview', { + rv_template_uid: rvUid, + search_query: { page: p.page, limit: p.limit, search: p.search ?? '', sort_by: '', sort_dir: '' }, + }) + const columns: Column[] = (raw.config?.fields ?? []).filter((f) => f.field_key !== '').map((f) => ({ + key: f.field_key, label: f.output_label, data_type: f.data_type, sortable: true, + filterable: !!f.is_filter, searchable: !!f.is_search, + })) + const rows = Array.isArray(raw.data) ? (raw.data as Record[]) : [] + return { rows, columns, total: raw.pagination?.total_count ?? rows.length, totalPages: raw.pagination?.total_pages, page: raw.pagination?.page ?? p.page } +} + +export async function getRecordDetail(client: ZinoClient, dvUid: string, instanceId: string): Promise { + const raw = await client.request('GET', `/view/detailview/${encodeURIComponent(dvUid)}?instance_id=${encodeURIComponent(instanceId)}`) + const d = Array.isArray(raw.data) ? raw.data[0] : raw.data + const data = (d && typeof d === 'object' ? d : {}) as Record + const fields = (raw.config?.fields ?? []).filter((f) => f.field_key !== '') + return { + data, + sections: [{ + title: 'Details', + fields: fields.length ? fields.map((f) => ({ label: f.output_label, value: data[f.field_key] })) + : Object.entries(data).map(([k, v]) => ({ label: k, value: v })), + }], + } +} diff --git a/src/pages/ListPage.tsx b/src/pages/ListPage.tsx index 382bf67..0a90e7f 100644 --- a/src/pages/ListPage.tsx +++ b/src/pages/ListPage.tsx @@ -1,6 +1,7 @@ import { useState } from 'react' import { Link, useNavigate, useParams } from 'react-router-dom' import { useQuery, useZino } from '../zino-sdk' +import { getRecordView } from '../api' import { LISTS, SYSTEM_KEYS } from '../config' import { ErrorBox, Loading, PageTitle, btnPrimary, formatValue, inputCls } from '../components/ui' @@ -9,7 +10,7 @@ const PAGE_SIZE = 20 export default function ListPage() { const { listSlug } = useParams() const list = LISTS.find((l) => l.slug === listSlug) - const { views } = useZino() + const { client } = useZino() const nav = useNavigate() const [page, setPage] = useState(1) const [text, setText] = useState('') @@ -17,7 +18,7 @@ export default function ListPage() { const q = useQuery({ queryKey: ['recordview', list?.viewId, page, search], - queryFn: () => views.getTabularView(list!.viewId, { page, pageSize: PAGE_SIZE, search: search || undefined }), + queryFn: () => getRecordView(client, list!.viewId, { page, limit: PAGE_SIZE, search: search || undefined }), enabled: !!list, }) if (!list) return diff --git a/src/pages/RecordPage.tsx b/src/pages/RecordPage.tsx index 6ef8a54..c68853f 100644 --- a/src/pages/RecordPage.tsx +++ b/src/pages/RecordPage.tsx @@ -3,7 +3,7 @@ import { useQuery, useZino } from '../zino-sdk' import { DETAIL_VIEW_IDS, FIELD_DEFS, STEPS, SYSTEM_KEYS, type StepDef } from '../config' import { ErrorBox, Loading, PageTitle, btnPrimary, btnSecondary, formatValue } from '../components/ui' import { useState } from 'react' -import { performStep } from '../api' +import { getRecordDetail, performStep } from '../api' import { useMutation, useQueryClient } from '../zino-sdk' import { WORKFLOW_IDS } from '../config' @@ -15,12 +15,12 @@ function canPerform(step: StepDef, roles: string[]) { export default function RecordPage() { const { id = '' } = useParams() - const { views, user, client } = useZino() + const { user, client } = useZino() const qc = useQueryClient() const [done, setDone] = useState(null) const q = useQuery({ queryKey: ['detailview', id], - queryFn: () => views.getDetailView(DETAIL_VIEW_IDS.REGISTRATION_DETAILS, id), + queryFn: () => getRecordDetail(client, DETAIL_VIEW_IDS.REGISTRATION_DETAILS, id), }) const quick = useMutation({ mutationFn: (step: StepDef) => performStep(client, WORKFLOW_IDS.TRUCK_ONBOARDING, id, step.id, {}),