From eb2f1e2d6b95577aadbf33c1d889ec7e192074a0 Mon Sep 17 00:00:00 2001 From: TOURI ANIS Date: Tue, 17 Dec 2024 17:29:33 +0100 Subject: [PATCH] improve columnTypes --- .../config/column-type-filter-config.ts | 47 +++++++------- .../spreadsheet/config/equipment/battery.ts | 22 ++++--- .../spreadsheet/config/equipment/bus.ts | 13 ++-- .../config/equipment/dangling-line.ts | 14 +++-- .../spreadsheet/config/equipment/generator.ts | 24 +++++--- .../config/equipment/lcc-converter-station.ts | 14 +++-- .../spreadsheet/config/equipment/line.ts | 25 +++++--- .../spreadsheet/config/equipment/load.ts | 15 +++-- .../config/equipment/shunt-compensator.ts | 8 ++- .../equipment/static-var-compensator.ts | 15 +++-- .../equipment/three-windings-transformer.ts | 27 ++++---- .../spreadsheet/config/equipment/tie-line.ts | 21 ++++--- .../equipment/two-windings-transformer.ts | 25 ++++---- .../config/equipment/vsc-converter-station.ts | 15 +++-- .../spreadsheet/equipment-table.tsx | 5 +- src/components/spreadsheet/table-wrapper.tsx | 61 +------------------ .../spreadsheet/utils/cell-renderers.tsx | 6 +- src/components/spreadsheet/utils/constants.ts | 1 + 18 files changed, 176 insertions(+), 182 deletions(-) diff --git a/src/components/spreadsheet/config/column-type-filter-config.ts b/src/components/spreadsheet/config/column-type-filter-config.ts index 90145f9e61..7bc180e06b 100644 --- a/src/components/spreadsheet/config/column-type-filter-config.ts +++ b/src/components/spreadsheet/config/column-type-filter-config.ts @@ -12,6 +12,7 @@ import CountryCellRenderer from '../utils/country-cell-render'; import { BooleanCellRenderer, DefaultCellRenderer } from '../utils/cell-renderers'; import EnumCellRenderer from '../utils/enum-cell-renderer'; import { Writable } from 'type-fest'; +import RunningStatus from 'components/utils/running-status'; const contains = (target: string, lookingFor: string): boolean => { if (target && lookingFor) { @@ -55,12 +56,7 @@ const textType = { maxNumConditions: 1, filterOptions: [FILTER_TEXT_COMPARATORS.STARTS_WITH, FILTER_TEXT_COMPARATORS.CONTAINS], }, - cellRendererSelector: (props: any) => { - return { - component: DefaultCellRenderer, - props: props, - }; - }, + cellRenderer: DefaultCellRenderer, sortable: true, resizable: true, }; @@ -72,28 +68,32 @@ const numericType = { filterOptions: Object.values(FILTER_NUMBER_COMPARATORS), debounceMs: 200, }, - cellRendererSelector: (props: any) => { + cellRenderer: DefaultCellRenderer, + sortable: true, + resizable: true, +}; + +const numericCanBeInvalidatedType = { + filter: 'agNumberColumnFilter', + filterParams: { + maxNumConditions: 1, + filterOptions: Object.values(FILTER_NUMBER_COMPARATORS), + debounceMs: 200, + }, + cellRendererSelector: ({ context }: { context: any }) => { return { component: DefaultCellRenderer, - props: { - isValueInvalid: props.colDef.cellRendererParams.colisValueInvalid, - applyFluxConvention: props.context.applyFluxConvention, + params: { + isValueInvalid: context.loadFlowStatus !== RunningStatus.SUCCEED, }, }; }, + sortable: true, resizable: true, }; const booleanType = { - cellRendererSelector: ({ value }: { value: string }) => { - return { - component: BooleanCellRenderer, - props: { - value, - }, - }; - }, filter: 'agTextColumnFilter', filterParams: { caseSensitive: false, @@ -108,19 +108,12 @@ const booleanType = { }, debounceMs: 200, }, + cellRenderer: BooleanCellRenderer, sortable: true, resizable: true, }; const countryType = { - cellRendererSelector: ({ value }: { value: string }) => { - return { - component: CountryCellRenderer, - params: { - value, - }, - }; - }, filter: 'agTextColumnFilter', filterParams: { caseSensitive: false, @@ -136,6 +129,7 @@ const countryType = { }, debounceMs: 200, }, + cellRenderer: CountryCellRenderer, sortable: true, resizable: true, }; @@ -143,6 +137,7 @@ const countryType = { export const defaultColumnType = { textType, numericType, + numericCanBeInvalidatedType, booleanType, countryType, }; diff --git a/src/components/spreadsheet/config/equipment/battery.ts b/src/components/spreadsheet/config/equipment/battery.ts index eb5ec93132..5cad804404 100644 --- a/src/components/spreadsheet/config/equipment/battery.ts +++ b/src/components/spreadsheet/config/equipment/battery.ts @@ -11,7 +11,13 @@ import { editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from ' import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { booleanCellEditorConfig, numericalCellEditorConfig } from '../common/cell-editors'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, NUMERIC_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from 'components/spreadsheet/utils/constants'; import { SortWay } from 'hooks/use-aggrid-sort'; export const BATTERY_TAB_DEF = { @@ -54,9 +60,10 @@ export const BATTERY_TAB_DEF = { field: 'p', numeric: true, fractionDigits: 1, - type: NUMERIC_TYPE, - canBeInvalidated: true, - withFluxConvention: true, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, + valueGetter: (params) => { + return params.context.applyFluxConvention(params.data.p); + }, getQuickFilterText: excludeFromGlobalFilter, }, { @@ -64,9 +71,10 @@ export const BATTERY_TAB_DEF = { field: 'q', numeric: true, fractionDigits: 1, - type: NUMERIC_TYPE, - canBeInvalidated: true, - withFluxConvention: true, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, + valueGetter: (params) => { + return params.context.applyFluxConvention(params.data.q); + }, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/bus.ts b/src/components/spreadsheet/config/equipment/bus.ts index ad38137800..bc5d17dcb4 100644 --- a/src/components/spreadsheet/config/equipment/bus.ts +++ b/src/components/spreadsheet/config/equipment/bus.ts @@ -10,7 +10,12 @@ import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { typeAndFetchers } from './common-config'; import { genericColumnOfProperties } from '../common/column-properties'; -import { COUNTRY_TYPE, NUMERIC_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants'; +import { + COUNTRY_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from 'components/spreadsheet/utils/constants'; import { SortWay } from 'hooks/use-aggrid-sort'; export const BUS_TAB_DEF = { @@ -29,16 +34,14 @@ export const BUS_TAB_DEF = { field: 'v', numeric: true, fractionDigits: 1, - canBeInvalidated: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, }, { id: 'Angle', field: 'angle', numeric: true, fractionDigits: 1, - canBeInvalidated: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, }, { id: 'ConnectedComponent', diff --git a/src/components/spreadsheet/config/equipment/dangling-line.ts b/src/components/spreadsheet/config/equipment/dangling-line.ts index ed9c652fd8..afaee6ea88 100644 --- a/src/components/spreadsheet/config/equipment/dangling-line.ts +++ b/src/components/spreadsheet/config/equipment/dangling-line.ts @@ -11,7 +11,13 @@ import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { NOMINAL_V } from '../../../utils/field-constants'; import { genericColumnOfProperties } from '../common/column-properties'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, NUMERIC_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from 'components/spreadsheet/utils/constants'; import { SortWay } from 'hooks/use-aggrid-sort'; export const DANGLING_LINE_TAB_DEF = { @@ -57,18 +63,16 @@ export const DANGLING_LINE_TAB_DEF = { id: 'activePower', field: 'p', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/generator.ts b/src/components/spreadsheet/config/equipment/generator.ts index be6862e515..375295a885 100644 --- a/src/components/spreadsheet/config/equipment/generator.ts +++ b/src/components/spreadsheet/config/equipment/generator.ts @@ -14,7 +14,14 @@ import { } from '../../utils/equipment-table-editors'; import type { EditableCallback, ValueGetterFunc } from 'ag-grid-community'; import { editableCellStyle, editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { ENERGY_SOURCES, REGULATION_TYPES } from '../../../network/constants'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { @@ -99,9 +106,10 @@ export const GENERATOR_TAB_DEF = { field: 'p', numeric: true, fractionDigits: 1, - type: NUMERIC_TYPE, - canBeInvalidated: true, - withFluxConvention: true, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, + valueGetter: (params) => { + return params.context.applyFluxConvention(params.data.p); + }, getQuickFilterText: excludeFromGlobalFilter, }, { @@ -109,9 +117,11 @@ export const GENERATOR_TAB_DEF = { field: 'q', numeric: true, fractionDigits: 1, - type: NUMERIC_TYPE, - canBeInvalidated: true, - withFluxConvention: true, + + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, + valueGetter: (params) => { + return params.context.applyFluxConvention(params.data.p); + }, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/lcc-converter-station.ts b/src/components/spreadsheet/config/equipment/lcc-converter-station.ts index 40e05a61cf..2acf8e9d70 100644 --- a/src/components/spreadsheet/config/equipment/lcc-converter-station.ts +++ b/src/components/spreadsheet/config/equipment/lcc-converter-station.ts @@ -10,7 +10,13 @@ import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { genericColumnOfProperties } from '../common/column-properties'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, NUMERIC_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from 'components/spreadsheet/utils/constants'; import { SortWay } from 'hooks/use-aggrid-sort'; export const LCC_CONVERTER_STATION_TAB_DEF = { @@ -55,18 +61,16 @@ export const LCC_CONVERTER_STATION_TAB_DEF = { id: 'activePower', field: 'p', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/line.ts b/src/components/spreadsheet/config/equipment/line.ts index d55afc06e5..bf318b5a21 100644 --- a/src/components/spreadsheet/config/equipment/line.ts +++ b/src/components/spreadsheet/config/equipment/line.ts @@ -10,7 +10,14 @@ import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import CountryCellRenderer from '../../utils/country-cell-render'; import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { unitToMicroUnit } from '../../../../utils/unit-converter'; import { genericColumnOfProperties } from '../common/column-properties'; import { SortWay } from 'hooks/use-aggrid-sort'; @@ -72,37 +79,35 @@ export const LINE_TAB_DEF = { id: 'ActivePowerSide1', field: 'p1', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, - withFluxConvention: true, + valueGetter: (params) => { + return params.context.applyFluxConvention(params.data.p1); + }, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerSide2', field: 'p2', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide1', field: 'q1', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide2', field: 'q2', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/load.ts b/src/components/spreadsheet/config/equipment/load.ts index aa956a35a7..3c4a35a27b 100644 --- a/src/components/spreadsheet/config/equipment/load.ts +++ b/src/components/spreadsheet/config/equipment/load.ts @@ -9,7 +9,14 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { LOAD_TYPES } from '../../../network/constants'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { enumCellEditorConfig, numericalCellEditorConfig } from '../common/cell-editors'; @@ -66,18 +73,16 @@ export const LOAD_TAB_DEF = { id: 'activePower', field: 'p', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/shunt-compensator.ts b/src/components/spreadsheet/config/equipment/shunt-compensator.ts index b0e5ac3395..69c09718dc 100644 --- a/src/components/spreadsheet/config/equipment/shunt-compensator.ts +++ b/src/components/spreadsheet/config/equipment/shunt-compensator.ts @@ -14,6 +14,7 @@ import { COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, MIN_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, NUMERIC_TYPE, TEXT_TYPE, } from '../../utils/constants'; @@ -64,9 +65,10 @@ export const SHUNT_COMPENSATOR_TAB_DEF = { field: 'q', numeric: true, fractionDigits: 1, - type: NUMERIC_TYPE, - canBeInvalidated: true, - withFluxConvention: true, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, + valueGetter: (params) => { + return params.context.applyFluxConvention(params.data.q); + }, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/static-var-compensator.ts b/src/components/spreadsheet/config/equipment/static-var-compensator.ts index 4be672b3ed..cce31253e1 100644 --- a/src/components/spreadsheet/config/equipment/static-var-compensator.ts +++ b/src/components/spreadsheet/config/equipment/static-var-compensator.ts @@ -9,7 +9,14 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { NOMINAL_V } from '../../../utils/field-constants'; import { genericColumnOfProperties } from '../common/column-properties'; import { SortWay } from 'hooks/use-aggrid-sort'; @@ -51,18 +58,16 @@ export const STATIC_VAR_COMPENSATOR_TAB_DEF = { id: 'activePower', field: 'p', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/three-windings-transformer.ts b/src/components/spreadsheet/config/equipment/three-windings-transformer.ts index 79a550d8d1..200b57a35b 100644 --- a/src/components/spreadsheet/config/equipment/three-windings-transformer.ts +++ b/src/components/spreadsheet/config/equipment/three-windings-transformer.ts @@ -9,7 +9,14 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { editableColumnConfig, excludeFromGlobalFilter, generateTapPositions, typeAndFetchers } from './common-config'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { genericColumnOfProperties } from '../common/column-properties'; import { standardSelectCellEditorConfig } from '../common/cell-editors'; import { SortWay } from 'hooks/use-aggrid-sort'; @@ -89,54 +96,48 @@ export const THREE_WINDINGS_TRANSFORMER_TAB_DEF = { id: 'ActivePowerT3WSide1', field: 'p1', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerT3WSide2', field: 'p2', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerT3WSide3', field: 'p3', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerT3WSide1', field: 'q1', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerT3WSide2', field: 'q2', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerT3WSide3', field: 'q3', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/tie-line.ts b/src/components/spreadsheet/config/equipment/tie-line.ts index 5a215117c2..de15b38423 100644 --- a/src/components/spreadsheet/config/equipment/tie-line.ts +++ b/src/components/spreadsheet/config/equipment/tie-line.ts @@ -9,7 +9,14 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { unitToMicroUnit } from '../../../../utils/unit-converter'; import { genericColumnOfPropertiesReadonly } from '../common/column-properties'; import { SortWay } from 'hooks/use-aggrid-sort'; @@ -70,36 +77,32 @@ export const TIE_LINE_TAB_DEF = { id: 'ActivePowerSide1', field: 'p1', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerSide2', field: 'p2', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide1', field: 'q1', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide2', field: 'q2', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/two-windings-transformer.ts b/src/components/spreadsheet/config/equipment/two-windings-transformer.ts index 616fb86568..67f5bb3f4f 100644 --- a/src/components/spreadsheet/config/equipment/two-windings-transformer.ts +++ b/src/components/spreadsheet/config/equipment/two-windings-transformer.ts @@ -20,7 +20,14 @@ import { isEditable, typeAndFetchers, } from './common-config'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { PHASE_REGULATION_MODES, RATIO_REGULATION_MODES, REGULATION_TYPES, SIDE } from '../../../network/constants'; import { computeHighTapPosition, getTapChangerRegulationTerminalValue } from '../../../utils/utils'; import { unitToMicroUnit } from '../../../../utils/unit-converter'; @@ -165,36 +172,32 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { id: 'ActivePowerSide1', field: 'p1', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerSide2', field: 'p2', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide1', field: 'q1', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide2', field: 'q2', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { @@ -617,16 +620,12 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'connected1', field: 'terminal1Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected2', field: 'terminal2Connected', - boolean: true, - //cellRenderer: BooleanCellRenderer, type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, diff --git a/src/components/spreadsheet/config/equipment/vsc-converter-station.ts b/src/components/spreadsheet/config/equipment/vsc-converter-station.ts index 8205edf015..a69f4ac816 100644 --- a/src/components/spreadsheet/config/equipment/vsc-converter-station.ts +++ b/src/components/spreadsheet/config/equipment/vsc-converter-station.ts @@ -9,7 +9,14 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; -import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { genericColumnOfProperties } from '../common/column-properties'; import { SortWay } from 'hooks/use-aggrid-sort'; @@ -56,18 +63,16 @@ export const VSC_CONVERTER_STATION_TAB_DEF = { id: 'activePower', field: 'p', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', numeric: true, - type: NUMERIC_TYPE, + type: NUMERIC_CAN_BE_INVALIDATED_TYPE, fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/equipment-table.tsx b/src/components/spreadsheet/equipment-table.tsx index bf4e3a8230..2b5533e89d 100644 --- a/src/components/spreadsheet/equipment-table.tsx +++ b/src/components/spreadsheet/equipment-table.tsx @@ -54,6 +54,7 @@ interface EquipmentTableProps { shouldHidePinnedHeaderRightBorder: boolean; columnTypes: { [key: string]: ColDef }; applyFluxConvention: (value: number) => number; + loadFlowStatus: string; } const loadingOverlayComponent = (props: { loadingMessage: string }) => <>{props.loadingMessage}; @@ -74,6 +75,7 @@ export const EquipmentTable: FunctionComponent = ({ shouldHidePinnedHeaderRightBorder, columnTypes, applyFluxConvention, + loadFlowStatus, }) => { const theme = useTheme(); const intl = useIntl(); @@ -104,8 +106,9 @@ export const EquipmentTable: FunctionComponent = ({ intl: intl, translateCountryCode: translate, applyFluxConvention: applyFluxConvention, + loadFlowStatus: loadFlowStatus, }), - [applyFluxConvention, currentNode, intl, studyUuid, theme, topPinnedData, translate] + [applyFluxConvention, currentNode, intl, loadFlowStatus, studyUuid, theme, topPinnedData, translate] ); const getRowHeight = useCallback( diff --git a/src/components/spreadsheet/table-wrapper.tsx b/src/components/spreadsheet/table-wrapper.tsx index 0abd525f8f..28ba8d3fe4 100644 --- a/src/components/spreadsheet/table-wrapper.tsx +++ b/src/components/spreadsheet/table-wrapper.tsx @@ -300,77 +300,19 @@ const TableWrapper: FunctionComponent = ({ const columnExtended = { ...column }; columnExtended.headerName = intl.formatMessage({ id: columnExtended.id }); - if (columnExtended.numeric) { - //numeric columns need the loadflow status in order to apply a specific css class in case the loadflow is invalid to highlight the value has not been computed - const isValueInvalid = loadFlowStatus !== RunningStatus.SUCCEED && columnExtended.canBeInvalidated; - - columnExtended.cellRendererParams = { - isValueInvalid: isValueInvalid, - }; - if (columnExtended.withFluxConvention) { - // We enrich "flux convention" properties here (and not in config-tables) because we use a hook - // to get the convention, which requires a component context. - columnExtended.cellRendererParams.applyFluxConvention = applyFluxConvention; - columnExtended.comparator = (valueA: number, valueB: number) => { - const normedValueA = valueA !== undefined ? applyFluxConvention(valueA) : undefined; - const normedValueB = valueB !== undefined ? applyFluxConvention(valueB) : undefined; - if (normedValueA !== undefined && normedValueB !== undefined) { - return normedValueA - normedValueB; - } else if (normedValueA === undefined && normedValueB === undefined) { - return 0; - } else if (normedValueA === undefined) { - return -1; - } else if (normedValueB === undefined) { - return 1; - } - return 0; - }; - } - } - - if (columnExtended.cellRenderer == null) { - columnExtended.cellRenderer = DefaultCellRenderer; - } - columnExtended.width = columnExtended.columnWidth || MIN_COLUMN_WIDTH; //if it is not the first render the column might already have a pinned value so we need to handle the case where it needs to be reseted to undefined //we reuse and mutate the column objects so we need to clear to undefined columnExtended.pinned = lockedColumnsNames.has(columnExtended.id) ? 'left' : undefined; - //Set sorting comparator for enum columns so it sorts the translated values instead of the enum values - if (columnExtended?.isEnum) { - columnExtended.comparator = (valueA: string, valueB: string) => { - const getTranslatedOrOriginalValue = (value: string) => { - if (value === undefined || value === null) { - return ''; - } - if (columnExtended.isCountry) { - return translate(value); - } else if (columnExtended.getEnumLabel) { - const labelId = columnExtended.getEnumLabel(value); - return intl.formatMessage({ - id: labelId || value, - defaultMessage: value, - }); - } - return value; - }; - - const translatedValueA = getTranslatedOrOriginalValue(valueA); - const translatedValueB = getTranslatedOrOriginalValue(valueB); - - return translatedValueA.localeCompare(translatedValueB); - }; - } - return makeSpreadsheetAgGridColumn({ headerName: columnExtended.headerName, field: columnExtended.field, ...columnExtended, }); }, - [intl, lockedColumnsNames, loadFlowStatus, applyFluxConvention, translate] + [intl, lockedColumnsNames] ); useEffect(() => { @@ -1218,6 +1160,7 @@ const TableWrapper: FunctionComponent = ({ shouldHidePinnedHeaderRightBorder={isLockedColumnNamesEmpty} columnTypes={defaultColumnType} applyFluxConvention={applyFluxConvention} + loadFlowStatus={loadFlowStatus} /> )} diff --git a/src/components/spreadsheet/utils/cell-renderers.tsx b/src/components/spreadsheet/utils/cell-renderers.tsx index 39e1df6a77..57c051f88c 100644 --- a/src/components/spreadsheet/utils/cell-renderers.tsx +++ b/src/components/spreadsheet/utils/cell-renderers.tsx @@ -142,6 +142,7 @@ export const convertDuration = (duration: number) => { export const DefaultCellRenderer = (props: any) => { const cellValue = formatCell(props); + return ( { title={cellValue.tooltip ? cellValue.tooltip : cellValue.value} > diff --git a/src/components/spreadsheet/utils/constants.ts b/src/components/spreadsheet/utils/constants.ts index 0daa3ffe33..23e8de1bc2 100644 --- a/src/components/spreadsheet/utils/constants.ts +++ b/src/components/spreadsheet/utils/constants.ts @@ -17,6 +17,7 @@ export const REORDERED_COLUMNS_PARAMETER_PREFIX_IN_DATABASE = 'reorderedColumns. export const TEXT_TYPE = 'textType'; export const NUMERIC_TYPE = 'numericType'; +export const NUMERIC_CAN_BE_INVALIDATED_TYPE = 'numericCanBeInvalidatedType'; export const ENUM_TYPE = 'enumType'; export const BOOLEAN_TYPE = 'booleanType'; export const COUNTRY_TYPE = 'countryType';