Fix lists and record details: use the app-scoped view endpoints
This commit is contained in:
parent
4d3f4ae2b5
commit
0da102098e
40
src/api.ts
40
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<TabularViewResponse> {
|
||||
const raw = await client.request<RawView>('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<string, unknown>[]) : []
|
||||
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<DetailViewResponse> {
|
||||
const raw = await client.request<RawView>('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<string, unknown>
|
||||
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 })),
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 <ErrorBox error={{ message: 'Unknown list' }} />
|
||||
|
||||
@ -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<string | null>(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, {}),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user