From c2338c98ababa43326b6ebe2f12999f9d8b40c94 Mon Sep 17 00:00:00 2001 From: goodmice Date: Wed, 15 Jun 2022 11:56:31 +0500 Subject: [PATCH] =?UTF-8?q?*=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=82=D1=83=D0=BB=D1=82=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=20*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=83=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=BC=20?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=20(?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=B3=D0=BB=D1=83=D0=B1=D0=BE=D0=BA=D0=BE=D0=B5?= =?UTF-8?q?=20=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/charts/ChartTimeBase.tsx | 6 ++-- src/pages/WellOperations/Tvd/index.jsx | 11 +++++--- src/utils/filters/columnFilters.ts | 36 ++++++++++++++++++++++++ src/utils/filters/index.ts | 37 ++----------------------- 4 files changed, 49 insertions(+), 41 deletions(-) create mode 100644 src/utils/filters/columnFilters.ts diff --git a/src/components/charts/ChartTimeBase.tsx b/src/components/charts/ChartTimeBase.tsx index 3c1b6db..5960a3d 100755 --- a/src/components/charts/ChartTimeBase.tsx +++ b/src/components/charts/ChartTimeBase.tsx @@ -10,7 +10,8 @@ import { ChartData, ChartOptions, ChartType, - ChartDataset + ChartDataset, + Tooltip } from 'chart.js' import 'chartjs-adapter-moment' import ChartDataLabels from 'chartjs-plugin-datalabels' @@ -24,7 +25,8 @@ Chart.register( PointElement, Legend, ChartDataLabels, - zoomPlugin + zoomPlugin, + Tooltip, ) const defaultOptions: ChartOptions = { diff --git a/src/pages/WellOperations/Tvd/index.jsx b/src/pages/WellOperations/Tvd/index.jsx index 8a4d57c..2e4fbe0 100755 --- a/src/pages/WellOperations/Tvd/index.jsx +++ b/src/pages/WellOperations/Tvd/index.jsx @@ -10,7 +10,8 @@ import { Legend, LineController, PointElement, - LineElement + LineElement, + Tooltip } from 'chart.js' import 'chartjs-adapter-moment' import zoomPlugin from 'chartjs-plugin-zoom' @@ -27,6 +28,7 @@ import AdditionalTables from './AdditionalTables' import '@styles/index.css' import '@styles/tvd.less' +import { unique } from '@asb/utils/filters' Chart.register( TimeScale, @@ -36,7 +38,8 @@ Chart.register( PointElement, Legend, ChartDataLabels, - zoomPlugin + zoomPlugin, + Tooltip, ) const numericRender = (value) => Number.isFinite(value) ? (+value).toFixed(2) : '-' @@ -135,7 +138,7 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => { if (typeof datasetId === 'undefined') return const datasetName = datasetId === 2 ? 'plan' : 'fact' - const ids = points.filter((p) => p?.raw?.id).map((p) => p.raw.id).join(',') + const ids = points.map((p) => p.raw.id).filter(Boolean).filter(unique).join(',') navigate(`/well/${idWell}/operations/${datasetName}/?selectedId=${ids}`) }, [idWell, navigate]) @@ -175,8 +178,8 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => { const newChart = new Chart(chartRef.current, { type: 'line', - plugins: [ChartDataLabels], options: options, + plugins: [ChartDataLabels], data: { datasets: [] }, }) setChart(newChart) diff --git a/src/utils/filters/columnFilters.ts b/src/utils/filters/columnFilters.ts new file mode 100644 index 0000000..dcf0e2d --- /dev/null +++ b/src/utils/filters/columnFilters.ts @@ -0,0 +1,36 @@ +export const makeTextOnFilter = (key: string) => + (value: string, record?: Record) => String(record?.[key]).startsWith(value) + +export const makeArrayOnFilter = (key: string) => + (value: string, record?: Record) => (!value && (record?.[key]?.length ?? 0) <= 0) || record?.[key]?.includes(value) + +export const makeObjectOnFilter = (field: string, key: string) => + (value: string, record?: Record>) => String(record?.[field]?.[key]).startsWith(value) + +export const makeTextFilters = (array: Record[], keys: string[]) => { + const filters: string[][] = Array(keys.length) + + for (let i = 0; i < keys.length; filters[i++] = []); + + array.forEach((row) => { + if (!row) return + keys.forEach((key, idx) => { + if (!row[key]) return + const value = String(row[key]) + if (filters[idx].indexOf(value) < 0) + filters[idx].push(value) + }) + }) + + const out: Record = {} + + keys.forEach((key, idx) => { + filters[idx].sort() + out[key] = filters[idx].map((filter) => ({ + value: filter, + text: filter, + })) + }) + + return out +} diff --git a/src/utils/filters/index.ts b/src/utils/filters/index.ts index dcf0e2d..cb2982b 100644 --- a/src/utils/filters/index.ts +++ b/src/utils/filters/index.ts @@ -1,36 +1,3 @@ -export const makeTextOnFilter = (key: string) => - (value: string, record?: Record) => String(record?.[key]).startsWith(value) +export * from './columnFilters' -export const makeArrayOnFilter = (key: string) => - (value: string, record?: Record) => (!value && (record?.[key]?.length ?? 0) <= 0) || record?.[key]?.includes(value) - -export const makeObjectOnFilter = (field: string, key: string) => - (value: string, record?: Record>) => String(record?.[field]?.[key]).startsWith(value) - -export const makeTextFilters = (array: Record[], keys: string[]) => { - const filters: string[][] = Array(keys.length) - - for (let i = 0; i < keys.length; filters[i++] = []); - - array.forEach((row) => { - if (!row) return - keys.forEach((key, idx) => { - if (!row[key]) return - const value = String(row[key]) - if (filters[idx].indexOf(value) < 0) - filters[idx].push(value) - }) - }) - - const out: Record = {} - - keys.forEach((key, idx) => { - filters[idx].sort() - out[key] = filters[idx].map((filter) => ({ - value: filter, - text: filter, - })) - }) - - return out -} +export const unique = (value: T, index: number, self: T[]) => self.indexOf(value) === index