sozsoft-platform/ui/src/views/report/reportRouteParams.ts
2026-06-17 22:55:23 +03:00

52 lines
1.2 KiB
TypeScript

export type ReportRouteParams = {
report?: string
id?: string
listFormCode?: string
}
const isDynamicGridReport = (report?: string) =>
report === 'DynamicGrid' ||
report === 'DynamicGridReport' ||
report === 'DynamicTree' ||
report === 'DynamicTreeReport'
export const normalizeReportRouteParams = ({
report,
id,
listFormCode,
}: ReportRouteParams) => {
if (isDynamicGridReport(report) && id && !listFormCode) {
return {
report,
id: undefined,
listFormCode: id,
}
}
return {
report,
id,
listFormCode,
}
}
export const createReportUrl = (
params: ReportRouteParams,
search: string,
action = 'view',
) => {
const { report, id, listFormCode } = normalizeReportRouteParams(params)
if (!report) return ''
const searchParams = new URLSearchParams(search)
searchParams.delete('id')
searchParams.delete('listFormCode')
const pathSegments = [report, action]
if (id) pathSegments.push(id)
if (listFormCode) pathSegments.push(listFormCode)
const path = pathSegments.map((segment) => encodeURIComponent(segment)).join('/')
const queryString = searchParams.toString()
return queryString ? `${path}?${queryString}` : path
}