From fe2d163cd031829b3d2706ed909b3a25637fe205 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 10 May 2023 13:56:25 +0300 Subject: [PATCH] fix build --- .../Components/Calculation/Form/ELT/Kasko.tsx | 24 ++++++++++++++----- .../Components/Calculation/Form/ELT/Osago.tsx | 24 ++++++++++++++----- .../Calculation/Form/ELT/lib/config.tsx | 10 +++++--- packages/tools/array.ts | 4 ---- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/apps/web/Components/Calculation/Form/ELT/Kasko.tsx b/apps/web/Components/Calculation/Form/ELT/Kasko.tsx index 4e1789a..b860b0d 100644 --- a/apps/web/Components/Calculation/Form/ELT/Kasko.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Kasko.tsx @@ -10,7 +10,6 @@ import { useStore } from '@/stores/hooks'; import { useApolloClient } from '@apollo/client'; import type { QueryFunctionContext } from '@tanstack/react-query'; import { useQueries } from '@tanstack/react-query'; -import { clone } from 'tools'; import { Flex } from 'ui/grid'; const storeSelector: StoreSelector = ({ kasko }) => kasko; @@ -118,11 +117,24 @@ export function Kasko() { $calculation.element('tbxInsFranchise').setValue(row.totalFranchise); } - const kaskoColumns = clone(columns); - kaskoColumns[0].title = 'Страховая компания КАСКО'; - kaskoColumns[3].title = ( - handleOnClick()} /> - ); + type Column = (typeof columns)[number]; + const kaskoColumns = columns.map((column: Column) => { + if (column.key === 'name') { + return { + ...column, + title: 'Страховая компания КАСКО', + }; + } + + if (column.key === 'status') { + return { + ...column, + title: handleOnClick()} />, + }; + } + + return column; + }); return ( diff --git a/apps/web/Components/Calculation/Form/ELT/Osago.tsx b/apps/web/Components/Calculation/Form/ELT/Osago.tsx index 3d843cf..3e6924c 100644 --- a/apps/web/Components/Calculation/Form/ELT/Osago.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Osago.tsx @@ -10,7 +10,6 @@ import { useStore } from '@/stores/hooks'; import { useApolloClient } from '@apollo/client'; import type { QueryFunctionContext } from '@tanstack/react-query'; import { useQueries } from '@tanstack/react-query'; -import { clone } from 'tools'; import { Flex } from 'ui/grid'; const storeSelector: StoreSelector = ({ osago }) => osago; @@ -103,11 +102,24 @@ export function Osago() { $tables.insurance.row('osago').column('insCost').setValue(row.sum); } - const osagoColumns = clone(columns); - osagoColumns[0].title = 'Страховая компания ОСАГО'; - osagoColumns[3].title = ( - handleOnClick()} /> - ); + type Column = (typeof columns)[number]; + const osagoColumns = columns.map((column: Column) => { + if (column.key === 'name') { + return { + ...column, + title: 'Страховая компания ОСАГО', + }; + } + + if (column.key === 'status') { + return { + ...column, + title: handleOnClick()} />, + }; + } + + return column; + }); return ( diff --git a/apps/web/Components/Calculation/Form/ELT/lib/config.tsx b/apps/web/Components/Calculation/Form/ELT/lib/config.tsx index 5afc0af..d5c77e6 100644 --- a/apps/web/Components/Calculation/Form/ELT/lib/config.tsx +++ b/apps/web/Components/Calculation/Form/ELT/lib/config.tsx @@ -14,11 +14,13 @@ const formatter = Intl.NumberFormat('ru', { export const columns: ColumnsType = [ { dataIndex: 'name', + key: 'name', title: 'Страховая компания', width: '50%', }, { dataIndex: 'sum', + key: 'sum', render: formatter, sortDirections: ['descend', 'ascend'], sorter: (a, b) => a.sum - b.sum, @@ -27,20 +29,22 @@ export const columns: ColumnsType = [ }, { dataIndex: 'totalFranchise', + key: 'totalFranchise', render: formatter, title: 'Франшиза', width: '20%', }, { dataIndex: 'status', - render: (value) => { - if (value === 'fetching') + key: 'status', + render: (_, record) => { + if (record.status === 'fetching') return ( ); - if (value === 'error') + if (record.status === 'error') return ( diff --git a/packages/tools/array.ts b/packages/tools/array.ts index 50933ff..65f7049 100644 --- a/packages/tools/array.ts +++ b/packages/tools/array.ts @@ -19,7 +19,3 @@ export function difference(arr1: readonly T[], arr2: readonly T[]) { export function isSorted(arr: number[]) { return arr.every((value, index, array) => !index || array[index - 1] <= value); } - -export function clone(arr: T[]) { - return arr.map((x) => ({ ...x })) as T[]; -}