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