diff --git a/src/components/spreadsheet/config/column-aggrid-utils.ts b/src/components/spreadsheet/config/column-aggrid-utils.ts new file mode 100644 index 0000000000..87bec3d77c --- /dev/null +++ b/src/components/spreadsheet/config/column-aggrid-utils.ts @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import { SpreadsheetColDef } from './spreadsheet.type'; + +export const makeSpreadsheetAgGridColumn = ({ + forceDisplayFilterIcon, + tabIndex, + isCustomColumn, + Menu, + ...props // agGrid column props +}: SpreadsheetColDef) => { + const { headerName, fractionDigits, numeric } = props; + + let minWidth = 75; + + return { + headerTooltip: headerName, + minWidth, + fractionDigits: numeric && !fractionDigits ? 2 : fractionDigits, + ...props, + }; +}; diff --git a/src/components/spreadsheet/config/column-type-filter-config.ts b/src/components/spreadsheet/config/column-type-filter-config.ts new file mode 100644 index 0000000000..aa1610f022 --- /dev/null +++ b/src/components/spreadsheet/config/column-type-filter-config.ts @@ -0,0 +1,245 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import { ColDef, ICellRendererParams, ValueGetterFunc, ValueGetterParams } from 'ag-grid-community'; +import { FILTER_NUMBER_COMPARATORS, FILTER_TEXT_COMPARATORS } from 'components/custom-aggrid/custom-aggrid-header.type'; +import { BooleanCellRenderer, DefaultSpreadsheetCellRenderer, PropertiesCellRenderer } from '../utils/cell-renderers'; +import { EnumOption } from 'components/utils/utils-type'; +import { computeHighTapPosition, getEnumLabelById } from 'components/utils/utils'; +import { Writable } from 'type-fest'; +import RunningStatus from 'components/utils/running-status'; +import { + ENERGY_SOURCES, + LOAD_TYPES, + PHASE_REGULATION_MODES, + RATIO_REGULATION_MODES, + REGULATION_TYPES, + SHUNT_COMPENSATOR_TYPES, + SIDE, +} from 'components/network/constants'; +import { unitToKiloUnit, unitToMicroUnit } from 'utils/unit-converter'; +import { RegulatingTerminalCellGetter } from './equipment/generator'; +import { + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_2_FRACTION_DIGITS_TYPE, + NUMERIC_5_FRACTION_DIGITS_TYPE, + NUMERIC_APPLY_FLUX_CONVENTION_1_FRACTION_DIGITS_TYPE, + NUMERIC_APPLY_FLUX_CONVENTION_2_FRACTION_DIGITS_TYPE, + NUMERIC_APPLY_FLUX_CONVENTION_5_FRACTION_DIGITS_TYPE, + NUMERIC_APPLY_FLUX_CONVENTION_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_HIGH_TAP_POSITION_TYPE, + NUMERIC_SWITCHED_ON_Q_AT_NOMINAL_V_TYPE, + NUMERIC_SWITCHED_ON_SUSCEPTANCE_TYPE, + NUMERIC_TYPE, + NUMERIC_UNIT_TO_KILO_UNIT_TYPE, + NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, +} from '../utils/constants'; + +const TEXT_FILTER_PARAMS = { + caseSensitive: false, + maxNumConditions: 1, + filterOptions: [FILTER_TEXT_COMPARATORS.STARTS_WITH, FILTER_TEXT_COMPARATORS.CONTAINS], + debounceMs: 200, +}; + +const NUMERIC_FILTER_PARAMS = { + maxNumConditions: 1, + filterOptions: Object.values(FILTER_NUMBER_COMPARATORS), + debounceMs: 200, +}; + +const formatCellValue = (value: any, decimalPlaces: number = 1) => { + if (value != null) { + return parseFloat(value.toFixed(decimalPlaces)); + } + + return null; +}; + +const propertiesGetter: ValueGetterFunc = (params: ValueGetterParams) => { + const properties = params?.data?.properties; + if (properties && Object.keys(properties).length) { + return Object.keys(properties) + .map((property) => `${property} : ${properties[property]}`) + .join(' | '); + } else { + return null; + } +}; + +const createTextColumnType = (cellRenderer: any, valueGetter?: ValueGetterFunc) => ({ + filter: 'agTextColumnFilter', + filterParams: TEXT_FILTER_PARAMS, + cellRenderer, + valueGetter, + sortable: true, + resizable: true, +}); + +const createNumericColumnType = (valueGetter: ValueGetterFunc) => ({ + filter: 'agNumberColumnFilter', + filterParams: NUMERIC_FILTER_PARAMS, + cellRenderer: DefaultSpreadsheetCellRenderer, + valueGetter, + sortable: true, + resizable: true, +}); + +const createEnumConfig = (enumOptions: Readonly) => { + return { + filter: 'agTextColumnFilter', + filterParams: { + caseSensitive: false, + maxNumConditions: 1, + filterOptions: [FILTER_TEXT_COMPARATORS.CONTAINS], + debounceMs: 200, + }, + + valueGetter: (params: any) => { + const value = params.data[params?.colDef?.field!]; + return value + ? params.context.intl.formatMessage({ + id: getEnumLabelById(enumOptions as Writable, value), + }) + : value; + }, + }; +}; + +const textType = createTextColumnType(DefaultSpreadsheetCellRenderer); +const propertyType = createTextColumnType(PropertiesCellRenderer, propertiesGetter); + +const getNumericType = (fractionDigits?: number) => + createNumericColumnType((params) => { + let value = params.data[params?.colDef?.field!]; + if (params?.colDef?.field === 'coordinatedReactiveControl.qPercent') { + value = isNaN(value) ? 0 : value; + } + if (params?.colDef?.field === 'generatorShortCircuit.directTransX') { + value = value || 0; + } + if (params?.colDef?.field === 'RegulatingTerminalGenerator') { + return RegulatingTerminalCellGetter; + } + return fractionDigits ? formatCellValue(value, fractionDigits) : value; + }); + +const numericType = getNumericType(); +const numeric0FractionDigitsType = getNumericType(0); +const numeric1FractionDigitsType = getNumericType(1); +const numeric2FractionDigitsType = getNumericType(2); +const numeric5FractionDigitsType = getNumericType(5); + +const createNumericUnitConversionType = (conversionFunction: (value: any) => any) => + createNumericColumnType((params) => conversionFunction(params.data[params?.colDef?.field!])); + +const numericUnitToMicroUnitType = createNumericUnitConversionType(unitToMicroUnit); +const numericUnitToKiloUnitType = createNumericUnitConversionType(unitToKiloUnit); + +const numericHighTapPositionType = createNumericColumnType((params) => + computeHighTapPosition(params.data[params?.colDef?.field!]?.steps) +); +const numericSwitchedOnSusceptanceType = createNumericColumnType((params) => { + return formatCellValue( + (params?.data?.maxSusceptance / params?.data?.maximumSectionCount) * params?.data?.sectionCount, + 5 + ); +}); + +const numericSwitchedOnQAtNominalVType = createNumericColumnType((params) => { + return formatCellValue( + (params?.data?.maxQAtNominalV / params?.data?.maximumSectionCount) * params?.data?.sectionCount, + 5 + ); +}); + +const getNumericApplyFluxConventionType = (fractionDigits?: number) => + createNumericColumnType((params) => { + const value = params.context.applyFluxConvention(params.data[params?.colDef?.field!]); + return formatCellValue(value, fractionDigits); + }); + +const numericApplyFluxConventionType = getNumericApplyFluxConventionType(0); +const numericApplyFluxConvention1FractionDigitsType = getNumericApplyFluxConventionType(1); +const numericApplyFluxConvention2FractionDigitsType = getNumericApplyFluxConventionType(2); +const numericApplyFluxConvention5FractionDigitsType = getNumericApplyFluxConventionType(5); + +const numericCanBeInvalidatedType = { + cellRendererSelector: (params: ICellRendererParams) => ({ + component: DefaultSpreadsheetCellRenderer, + params: { + isValueInvalid: params.context.loadFlowStatus !== RunningStatus.SUCCEED, + }, + }), +}; + +const booleanType = createTextColumnType(BooleanCellRenderer); + +const countryType = createTextColumnType(DefaultSpreadsheetCellRenderer, (params: ValueGetterParams) => { + if (params.context?.translateCountryCode && params?.colDef?.field) { + return params.context.translateCountryCode(params.data[params.colDef.field]); + } +}); + +const energySourceEnumType = createEnumConfig(ENERGY_SOURCES); +const regulationEnumType = createEnumConfig(Object.values(REGULATION_TYPES)); +const loadEnumType = createEnumConfig([...LOAD_TYPES, { id: 'UNDEFINED', label: 'Undefined' }]); +const shuntCompensatorEnumType = createEnumConfig(Object.values(SHUNT_COMPENSATOR_TYPES)); +const ratioRegulationModesEnumType = createEnumConfig(Object.values(RATIO_REGULATION_MODES)); +const sideEnumType = createEnumConfig(Object.values(SIDE)); +const phaseRegulatingModeEnumType = createEnumConfig(Object.values(PHASE_REGULATION_MODES)); + +const numericTypes = [ + NUMERIC_TYPE, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_2_FRACTION_DIGITS_TYPE, + NUMERIC_5_FRACTION_DIGITS_TYPE, + NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, + NUMERIC_UNIT_TO_KILO_UNIT_TYPE, + NUMERIC_APPLY_FLUX_CONVENTION_TYPE, + NUMERIC_APPLY_FLUX_CONVENTION_1_FRACTION_DIGITS_TYPE, + NUMERIC_APPLY_FLUX_CONVENTION_2_FRACTION_DIGITS_TYPE, + NUMERIC_APPLY_FLUX_CONVENTION_5_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_HIGH_TAP_POSITION_TYPE, + NUMERIC_SWITCHED_ON_SUSCEPTANCE_TYPE, + NUMERIC_SWITCHED_ON_Q_AT_NOMINAL_V_TYPE, +]; + +export const isNumericType = (type: string) => numericTypes.includes(type); + +export const defaultColumnType: { [key: string]: ColDef } = { + textType, + propertyType, + numericType, + numeric0FractionDigitsType, + numeric1FractionDigitsType, + numeric2FractionDigitsType, + numeric5FractionDigitsType, + numericUnitToMicroUnitType, + numericUnitToKiloUnitType, + numericHighTapPositionType, + numericCanBeInvalidatedType, + numericApplyFluxConventionType, + numericApplyFluxConvention1FractionDigitsType, + numericApplyFluxConvention2FractionDigitsType, + numericApplyFluxConvention5FractionDigitsType, + numericSwitchedOnSusceptanceType, + numericSwitchedOnQAtNominalVType, + booleanType, + countryType, + energySourceEnumType, + regulationEnumType, + loadEnumType, + shuntCompensatorEnumType, + ratioRegulationModesEnumType, + sideEnumType, + phaseRegulatingModeEnumType, +}; diff --git a/src/components/spreadsheet/config/common/column-properties.tsx b/src/components/spreadsheet/config/common/column-properties.tsx index 7c6a4642e9..d52e48c84c 100644 --- a/src/components/spreadsheet/config/common/column-properties.tsx +++ b/src/components/spreadsheet/config/common/column-properties.tsx @@ -5,31 +5,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { PropertiesCellRenderer } from '../../utils/cell-renderers'; import { SitePropertiesEditor } from '../../utils/equipement-table-popup-editors'; -import type { ValueGetterFunc, ValueSetterParams } from 'ag-grid-community'; -import { defaultTextFilterConfig, editableColumnConfig, excludeFromGlobalFilter } from '../equipment/common-config'; - -const propertiesGetter: ValueGetterFunc = (params) => { - const properties = params?.data?.properties; - if (properties && Object.keys(properties).length) { - return Object.keys(properties) - .map((property) => `${property} : ${properties[property]}`) - .join(' | '); - } else { - return null; - } -}; +import type { ValueSetterParams } from 'ag-grid-community'; +import { editableColumnConfig, excludeFromGlobalFilter } from '../equipment/common-config'; //TODO only used in tie-line config, is "valueSetter" forgotten? export const genericColumnOfPropertiesReadonly = { id: 'Properties', field: 'properties', - valueGetter: propertiesGetter, - cellRenderer: PropertiesCellRenderer, minWidth: 300, getQuickFilterText: excludeFromGlobalFilter, - ...defaultTextFilterConfig, + type: 'propertyType', }; export const genericColumnOfProperties = { diff --git a/src/components/spreadsheet/config/equipment/battery.ts b/src/components/spreadsheet/config/equipment/battery.ts index 27f4f9ff99..822474dba1 100644 --- a/src/components/spreadsheet/config/equipment/battery.ts +++ b/src/components/spreadsheet/config/equipment/battery.ts @@ -7,20 +7,19 @@ import type { ReadonlyDeep } from 'type-fest'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; -import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - editableColumnConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; +import { editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config'; 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_1_FRACTION_DIGITS_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 = { index: 9, @@ -30,58 +29,47 @@ export const BATTERY_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, ...editableColumnConfig, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: 'nominalVoltage', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_TYPE, }, { id: 'activePower', field: 'p', - numeric: true, - fractionDigits: 1, - ...defaultNumericFilterConfig, - canBeInvalidated: true, - withFluxConvention: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', - numeric: true, - fractionDigits: 1, - ...defaultNumericFilterConfig, - canBeInvalidated: true, - withFluxConvention: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerControl', field: 'activePowerControl.participate', - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, ...editableColumnConfig, valueSetter: (params) => { params.data.activePowerControl = { @@ -96,12 +84,9 @@ export const BATTERY_TAB_DEF = { { id: 'DroopColumnName', field: 'activePowerControl.droop', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.activePowerControl?.droop), - valueGetter: (params) => params.data?.activePowerControl?.droop, valueSetter: (params) => { params.data.activePowerControl = { ...(params.data.activePowerControl || {}), @@ -120,9 +105,7 @@ export const BATTERY_TAB_DEF = { { id: 'minP', field: 'minP', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.minP), crossValidation: { @@ -133,9 +116,7 @@ export const BATTERY_TAB_DEF = { { id: 'maxP', field: 'maxP', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.maxP), crossValidation: { @@ -146,9 +127,7 @@ export const BATTERY_TAB_DEF = { { id: 'activePowerSetpoint', field: 'targetP', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.targetP), crossValidation: { @@ -161,9 +140,7 @@ export const BATTERY_TAB_DEF = { { id: 'reactivePowerSetpoint', field: 'targetQ', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.targetQ), getQuickFilterText: excludeFromGlobalFilter, @@ -171,9 +148,7 @@ export const BATTERY_TAB_DEF = { { id: 'connected', field: 'terminalConnected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfPropertiesEditPopup, diff --git a/src/components/spreadsheet/config/equipment/bus.ts b/src/components/spreadsheet/config/equipment/bus.ts index df4e9d7adc..195a79566e 100644 --- a/src/components/spreadsheet/config/equipment/bus.ts +++ b/src/components/spreadsheet/config/equipment/bus.ts @@ -8,14 +8,17 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { - countryEnumFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - typeAndFetchers, -} from './common-config'; +import { typeAndFetchers } from './common-config'; import { genericColumnOfProperties } from '../common/column-properties'; +import { + COUNTRY_TYPE, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_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 = { index: 14, @@ -25,52 +28,43 @@ export const BUS_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Magnitude', field: 'v', - numeric: true, - fractionDigits: 1, - canBeInvalidated: true, - ...defaultNumericFilterConfig, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], }, { id: 'Angle', field: 'angle', - numeric: true, - fractionDigits: 1, - canBeInvalidated: true, - ...defaultNumericFilterConfig, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], }, { id: 'ConnectedComponent', field: 'connectedComponentNum', - ...defaultNumericFilterConfig, + type: NUMERIC_TYPE, }, { id: 'SynchronousComponent', field: 'synchronousComponentNum', - ...defaultNumericFilterConfig, + type: NUMERIC_TYPE, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: 'nominalVoltage', - numeric: true, - fractionDigits: 0, - ...defaultNumericFilterConfig, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, genericColumnOfProperties, ], diff --git a/src/components/spreadsheet/config/equipment/busbar-section.ts b/src/components/spreadsheet/config/equipment/busbar-section.ts index 0e5a2daab5..fe219cb19e 100644 --- a/src/components/spreadsheet/config/equipment/busbar-section.ts +++ b/src/components/spreadsheet/config/equipment/busbar-section.ts @@ -7,8 +7,10 @@ import { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import { defaultTextFilterConfig, typeAndFetchers } from './common-config'; +import { typeAndFetchers } from './common-config'; import type { ReadonlyDeep } from 'type-fest'; +import { TEXT_TYPE } from 'components/spreadsheet/utils/constants'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const BUSBAR_SECTION_TAB_DEF = { index: 16, @@ -18,13 +20,13 @@ export const BUSBAR_SECTION_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, ], } as const satisfies ReadonlyDeep; diff --git a/src/components/spreadsheet/config/equipment/common-config.ts b/src/components/spreadsheet/config/equipment/common-config.ts index 1338b8c7b7..ddde5b3236 100644 --- a/src/components/spreadsheet/config/equipment/common-config.ts +++ b/src/components/spreadsheet/config/equipment/common-config.ts @@ -5,17 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import type { ReadonlyDeep, Writable } from 'type-fest'; -import { getEnumLabelById } from '../../../utils/utils'; -import { - type CustomColDef, - FILTER_DATA_TYPES, - FILTER_NUMBER_COMPARATORS, - FILTER_TEXT_COMPARATORS, -} from '../../../custom-aggrid/custom-aggrid-header.type'; -import { EnumOption } from '../../../utils/utils-type'; +import type { ReadonlyDeep } from 'type-fest'; +import { type CustomColDef } from '../../../custom-aggrid/custom-aggrid-header.type'; import type { CellStyleFunc, EditableCallback } from 'ag-grid-community'; -import EnumCellRenderer, { type EnumCellRendererProps } from '../../utils/enum-cell-renderer'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { fetchBatteries, @@ -37,12 +29,6 @@ import { fetchVscConverterStations, } from '../../../../services/study/network'; import { EquipmentFetcher, SpreadsheetEquipmentType } from '../spreadsheet.type'; -import { - BooleanFilterValue, - CustomAggridBooleanFilter, -} from '../../../custom-aggrid/custom-aggrid-filters/custom-aggrid-boolean-filter'; -import { CustomAggridAutocompleteFilter } from '../../../custom-aggrid/custom-aggrid-filters/custom-aggrid-autocomplete-filter'; -import { CustomAggridComparatorFilter } from '../../../custom-aggrid/custom-aggrid-filters/custom-aggrid-comparator-filter'; type TapPositionsType = { lowTapPosition: number; @@ -120,104 +106,3 @@ export const editableColumnConfig = { // The columns we want to include in the global filter at the date of this comment: ID (all), Name, Country, Type and Nominal Voltage (all). // All the others should be excluded. export const excludeFromGlobalFilter = () => '' as const; - -export const defaultTextFilterConfig = { - filter: 'agTextColumnFilter', - filterComponent: CustomAggridComparatorFilter, - filterComponentParams: { - filterParams: { - filterDataType: FILTER_DATA_TYPES.TEXT, - filterComparators: [FILTER_TEXT_COMPARATORS.STARTS_WITH, FILTER_TEXT_COMPARATORS.CONTAINS], - }, - }, -} as const satisfies Partial>; - -/** - * Default configuration for an enum filter - * a new filter option is added to the default ag-grid filter - */ -export const defaultEnumFilterConfig = { - filter: 'agTextColumnFilter', - agGridFilterParams: { - filterOptions: [ - { - displayKey: 'customInRange', - displayName: 'customInRange', - predicate: (filterValues: string[], cellValue: string) => - // We receive here the filter enum values as a string (filterValue) - filterValues.at(0)?.includes(cellValue) ?? false, - }, - ], - }, - filterComponent: CustomAggridAutocompleteFilter, - filterComponentParams: { - filterParams: { - filterDataType: FILTER_DATA_TYPES.TEXT, - }, - }, - isEnum: true, -} as const satisfies Partial>; - -/** - * Default configuration for a boolean filter - */ -export const defaultBooleanFilterConfig = { - filter: 'agTextColumnFilter', - agGridFilterParams: { - filterOptions: [ - { - displayKey: 'booleanMatches', - displayName: 'booleanMatches', - predicate: (filterValues: string[], cellValue: boolean) => { - const filterValue = filterValues.at(0); - if (filterValue === undefined) { - return false; - } - // We receive here the filter boolean value as a string (filterValue) - // we check if the cellValue is not null neither undefined - if (cellValue != null) { - return filterValue === cellValue.toString(); - } - - // we return true if the filter chosen is undefinedValue - return filterValue === BooleanFilterValue.UNDEFINED; - }, - }, - ], - }, - filterComponent: CustomAggridBooleanFilter, - filterComponentParams: { - filterParams: { - filterDataType: FILTER_DATA_TYPES.BOOLEAN, - }, - }, -} as const satisfies Partial>; - -// This function is used to generate the default configuration for an enum filter -// It generates configuration for filtering, sorting and rendering -export const getDefaultEnumConfig = (enumOptions: Readonly) => - ({ - ...defaultEnumFilterConfig, - cellRenderer: EnumCellRenderer, - cellRendererParams: { - enumOptions: enumOptions as Writable, - // @ts-expect-error TODO TS1360: Property value is missing in type - } satisfies EnumCellRendererProps, - getEnumLabel: (value: string) => getEnumLabelById(enumOptions as Writable, value), - } as const satisfies Partial>); - -export const countryEnumFilterConfig = { - ...defaultEnumFilterConfig, - isCountry: true, -} as const satisfies Partial>; - -export const defaultNumericFilterConfig = { - filter: 'agNumberColumnFilter', - filterComponent: CustomAggridComparatorFilter, - filterComponentParams: { - filterParams: { - filterDataType: FILTER_DATA_TYPES.NUMBER, - filterComparators: Object.values(FILTER_NUMBER_COMPARATORS), - }, - }, -} as const satisfies Partial>; diff --git a/src/components/spreadsheet/config/equipment/dangling-line.ts b/src/components/spreadsheet/config/equipment/dangling-line.ts index 5242bafede..78fade11ad 100644 --- a/src/components/spreadsheet/config/equipment/dangling-line.ts +++ b/src/components/spreadsheet/config/equipment/dangling-line.ts @@ -8,18 +8,18 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; -import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; +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_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + TEXT_TYPE, +} from 'components/spreadsheet/utils/constants'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const DANGLING_LINE_TAB_DEF = { index: 13, @@ -29,78 +29,64 @@ export const DANGLING_LINE_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: NOMINAL_V, - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'PairingKey', field: 'pairingKey', getQuickFilterText: excludeFromGlobalFilter, - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'activePower', field: 'p', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'p0', field: 'p0', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'q0', field: 'q0', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected', field: 'terminalConnected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfProperties, diff --git a/src/components/spreadsheet/config/equipment/generator.ts b/src/components/spreadsheet/config/equipment/generator.ts index e4885914ed..b805dee88c 100644 --- a/src/components/spreadsheet/config/equipment/generator.ts +++ b/src/components/spreadsheet/config/equipment/generator.ts @@ -12,21 +12,20 @@ import { type EquipmentTableDataEditorProps, GeneratorRegulatingTerminalEditor, } from '../../utils/equipment-table-editors'; -import CountryCellRenderer from '../../utils/country-cell-render'; import type { EditableCallback, ValueGetterFunc } from 'ag-grid-community'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { editableCellStyle, editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - editableCellStyle, - editableColumnConfig, - excludeFromGlobalFilter, - getDefaultEnumConfig, - typeAndFetchers, -} from './common-config'; -import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + ENERGY_SOURCE_ENUM_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_APPLY_FLUX_CONVENTION_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + REGULATION_ENUM_TYPE, + TEXT_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_2_FRACTION_DIGITS_TYPE, +} from '../../utils/constants'; import { ENERGY_SOURCES, REGULATION_TYPES } from '../../../network/constants'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { @@ -35,8 +34,9 @@ import { type ICustomCellEditorParams, numericalCellEditorConfig, } from '../common/cell-editors'; +import { SortWay } from 'hooks/use-aggrid-sort'; -const RegulatingTerminalCellGetter: ValueGetterFunc = (params) => { +export const RegulatingTerminalCellGetter: ValueGetterFunc = (params) => { const { regulatingTerminalConnectableId, regulatingTerminalVlId, regulatingTerminalConnectableType } = params?.data || {}; @@ -71,65 +71,53 @@ export const GENERATOR_TAB_DEF = { id: 'ID', field: 'id', columnWidth: MEDIUM_COLUMN_WIDTH, - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, ...editableColumnConfig, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: 'nominalVoltage', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, }, { id: 'energySource', field: 'energySource', - ...getDefaultEnumConfig(ENERGY_SOURCES), + type: ENERGY_SOURCE_ENUM_TYPE, ...editableColumnConfig, ...enumCellEditorConfig((params) => params.data?.energySource, ENERGY_SOURCES), }, { id: 'activePower', field: 'p', - numeric: true, - fractionDigits: 1, - ...defaultNumericFilterConfig, - canBeInvalidated: true, - withFluxConvention: true, + type: [NUMERIC_APPLY_FLUX_CONVENTION_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', - numeric: true, - fractionDigits: 1, - ...defaultNumericFilterConfig, - canBeInvalidated: true, - withFluxConvention: true, + type: [NUMERIC_APPLY_FLUX_CONVENTION_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerControl', field: 'activePowerControl.participate', - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, ...editableColumnConfig, valueSetter: (params) => { params.data.activePowerControl = { @@ -145,12 +133,9 @@ export const GENERATOR_TAB_DEF = { { id: 'ActivePowerRegulationDroop', field: 'activePowerControl.droop', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.activePowerControl?.droop), - valueGetter: (params) => params.data?.activePowerControl?.droop, valueSetter: (params) => { params.data.activePowerControl = { ...(params.data.activePowerControl || {}), @@ -169,9 +154,7 @@ export const GENERATOR_TAB_DEF = { { id: 'minP', field: 'minP', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.minP), getQuickFilterText: excludeFromGlobalFilter, @@ -182,9 +165,7 @@ export const GENERATOR_TAB_DEF = { { id: 'maxP', field: 'maxP', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.maxP), getQuickFilterText: excludeFromGlobalFilter, @@ -196,10 +177,9 @@ export const GENERATOR_TAB_DEF = { id: 'activePowerSetpoint', field: 'targetP', numeric: true, - ...defaultNumericFilterConfig, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.targetP), - fractionDigits: 1, getQuickFilterText: excludeFromGlobalFilter, crossValidation: { minExpression: 'minP', @@ -210,9 +190,7 @@ export const GENERATOR_TAB_DEF = { { id: 'reactivePowerSetpoint', field: 'targetQ', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.targetQ), crossValidation: { @@ -226,8 +204,7 @@ export const GENERATOR_TAB_DEF = { { id: 'voltageRegulationOn', field: 'voltageRegulatorOn', - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, ...editableColumnConfig, ...booleanCellEditorConfig((params) => params.data?.voltageRegulatorOn ?? false), getQuickFilterText: excludeFromGlobalFilter, @@ -235,9 +212,7 @@ export const GENERATOR_TAB_DEF = { { id: 'voltageSetpoint', field: 'targetV', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.targetV), crossValidation: { @@ -251,19 +226,14 @@ export const GENERATOR_TAB_DEF = { { id: 'ReactivePercentageVoltageRegulation', field: 'coordinatedReactiveControl.qPercent', - ...defaultNumericFilterConfig, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, ...editableColumnConfig, - numeric: true, - fractionDigits: 1, ...numericalCellEditorConfig((params) => { const qPercent = params.data?.coordinatedReactiveControl?.qPercent; return isNaN(qPercent) ? 0 : qPercent; }), - valueGetter: (params) => { - const qPercent = params.data?.coordinatedReactiveControl?.qPercent; - return isNaN(qPercent) ? 0 : qPercent; - }, + valueSetter: (params) => { params.data.coordinatedReactiveControl = { ...params.data.coordinatedReactiveControl, @@ -278,13 +248,10 @@ export const GENERATOR_TAB_DEF = { { id: 'directTransX', field: 'generatorShortCircuit.directTransX', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data?.generatorShortCircuit?.directTransX || 0), - valueGetter: (params) => params.data?.generatorShortCircuit?.directTransX, valueSetter: (params) => { params.data.generatorShortCircuit = { ...params.data.generatorShortCircuit, @@ -299,13 +266,10 @@ export const GENERATOR_TAB_DEF = { { id: 'stepUpTransformerX', field: 'generatorShortCircuit.stepUpTransformerX', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data?.generatorShortCircuit?.stepUpTransformerX || 0), - valueGetter: (params) => params.data?.generatorShortCircuit?.stepUpTransformerX, valueSetter: (params) => { params.data.generatorShortCircuit = { ...params.data.generatorShortCircuit, @@ -320,13 +284,10 @@ export const GENERATOR_TAB_DEF = { { id: 'plannedActivePowerSetPoint', field: 'generatorStartup.plannedActivePowerSetPoint', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data?.generatorStartup?.plannedActivePowerSetPoint), - valueGetter: (params) => params.data?.generatorStartup?.plannedActivePowerSetPoint, valueSetter: (params) => { params.data.generatorStartup = { ...params.data?.generatorStartup, @@ -343,11 +304,8 @@ export const GENERATOR_TAB_DEF = { field: 'generatorStartup.marginalCost', ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data?.generatorStartup?.marginalCost), - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, - valueGetter: (params) => params.data?.generatorStartup?.marginalCost, valueSetter: (params) => { params.data.generatorStartup = { ...params.data?.generatorStartup, @@ -362,9 +320,7 @@ export const GENERATOR_TAB_DEF = { { id: 'plannedOutageRate', field: 'generatorStartup.plannedOutageRate', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 2, + type: NUMERIC_2_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data?.generatorStartup?.plannedOutageRate || 0), @@ -373,7 +329,6 @@ export const GENERATOR_TAB_DEF = { maxExpression: 1, minExpression: 0, }, - valueGetter: (params) => params.data?.generatorStartup?.plannedOutageRate, valueSetter: (params) => { params.data.generatorStartup = { ...params.data?.generatorStartup, @@ -385,9 +340,7 @@ export const GENERATOR_TAB_DEF = { { id: 'forcedOutageRate', field: 'generatorStartup.forcedOutageRate', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 2, + type: NUMERIC_2_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.generatorStartup?.forcedOutageRate), @@ -396,7 +349,6 @@ export const GENERATOR_TAB_DEF = { maxExpression: 1, minExpression: 0, }, - valueGetter: (params) => params.data?.generatorStartup?.forcedOutageRate, valueSetter: (params) => { params.data.generatorStartup = { ...params.data?.generatorStartup, @@ -408,23 +360,20 @@ export const GENERATOR_TAB_DEF = { { id: 'connected', field: 'terminalConnected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulationTypeText', field: 'RegulationTypeText', - ...getDefaultEnumConfig(Object.values(REGULATION_TYPES)), + type: REGULATION_ENUM_TYPE, ...editableColumnConfig, ...enumCellEditorConfig((params) => params.data?.RegulationTypeText, Object.values(REGULATION_TYPES)), }, { id: 'RegulatingTerminalGenerator', field: 'RegulatingTerminalGenerator', - ...defaultTextFilterConfig, - valueGetter: RegulatingTerminalCellGetter, + type: TEXT_TYPE, cellStyle: (params) => (isEditableRegulatingTerminalCell(params) ? editableCellStyle(params) : {}), editable: isEditableRegulatingTerminalCell, crossValidation: { diff --git a/src/components/spreadsheet/config/equipment/hvdc-line.ts b/src/components/spreadsheet/config/equipment/hvdc-line.ts index 62fa9b6751..ca0ce22c7f 100644 --- a/src/components/spreadsheet/config/equipment/hvdc-line.ts +++ b/src/components/spreadsheet/config/equipment/hvdc-line.ts @@ -8,19 +8,17 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultEnumFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; -import { LARGE_COLUMN_WIDTH, MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + LARGE_COLUMN_WIDTH, + MEDIUM_COLUMN_WIDTH, + NUMERIC_1_FRACTION_DIGITS_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { genericColumnOfProperties } from '../common/column-properties'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const HVDC_LINE_TAB_DEF = { index: 10, @@ -31,120 +29,102 @@ export const HVDC_LINE_TAB_DEF = { id: 'ID', field: 'id', columnWidth: MEDIUM_COLUMN_WIDTH, - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', columnWidth: MEDIUM_COLUMN_WIDTH, - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdSide1', field: 'voltageLevelId1', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdSide2', field: 'voltageLevelId2', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'ConvertersMode', field: 'convertersMode', columnWidth: LARGE_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, - ...defaultEnumFilterConfig, + type: TEXT_TYPE, }, { id: 'ConverterStationId1', field: 'converterStationId1', columnWidth: LARGE_COLUMN_WIDTH, - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'ConverterStationId2', field: 'converterStationId2', columnWidth: LARGE_COLUMN_WIDTH, - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country1', field: 'country1', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'Country2', field: 'country2', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'R', field: 'r', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerSetpoint', field: 'activePowerSetpoint', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'maxActivePower', field: 'maxP', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'OprFromCS1toCS2', field: 'hvdcOperatorActivePowerRange.oprFromCS1toCS2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, columnWidth: LARGE_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'OprFromCS2toCS1', field: 'hvdcOperatorActivePowerRange.oprFromCS2toCS1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, columnWidth: LARGE_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'AcEmulation', field: 'hvdcAngleDroopActivePowerControl.isEnabled', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'K', field: 'hvdcAngleDroopActivePowerControl.droop', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'P0', field: 'hvdcAngleDroopActivePowerControl.p0', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfProperties, diff --git a/src/components/spreadsheet/config/equipment/lcc-converter-station.ts b/src/components/spreadsheet/config/equipment/lcc-converter-station.ts index 35cd1c14d7..bff3e80a2f 100644 --- a/src/components/spreadsheet/config/equipment/lcc-converter-station.ts +++ b/src/components/spreadsheet/config/equipment/lcc-converter-station.ts @@ -8,17 +8,17 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; -import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; +import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { genericColumnOfProperties } from '../common/column-properties'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + TEXT_TYPE, +} from 'components/spreadsheet/utils/constants'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const LCC_CONVERTER_STATION_TAB_DEF = { index: 11, @@ -28,77 +28,62 @@ export const LCC_CONVERTER_STATION_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: 'nominalV', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'HvdcLineId', field: 'hvdcLineId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'activePower', field: 'p', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'PowerFactor', field: 'powerFactor', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'LossFactor', field: 'lossFactor', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected', field: 'terminalConnected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfProperties, diff --git a/src/components/spreadsheet/config/equipment/line.ts b/src/components/spreadsheet/config/equipment/line.ts index 6585d2dfdc..03c41aab7e 100644 --- a/src/components/spreadsheet/config/equipment/line.ts +++ b/src/components/spreadsheet/config/equipment/line.ts @@ -9,18 +9,19 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; -import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; -import { unitToMicroUnit } from '../../../../utils/unit-converter'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { genericColumnOfProperties } from '../common/column-properties'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const LINE_TAB_DEF = { index: 2, @@ -31,153 +32,117 @@ export const LINE_TAB_DEF = { id: 'ID', field: 'id', columnWidth: MEDIUM_COLUMN_WIDTH, - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', columnWidth: MEDIUM_COLUMN_WIDTH, - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdSide1', field: 'voltageLevelId1', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdSide2', field: 'voltageLevelId2', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country1', field: 'country1', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'Country2', field: 'country2', - ...countryEnumFilterConfig, + type: COUNTRY_TYPE, cellRenderer: CountryCellRenderer, }, { id: 'nominalVoltage1KV', field: 'nominalVoltage1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'nominalVoltage2KV', field: 'nominalVoltage2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'ActivePowerSide1', field: 'p1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerSide2', field: 'p2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide1', field: 'q1', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide2', field: 'q2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'r', field: 'r', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'x', field: 'x', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'g1', field: 'g1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g1), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'g2', field: 'g2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g2), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'b1', field: 'b1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b1), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'b2', field: 'b2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b2), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected1', field: 'terminal1Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected2', field: 'terminal2Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfProperties, diff --git a/src/components/spreadsheet/config/equipment/load.ts b/src/components/spreadsheet/config/equipment/load.ts index f11528fcc7..be61b68e5e 100644 --- a/src/components/spreadsheet/config/equipment/load.ts +++ b/src/components/spreadsheet/config/equipment/load.ts @@ -8,22 +8,21 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - editableColumnConfig, - excludeFromGlobalFilter, - getDefaultEnumConfig, - typeAndFetchers, -} from './common-config'; -import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + LOAD_ENUM_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_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'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const LOAD_TAB_DEF = { index: 6, @@ -34,20 +33,20 @@ export const LOAD_TAB_DEF = { id: 'ID', field: 'id', columnWidth: MEDIUM_COLUMN_WIDTH, - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, ...editableColumnConfig, }, { id: 'loadType', field: 'type', - ...getDefaultEnumConfig([...LOAD_TYPES, { id: 'UNDEFINED', label: 'Undefined' }]), + type: LOAD_ENUM_TYPE, ...editableColumnConfig, ...enumCellEditorConfig( (params) => params.data?.type, @@ -57,45 +56,34 @@ export const LOAD_TAB_DEF = { { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: 'nominalVoltage', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'activePower', field: 'p', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'p0', field: 'p0', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.p0), getQuickFilterText: excludeFromGlobalFilter, @@ -103,9 +91,7 @@ export const LOAD_TAB_DEF = { { id: 'q0', field: 'q0', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.q0), getQuickFilterText: excludeFromGlobalFilter, @@ -113,9 +99,7 @@ export const LOAD_TAB_DEF = { { id: 'connected', field: 'terminalConnected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfPropertiesEditPopup, diff --git a/src/components/spreadsheet/config/equipment/shunt-compensator.ts b/src/components/spreadsheet/config/equipment/shunt-compensator.ts index 0bdd172528..9fb5623041 100644 --- a/src/components/spreadsheet/config/equipment/shunt-compensator.ts +++ b/src/components/spreadsheet/config/equipment/shunt-compensator.ts @@ -8,22 +8,26 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - editableColumnConfig, - excludeFromGlobalFilter, - getDefaultEnumConfig, - typeAndFetchers, -} from './common-config'; -import { MEDIUM_COLUMN_WIDTH, MIN_COLUMN_WIDTH } from '../../utils/constants'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + MIN_COLUMN_WIDTH, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_5_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_SWITCHED_ON_Q_AT_NOMINAL_V_TYPE, + NUMERIC_SWITCHED_ON_SUSCEPTANCE_TYPE, + NUMERIC_TYPE, + SHUNT_COMPENSATOR_ENUM_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { SHUNT_COMPENSATOR_TYPES } from '../../../network/constants'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { enumCellEditorConfig, numericalCellEditorConfig } from '../common/cell-editors'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const SHUNT_COMPENSATOR_TAB_DEF = { index: 7, @@ -34,51 +38,43 @@ export const SHUNT_COMPENSATOR_TAB_DEF = { id: 'ID', field: 'id', columnWidth: MEDIUM_COLUMN_WIDTH, - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, ...editableColumnConfig, columnWidth: MIN_COLUMN_WIDTH, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: 'nominalVoltage', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'ReactivePower', field: 'q', - numeric: true, - fractionDigits: 1, - ...defaultNumericFilterConfig, - canBeInvalidated: true, - withFluxConvention: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'maximumSectionCount', field: 'maximumSectionCount', ...editableColumnConfig, - numeric: true, ...numericalCellEditorConfig((params) => params.data.maximumSectionCount), - ...defaultNumericFilterConfig, + type: NUMERIC_TYPE, getQuickFilterText: excludeFromGlobalFilter, crossValidation: { minExpression: 1, @@ -88,9 +84,8 @@ export const SHUNT_COMPENSATOR_TAB_DEF = { id: 'sectionCount', field: 'sectionCount', ...editableColumnConfig, - numeric: true, ...numericalCellEditorConfig((params) => params.data.sectionCount), - ...defaultNumericFilterConfig, + type: NUMERIC_TYPE, getQuickFilterText: excludeFromGlobalFilter, crossValidation: { minExpression: 0, @@ -100,7 +95,7 @@ export const SHUNT_COMPENSATOR_TAB_DEF = { { id: 'Type', field: 'type', - ...getDefaultEnumConfig(Object.values(SHUNT_COMPENSATOR_TYPES)), + type: SHUNT_COMPENSATOR_ENUM_TYPE, ...editableColumnConfig, ...enumCellEditorConfig((params) => params.data?.type, Object.values(SHUNT_COMPENSATOR_TYPES)), }, @@ -108,10 +103,8 @@ export const SHUNT_COMPENSATOR_TAB_DEF = { id: 'maxQAtNominalV', field: 'maxQAtNominalV', ...editableColumnConfig, - numeric: true, ...numericalCellEditorConfig((params) => params.data.maxQAtNominalV), - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, crossValidation: { minExpression: 0, @@ -120,47 +113,34 @@ export const SHUNT_COMPENSATOR_TAB_DEF = { { id: 'SwitchedOnMaxQAtNominalV', field: 'switchedOnQAtNominalV', - numeric: true, - valueGetter: (params) => - (params?.data?.maxQAtNominalV / params?.data?.maximumSectionCount) * params?.data?.sectionCount, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_SWITCHED_ON_Q_AT_NOMINAL_V_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'maxSusceptance', ...editableColumnConfig, field: 'maxSusceptance', - numeric: true, ...numericalCellEditorConfig((params) => params.data.maxSusceptance), - ...defaultNumericFilterConfig, - fractionDigits: 5, + type: NUMERIC_5_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'SwitchedOnMaxSusceptance', field: 'switchedOnSusceptance', - numeric: true, - valueGetter: (params) => - (params?.data?.maxSusceptance / params?.data?.maximumSectionCount) * params?.data?.sectionCount, - ...defaultNumericFilterConfig, - fractionDigits: 5, + + type: NUMERIC_SWITCHED_ON_SUSCEPTANCE_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'voltageSetpoint', field: 'targetV', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected', field: 'terminalConnected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfPropertiesEditPopup, diff --git a/src/components/spreadsheet/config/equipment/static-var-compensator.ts b/src/components/spreadsheet/config/equipment/static-var-compensator.ts index 2889d9cb29..0d3d076536 100644 --- a/src/components/spreadsheet/config/equipment/static-var-compensator.ts +++ b/src/components/spreadsheet/config/equipment/static-var-compensator.ts @@ -8,19 +8,19 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; -import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_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'; export const STATIC_VAR_COMPENSATOR_TAB_DEF = { index: 8, @@ -30,73 +30,58 @@ export const STATIC_VAR_COMPENSATOR_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: NOMINAL_V, - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'activePower', field: 'p', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'VoltageSetpointKV', field: 'voltageSetpoint', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSetpointMVAR', field: 'reactivePowerSetpoint', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected', field: 'terminalConnected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfProperties, diff --git a/src/components/spreadsheet/config/equipment/substation.ts b/src/components/spreadsheet/config/equipment/substation.ts index 5a0981f8e7..65e98e8d03 100644 --- a/src/components/spreadsheet/config/equipment/substation.ts +++ b/src/components/spreadsheet/config/equipment/substation.ts @@ -9,14 +9,10 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { SelectCountryField } from '../../utils/equipment-table-editors'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { - countryEnumFilterConfig, - defaultTextFilterConfig, - editableColumnConfig, - typeAndFetchers, -} from './common-config'; +import { editableColumnConfig, typeAndFetchers } from './common-config'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; +import { COUNTRY_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const SUBSTATION_TAB_DEF = { index: 0, @@ -26,26 +22,25 @@ export const SUBSTATION_TAB_DEF = { { id: 'ID', field: 'id', - ...defaultTextFilterConfig, - isDefaultSort: true, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', ...editableColumnConfig, - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', ...editableColumnConfig, cellEditor: SelectCountryField, - cellRenderer: CountryCellRenderer, valueSetter: (params) => { params.data.country = params?.newValue; return true; }, - ...countryEnumFilterConfig, + type: COUNTRY_TYPE, }, genericColumnOfPropertiesEditPopup, // FIXME try valueFormatter? ], diff --git a/src/components/spreadsheet/config/equipment/three-windings-transformer.ts b/src/components/spreadsheet/config/equipment/three-windings-transformer.ts index a078bbdcec..288c81dca6 100644 --- a/src/components/spreadsheet/config/equipment/three-windings-transformer.ts +++ b/src/components/spreadsheet/config/equipment/three-windings-transformer.ts @@ -8,22 +8,20 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { editableColumnConfig, excludeFromGlobalFilter, generateTapPositions, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultEnumFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - editableColumnConfig, - excludeFromGlobalFilter, - generateTapPositions, - typeAndFetchers, -} from './common-config'; -import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + 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'; function generateTapRequest(tapType: string, legNumber: number) { return ( @@ -47,141 +45,114 @@ export const THREE_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdT3WSide1', field: 'voltageLevelId1', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdT3WSide2', field: 'voltageLevelId2', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdT3WSide3', field: 'voltageLevelId3', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalVT3WSide1', field: 'nominalV1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'NominalVT3WSide2', field: 'nominalV2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'NominalVT3WSide3', field: 'nominalV3', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'ActivePowerT3WSide1', field: 'p1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerT3WSide2', field: 'p2', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerT3WSide3', field: 'p3', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerT3WSide1', field: 'q1', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerT3WSide2', field: 'q2', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerT3WSide3', field: 'q3', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'HasLoadTapChanging1Capabilities', field: 'hasLoadTapChanging1Capabilities', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulatingRatio1', field: 'isRegulatingRatio1', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'TargetVPoint1', field: 'targetV1', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RatioTap1', - field: 'ratioTapChanger1', - ...defaultNumericFilterConfig, + field: 'ratioTapChanger1.tapPosition', + type: NUMERIC_TYPE, changeCmd: generateTapRequest('Ratio', 1), fractionDigits: 0, - valueGetter: (params) => params?.data?.ratioTapChanger1?.tapPosition, valueSetter: (params) => { params.data.ratioTapChanger1 = { ...params.data.ratioTapChanger1, @@ -196,34 +167,27 @@ export const THREE_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'HasLoadTapChanging2Capabilities', field: 'hasLoadTapChanging2Capabilities', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulatingRatio2', field: 'isRegulatingRatio2', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'TargetVPoint2', field: 'targetV2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RatioTap2', - field: 'ratioTapChanger2', - ...defaultNumericFilterConfig, + field: 'ratioTapChanger2.tapPosition', + type: NUMERIC_TYPE, changeCmd: generateTapRequest('Ratio', 2), fractionDigits: 0, - valueGetter: (params) => params?.data?.ratioTapChanger2?.tapPosition, valueSetter: (params) => { params.data.ratioTapChanger2 = { ...params.data.ratioTapChanger2, @@ -238,34 +202,26 @@ export const THREE_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'HasLoadTapChanging3Capabilities', field: 'hasLoadTapChanging3Capabilities', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulatingRatio3', field: 'isRegulatingRatio3', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'TargetVPoint3', field: 'targetV3', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RatioTap3', - field: 'ratioTapChanger3', - ...defaultNumericFilterConfig, + field: 'ratioTapChanger3.tapPosition', + type: NUMERIC_1_FRACTION_DIGITS_TYPE, changeCmd: generateTapRequest('Ratio', 3), - fractionDigits: 0, - valueGetter: (params) => params?.data?.ratioTapChanger3?.tapPosition, valueSetter: (params) => { params.data.ratioTapChanger3 = { ...params.data.ratioTapChanger3, @@ -280,25 +236,21 @@ export const THREE_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RegulatingMode1', field: 'regulationModeName1', - ...defaultEnumFilterConfig, + type: NUMERIC_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulatingPhase1', field: 'isRegulatingPhase1', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'PhaseTap1', - field: 'phaseTapChanger1', - ...defaultNumericFilterConfig, + field: 'phaseTapChanger1.tapPosition', + type: NUMERIC_0_FRACTION_DIGITS_TYPE, changeCmd: generateTapRequest('Phase', 1), - fractionDigits: 0, - valueGetter: (params) => params?.data?.phaseTapChanger1?.tapPosition, valueSetter: (params) => { params.data.phaseTapChanger1 = { ...params.data.phaseTapChanger1, @@ -313,34 +265,28 @@ export const THREE_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RegulatingValue1', field: 'regulatingValue1', - numeric: true, - ...defaultNumericFilterConfig, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, - fractionDigits: 1, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulatingMode2', field: 'regulationModeName2', - ...defaultEnumFilterConfig, + type: NUMERIC_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulatingPhase2', field: 'isRegulatingPhase2', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'PhaseTap2', - field: 'phaseTapChanger2', - ...defaultNumericFilterConfig, + field: 'phaseTapChanger2.tapPosition', + type: NUMERIC_0_FRACTION_DIGITS_TYPE, changeCmd: generateTapRequest('Phase', 2), - fractionDigits: 0, - valueGetter: (params) => params?.data?.phaseTapChanger2?.tapPosition, valueSetter: (params) => { params.data.phaseTapChanger2 = { ...params.data.phaseTapChanger2, @@ -355,34 +301,28 @@ export const THREE_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RegulatingValue2', field: 'regulatingValue2', - numeric: true, - ...defaultNumericFilterConfig, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, - fractionDigits: 1, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulatingMode3', field: 'regulationModeName3', - ...defaultEnumFilterConfig, + type: NUMERIC_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RegulatingPhase3', field: 'isRegulatingPhase3', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'PhaseTap3', - field: 'phaseTapChanger3', - ...defaultNumericFilterConfig, + field: 'phaseTapChanger3.tapPosition', + type: NUMERIC_0_FRACTION_DIGITS_TYPE, changeCmd: generateTapRequest('Phase', 3), - fractionDigits: 0, - valueGetter: (params) => params?.data?.phaseTapChanger3?.tapPosition, valueSetter: (params) => { params.data.phaseTapChanger3 = { ...params.data.phaseTapChanger3, @@ -397,34 +337,26 @@ export const THREE_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RegulatingValue3', field: 'regulatingValue3', - numeric: true, - ...defaultNumericFilterConfig, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, - fractionDigits: 1, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ConnectedT3WSide1', field: 'terminal1Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ConnectedT3WSide2', field: 'terminal2Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ConnectedT3WSide3', field: 'terminal3Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfProperties, diff --git a/src/components/spreadsheet/config/equipment/tie-line.ts b/src/components/spreadsheet/config/equipment/tie-line.ts index 08e6cbe1f0..6af0d658e5 100644 --- a/src/components/spreadsheet/config/equipment/tie-line.ts +++ b/src/components/spreadsheet/config/equipment/tie-line.ts @@ -8,19 +8,19 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; -import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; -import { unitToMicroUnit } from '../../../../utils/unit-converter'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { genericColumnOfPropertiesReadonly } from '../common/column-properties'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const TIE_LINE_TAB_DEF = { index: 15, @@ -31,153 +31,116 @@ export const TIE_LINE_TAB_DEF = { id: 'ID', field: 'id', columnWidth: MEDIUM_COLUMN_WIDTH, - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', columnWidth: MEDIUM_COLUMN_WIDTH, - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdSide1', field: 'voltageLevelId1', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdSide2', field: 'voltageLevelId2', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country1', field: 'country1', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'Country2', field: 'country2', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'nominalVoltage1KV', field: 'nominalVoltage1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'nominalVoltage2KV', field: 'nominalVoltage2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'ActivePowerSide1', field: 'p1', - numeric: true, - ...defaultNumericFilterConfig, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], fractionDigits: 1, - canBeInvalidated: true, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerSide2', field: 'p2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide1', field: 'q1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide2', field: 'q2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'r', field: 'r', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'x', field: 'x', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'g1', field: 'g1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g1), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'g2', field: 'g2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g2), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'b1', field: 'b1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b1), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'b2', field: 'b2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b2), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected1', field: 'terminal1Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected2', field: 'terminal2Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfPropertiesReadonly, diff --git a/src/components/spreadsheet/config/equipment/two-windings-transformer.ts b/src/components/spreadsheet/config/equipment/two-windings-transformer.ts index 83e8ba90ae..9c8490e1f8 100644 --- a/src/components/spreadsheet/config/equipment/two-windings-transformer.ts +++ b/src/components/spreadsheet/config/equipment/two-windings-transformer.ts @@ -10,26 +10,32 @@ import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import type { CustomColDef } from '../../../custom-aggrid/custom-aggrid-header.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import { type EquipmentTableDataEditorProps, TWTRegulatingTerminalEditor } from '../../utils/equipment-table-editors'; -import CountryCellRenderer from '../../utils/country-cell-render'; import type { EditableCallback } from 'ag-grid-community'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, editableCellStyle, editableColumnConfig, excludeFromGlobalFilter, generateTapPositions, - getDefaultEnumConfig, isEditable, typeAndFetchers, } from './common-config'; -import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; +import { + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + NUMERIC_HIGH_TAP_POSITION_TYPE, + NUMERIC_TYPE, + NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, + PHASE_REGULATING_MODE_ENUM_TYPE, + RATIO_REGULATION_MODES_ENUM_TYPE, + REGULATION_ENUM_TYPE, + SIDE_ENUM_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'; import { getComputedRegulationMode } from '../../../dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane-utils'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { @@ -39,6 +45,7 @@ import { numericalCellEditorConfig, standardSelectCellEditorConfig, } from '../common/cell-editors'; +import { SortWay } from 'hooks/use-aggrid-sort'; function getTwtRatioRegulationModeId(twt: any) { //regulationMode is set by the user (in edit mode) @@ -108,50 +115,43 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdSide1', field: 'voltageLevelId1', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelIdSide2', field: 'voltageLevelId2', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'nominalVoltage1KV', field: 'nominalVoltage1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'nominalVoltage2KV', field: 'nominalVoltage2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'ratedVoltage1KV', field: 'ratedU1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.ratedU1), getQuickFilterText: excludeFromGlobalFilter, @@ -159,9 +159,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'ratedVoltage2KV', field: 'ratedU2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.ratedU2), getQuickFilterText: excludeFromGlobalFilter, @@ -169,45 +167,31 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'ActivePowerSide1', field: 'p1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ActivePowerSide2', field: 'p2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide1', field: 'q1', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSide2', field: 'q2', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'HasLoadTapChangingCapabilities', field: 'ratioTapChanger.hasLoadTapChangingCapabilities', - valueGetter: (params) => params?.data?.ratioTapChanger?.hasLoadTapChangingCapabilities, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, editable: (params) => isEditable(params) && hasTwtRatioTapChanger(params), cellStyle: editableCellStyle, valueSetter: (params) => { @@ -228,7 +212,6 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RatioRegulationMode', field: 'ratioTapChanger.regulationMode', - valueGetter: (params) => params.data?.ratioTapChanger?.regulationMode, valueSetter: (params) => { params.data.ratioTapChanger = { ...(params.data?.ratioTapChanger || {}), @@ -250,13 +233,12 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { columnValue: true, }, }, - ...getDefaultEnumConfig(Object.values(RATIO_REGULATION_MODES)), + type: RATIO_REGULATION_MODES_ENUM_TYPE, }, { id: 'TargetVPoint', field: 'ratioTapChanger.targetV', - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, editable: isTwtRatioOnloadAndEditable, cellStyle: editableCellStyle, ...numericalCellEditorConfig((params) => params.data?.ratioTapChanger?.targetV), @@ -272,8 +254,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RatioDeadBand', field: 'ratioTapChanger.targetDeadband', - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, editable: isTwtRatioOnloadAndEditable, cellStyle: editableCellStyle, ...numericalCellEditorConfig((params) => params.data.ratioTapChanger.targetDeadband), @@ -289,7 +270,6 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RatioRegulationTypeText', field: 'ratioTapChanger.regulationType', - valueGetter: (params) => params.data?.ratioTapChanger?.regulationType, valueSetter: (params) => { params.data.ratioTapChanger = { ...(params.data?.ratioTapChanger || {}), @@ -305,13 +285,12 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { editable: isTwtRatioOnloadAndEditable, cellStyle: editableCellStyle, getQuickFilterText: excludeFromGlobalFilter, - ...getDefaultEnumConfig(Object.values(REGULATION_TYPES)), + type: REGULATION_ENUM_TYPE, }, { id: 'RatioRegulatedSide', field: 'ratioTapChanger.regulationSide', - ...getDefaultEnumConfig(Object.values(SIDE)), - valueGetter: (params) => params.data?.ratioTapChanger?.regulationSide, + type: SIDE_ENUM_TYPE, valueSetter: (params) => { params.data.ratioTapChanger = { ...(params.data?.ratioTapChanger || {}), @@ -333,8 +312,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RatioRegulatingTerminal', field: 'ratioTapChanger.ratioRegulatingTerminal', - ...defaultTextFilterConfig, - valueGetter: (params) => params.data?.ratioTapChanger?.ratioRegulatingTerminal, + type: NUMERIC_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, cellStyle: (params) => (isEditableTwtRatioRegulatingTerminalCell(params) ? editableCellStyle(params) : {}), @@ -351,9 +329,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { id: 'RatioLowTapPosition', field: 'ratioTapChanger.lowTapPosition', getQuickFilterText: excludeFromGlobalFilter, - ...defaultNumericFilterConfig, - numeric: true, - fractionDigits: 0, + type: NUMERIC_TYPE, editable: (params) => isEditable(params) && params.data?.ratioTapChanger?.steps?.length > 0, cellStyle: editableCellStyle, ...standardSelectCellEditorConfig((params) => generateTapPositions(params.data?.ratioTapChanger)), @@ -372,18 +348,14 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { }, { id: 'RatioHighTapPosition', - field: 'ratioTapChanger.highTapPosition', - ...defaultNumericFilterConfig, - valueGetter: (params) => computeHighTapPosition(params?.data?.ratioTapChanger?.steps), + field: 'ratioTapChanger', + type: NUMERIC_HIGH_TAP_POSITION_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'RatioTap', field: 'ratioTapChanger.tapPosition', - ...defaultNumericFilterConfig, - numeric: true, - fractionDigits: 0, - valueGetter: (params) => params?.data?.ratioTapChanger?.tapPosition, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, valueSetter: (params) => { params.data.ratioTapChanger = { ...params.data.ratioTapChanger, @@ -405,8 +377,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RegulatingMode', field: 'phaseTapChanger.regulationMode', - ...getDefaultEnumConfig(Object.values(PHASE_REGULATION_MODES)), - valueGetter: (params) => params?.data?.phaseTapChanger?.regulationMode, + type: PHASE_REGULATING_MODE_ENUM_TYPE, valueSetter: (params) => { params.data.phaseTapChanger = { ...(params.data?.phaseTapChanger || {}), @@ -426,10 +397,9 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'RegulatingValue', field: 'phaseTapChanger.regulationValue', - ...defaultNumericFilterConfig, + type: NUMERIC_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, fractionDigits: 1, - valueGetter: (params) => params?.data?.phaseTapChanger?.regulationValue, getQuickFilterText: excludeFromGlobalFilter, editable: (params) => hasTwtPhaseTapChangerAndEditable(params) && @@ -447,7 +417,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'PhaseDeadBand', field: 'phaseTapChanger.targetDeadband', - ...defaultNumericFilterConfig, + type: NUMERIC_TYPE, fractionDigits: 1, getQuickFilterText: excludeFromGlobalFilter, editable: (params) => @@ -466,8 +436,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'PhaseRegulationTypeText', field: 'phaseTapChanger.regulationType', - ...getDefaultEnumConfig(Object.values(REGULATION_TYPES)), - valueGetter: (params) => params.data?.phaseTapChanger?.regulationType, + type: REGULATION_ENUM_TYPE, valueSetter: (params) => { params.data.phaseTapChanger = { ...(params.data?.phaseTapChanger || {}), @@ -487,8 +456,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'PhaseRegulatedSide', field: 'phaseTapChanger.regulationSide', - ...getDefaultEnumConfig(Object.values(SIDE)), - valueGetter: (params) => params.data?.phaseTapChanger?.regulationSide, + type: SIDE_ENUM_TYPE, valueSetter: (params) => { params.data.phaseTapChanger = { ...(params.data?.phaseTapChanger || {}), @@ -510,8 +478,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { { id: 'PhaseRegulatingTerminal', field: 'phaseTapChanger.phaseRegulatingTerminal', - ...defaultTextFilterConfig, - valueGetter: (params) => params.data?.phaseTapChanger?.phaseRegulatingTerminal, + type: TEXT_TYPE, columnWidth: MEDIUM_COLUMN_WIDTH, getQuickFilterText: excludeFromGlobalFilter, cellStyle: (params) => (isEditableTwtPhaseRegulatingTerminalCell(params) ? editableCellStyle(params) : {}), @@ -528,7 +495,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { id: 'PhaseLowTapPosition', field: 'phaseTapChanger.lowTapPosition', getQuickFilterText: excludeFromGlobalFilter, - ...defaultNumericFilterConfig, + type: NUMERIC_TYPE, numeric: true, fractionDigits: 0, editable: (params) => isEditable(params) && params.data?.phaseTapChanger?.steps?.length > 0, @@ -549,18 +516,14 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { }, { id: 'PhaseHighTapPosition', - field: 'phaseTapChanger.highTapPosition', - ...defaultNumericFilterConfig, - valueGetter: (params) => computeHighTapPosition(params?.data?.phaseTapChanger?.steps), + field: 'phaseTapChanger', + type: NUMERIC_HIGH_TAP_POSITION_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'PhaseTap', field: 'phaseTapChanger.tapPosition', - ...defaultNumericFilterConfig, - numeric: true, - fractionDigits: 0, - valueGetter: (params) => params?.data?.phaseTapChanger?.tapPosition, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, valueSetter: (params) => { params.data.phaseTapChanger = { ...params.data.phaseTapChanger, @@ -582,58 +545,43 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { id: 'r', field: 'r', numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'x', field: 'x', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'g', field: 'g', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'b', field: 'b', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b), + type: NUMERIC_UNIT_TO_MICRO_UNIT_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ratedNominalPower', field: 'ratedS', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected1', field: 'terminal1Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected2', field: 'terminal2Connected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfPropertiesEditPopup, diff --git a/src/components/spreadsheet/config/equipment/voltage-level.ts b/src/components/spreadsheet/config/equipment/voltage-level.ts index 9728d292e8..c0653b6248 100644 --- a/src/components/spreadsheet/config/equipment/voltage-level.ts +++ b/src/components/spreadsheet/config/equipment/voltage-level.ts @@ -9,18 +9,18 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import type { CustomColDef } from '../../../custom-aggrid/custom-aggrid-header.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { - countryEnumFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - editableColumnConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; +import { editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { kiloUnitToUnit, unitToKiloUnit } from '../../../../utils/unit-converter'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { numericalCellEditorConfig } from '../common/cell-editors'; +import { + COUNTRY_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_TYPE, + NUMERIC_UNIT_TO_KILO_UNIT_TYPE, + TEXT_TYPE, +} from 'components/spreadsheet/utils/constants'; +import { SortWay } from 'hooks/use-aggrid-sort'; function generateEditableNumericColumnDefinition< TId extends string, @@ -31,9 +31,7 @@ function generateEditableNumericColumnDefinition< return { id: id, field: field, - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data[field]), crossValidation: { @@ -53,32 +51,29 @@ export const VOLTAGE_LEVEL_TAB_DEF = { { id: 'ID', field: 'id', - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', ...editableColumnConfig, - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'SubstationId', field: 'substationId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: 'nominalV', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_TYPE, ...editableColumnConfig, ...numericalCellEditorConfig((params) => params.data.nominalV), }, @@ -87,12 +82,9 @@ export const VOLTAGE_LEVEL_TAB_DEF = { { id: 'IpMin', field: 'identifiableShortCircuit.ipMin', - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_UNIT_TO_KILO_UNIT_TYPE, ...editableColumnConfig, - numeric: true, ...numericalCellEditorConfig((params) => unitToKiloUnit(params.data?.identifiableShortCircuit?.ipMin)), - valueGetter: (params) => unitToKiloUnit(params.data?.identifiableShortCircuit?.ipMin), valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, @@ -108,12 +100,9 @@ export const VOLTAGE_LEVEL_TAB_DEF = { { id: 'IpMax', field: 'identifiableShortCircuit.ipMax', - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_UNIT_TO_KILO_UNIT_TYPE, ...editableColumnConfig, - numeric: true, ...numericalCellEditorConfig((params) => unitToKiloUnit(params.data?.identifiableShortCircuit?.ipMax)), - valueGetter: (params) => unitToKiloUnit(params.data?.identifiableShortCircuit?.ipMax), valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, diff --git a/src/components/spreadsheet/config/equipment/vsc-converter-station.ts b/src/components/spreadsheet/config/equipment/vsc-converter-station.ts index cf3ad063d3..fc84fda167 100644 --- a/src/components/spreadsheet/config/equipment/vsc-converter-station.ts +++ b/src/components/spreadsheet/config/equipment/vsc-converter-station.ts @@ -8,18 +8,18 @@ import type { ReadonlyDeep } from 'type-fest'; import type { SpreadsheetTabDefinition } from '../spreadsheet.type'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; -import CountryCellRenderer from '../../utils/country-cell-render'; -import { BooleanCellRenderer } from '../../utils/cell-renderers'; +import { excludeFromGlobalFilter, typeAndFetchers } from './common-config'; import { - countryEnumFilterConfig, - defaultBooleanFilterConfig, - defaultNumericFilterConfig, - defaultTextFilterConfig, - excludeFromGlobalFilter, - typeAndFetchers, -} from './common-config'; -import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; + BOOLEAN_TYPE, + COUNTRY_TYPE, + MEDIUM_COLUMN_WIDTH, + NUMERIC_0_FRACTION_DIGITS_TYPE, + NUMERIC_1_FRACTION_DIGITS_TYPE, + NUMERIC_CAN_BE_INVALIDATED_TYPE, + TEXT_TYPE, +} from '../../utils/constants'; import { genericColumnOfProperties } from '../common/column-properties'; +import { SortWay } from 'hooks/use-aggrid-sort'; export const VSC_CONVERTER_STATION_TAB_DEF = { index: 12, @@ -30,93 +30,74 @@ export const VSC_CONVERTER_STATION_TAB_DEF = { id: 'ID', field: 'id', columnWidth: MEDIUM_COLUMN_WIDTH, - isDefaultSort: true, - ...defaultTextFilterConfig, + type: TEXT_TYPE, + sort: SortWay.ASC, }, { id: 'Name', field: 'name', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'VoltageLevelId', field: 'voltageLevelId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'Country', field: 'country', - ...countryEnumFilterConfig, - cellRenderer: CountryCellRenderer, + type: COUNTRY_TYPE, }, { id: 'NominalV', field: 'nominalV', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 0, + type: NUMERIC_0_FRACTION_DIGITS_TYPE, }, { id: 'HvdcLineId', field: 'hvdcLineId', - ...defaultTextFilterConfig, + type: TEXT_TYPE, }, { id: 'activePower', field: 'p', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePower', field: 'q', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, - canBeInvalidated: true, + type: [NUMERIC_1_FRACTION_DIGITS_TYPE, NUMERIC_CAN_BE_INVALIDATED_TYPE], getQuickFilterText: excludeFromGlobalFilter, }, { id: 'LossFactor', field: 'lossFactor', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'voltageRegulationOn', field: 'voltageRegulatorOn', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'VoltageSetpointKV', field: 'voltageSetpoint', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'ReactivePowerSetpointMVAR', field: 'reactivePowerSetpoint', - numeric: true, - ...defaultNumericFilterConfig, - fractionDigits: 1, + type: NUMERIC_1_FRACTION_DIGITS_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, { id: 'connected', field: 'terminalConnected', - boolean: true, - cellRenderer: BooleanCellRenderer, - ...defaultBooleanFilterConfig, + type: BOOLEAN_TYPE, getQuickFilterText: excludeFromGlobalFilter, }, genericColumnOfProperties, diff --git a/src/components/spreadsheet/config/spreadsheet.type.ts b/src/components/spreadsheet/config/spreadsheet.type.ts index 53c1181a45..871d7a462e 100644 --- a/src/components/spreadsheet/config/spreadsheet.type.ts +++ b/src/components/spreadsheet/config/spreadsheet.type.ts @@ -7,7 +7,9 @@ import type { UUID } from 'crypto'; import type { EQUIPMENT_TYPES } from '../../utils/equipment-types'; -import type { CustomAggridFilterParams, CustomColDef } from '../../custom-aggrid/custom-aggrid-header.type'; +import { ColDef, ITextFilterParams } from 'ag-grid-community'; +import { CrossValidationOptions } from '../utils/equipment-table-utils'; +import { CustomColumnConfigProps } from '../custom-columns/custom-column-menu'; export type EquipmentFetcher = (studyUuid: UUID, currentNodeUuid: UUID, substationsIds: string[]) => Promise; @@ -19,15 +21,34 @@ export type SpreadsheetEquipmentType = Exclude< | EQUIPMENT_TYPES.DISCONNECTOR >; -export interface SpreadsheetTabDefinition< - TData = any, - TValue = any, - F extends CustomAggridFilterParams = CustomAggridFilterParams -> { +export interface SpreadsheetTabDefinition { index: number; name: string; type: SpreadsheetEquipmentType; fetchers: EquipmentFetcher[]; - columns: CustomColDef[]; + columns: SpreadsheetColDef[]; groovyEquipmentGetter?: string; } + +export interface SpreadsheetColDef extends ColDef { + boolean?: boolean; + canBeInvalidated?: boolean; + changeCmd?: string; + columnWidth?: number; + crossValidation?: CrossValidationOptions; + type?: string | string[]; + filter?: string; + filterParams?: ITextFilterParams; + fractionDigits?: number; + getEnumLabel?: (value: string) => string | undefined; + id: string; + isCountry?: boolean; + isDefaultSort?: boolean; + isEnum?: boolean; + numeric?: boolean; + withFluxConvention?: boolean; + forceDisplayFilterIcon?: boolean; + tabIndex?: number; + isCustomColumn?: boolean; + Menu?: React.FC; +} diff --git a/src/components/spreadsheet/equipment-table.tsx b/src/components/spreadsheet/equipment-table.tsx index 8a550c0e46..2b5533e89d 100644 --- a/src/components/spreadsheet/equipment-table.tsx +++ b/src/components/spreadsheet/equipment-table.tsx @@ -21,6 +21,7 @@ import { } from 'ag-grid-community'; import { CurrentTreeNode } from '../../redux/reducer'; import { suppressEventsToPreventEditMode } from '../dialogs/commons/utils'; +import { useLocalizedCountries } from 'components/utils/localized-countries-hook'; const PINNED_ROW_HEIGHT = 42; const DEFAULT_ROW_HEIGHT = 28; @@ -51,6 +52,9 @@ interface EquipmentTableProps { handleRowDataUpdated: () => void; fetched: boolean; shouldHidePinnedHeaderRightBorder: boolean; + columnTypes: { [key: string]: ColDef }; + applyFluxConvention: (value: number) => number; + loadFlowStatus: string; } const loadingOverlayComponent = (props: { loadingMessage: string }) => <>{props.loadingMessage}; @@ -69,9 +73,13 @@ export const EquipmentTable: FunctionComponent = ({ handleRowDataUpdated, fetched, shouldHidePinnedHeaderRightBorder, + columnTypes, + applyFluxConvention, + loadFlowStatus, }) => { const theme = useTheme(); const intl = useIntl(); + const { translate } = useLocalizedCountries(); const getRowStyle = useCallback( (params: RowClassParams): RowStyle | undefined => { @@ -95,8 +103,12 @@ export const EquipmentTable: FunctionComponent = ({ dataToModify: topPinnedData ? JSON.parse(JSON.stringify(topPinnedData[0])) : {}, currentNode: currentNode, studyUuid: studyUuid, + intl: intl, + translateCountryCode: translate, + applyFluxConvention: applyFluxConvention, + loadFlowStatus: loadFlowStatus, }), - [currentNode, studyUuid, theme, topPinnedData] + [applyFluxConvention, currentNode, intl, loadFlowStatus, studyUuid, theme, topPinnedData, translate] ); const getRowHeight = useCallback( @@ -150,6 +162,7 @@ export const EquipmentTable: FunctionComponent = ({ loadingOverlayComponent={loadingOverlayComponent} loadingOverlayComponentParams={loadingOverlayComponentParams} showOverlay={true} + columnTypes={columnTypes} /> ); }; diff --git a/src/components/spreadsheet/table-wrapper.tsx b/src/components/spreadsheet/table-wrapper.tsx index 5b0343d716..6b8caf8f99 100644 --- a/src/components/spreadsheet/table-wrapper.tsx +++ b/src/components/spreadsheet/table-wrapper.tsx @@ -14,14 +14,8 @@ import { Theme } from '@mui/material/styles'; import { EDIT_COLUMN, MIN_COLUMN_WIDTH, REORDERED_COLUMNS_PARAMETER_PREFIX_IN_DATABASE } from './utils/constants'; import { EquipmentTable } from './equipment-table'; import { Identifiable, useSnackMessage } from '@gridsuite/commons-ui'; -import { PARAM_DEVELOPER_MODE, PARAM_FLUX_CONVENTION } from '../../utils/config-params'; -import { RunningStatus } from '../utils/running-status'; -import { - DefaultCellRenderer, - EditableCellRenderer, - EditingCellRenderer, - ReferenceLineCellRenderer, -} from './utils/cell-renderers'; +import { PARAM_DEVELOPER_MODE, PARAM_FLUX_CONVENTION, PARAM_LANGUAGE } from '../../utils/config-params'; +import { EditableCellRenderer, EditingCellRenderer, ReferenceLineCellRenderer } from './utils/cell-renderers'; import { ColumnsConfig } from './columns-config'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { GlobalFilter } from './global-filter'; @@ -52,7 +46,6 @@ import { } from 'components/utils/field-constants'; import { checkValidationsAndRefreshCells, - deepFindValue, formatFetchedEquipment, formatFetchedEquipments, updateGeneratorCells, @@ -60,16 +53,10 @@ import { updateTwtCells, } from './utils/equipment-table-utils'; import { fetchNetworkElementInfos } from 'services/study/network'; -import { toModificationOperation } from 'components/utils/utils'; import { sanitizeString } from 'components/dialogs/dialog-utils'; import { REGULATION_TYPES, SHUNT_COMPENSATOR_TYPES } from 'components/network/constants'; import ComputingType from 'components/computing-status/computing-type'; -import { makeAgGridCustomHeaderColumn } from 'components/custom-aggrid/custom-aggrid-header-utils'; -import { useAggridLocalRowFilter } from 'hooks/use-aggrid-local-row-filter'; -import { useAgGridSort } from 'hooks/use-aggrid-sort'; -import { setSpreadsheetFilter, updateEquipments } from 'redux/actions'; -import { useLocalizedCountries } from 'components/utils/localized-countries-hook'; -import { SPREADSHEET_SORT_STORE, SPREADSHEET_STORE_FIELD } from 'utils/store-sort-filter-fields'; +import { updateEquipments } from 'redux/actions'; import { useCustomColumn } from './custom-columns/use-custom-column'; import CustomColumnsConfig from './custom-columns/custom-columns-config'; import { AppState, CurrentTreeNode, EquipmentUpdateType, getUpdateTypeFromEquipmentType } from '../../redux/reducer'; @@ -83,15 +70,14 @@ import { ICellRendererParams, } from 'ag-grid-community'; import { mergeSx } from '../utils/functions'; -import { - CustomAggridFilterParams, - CustomColDef, - FILTER_NUMBER_COMPARATORS, -} from '../custom-aggrid/custom-aggrid-header.type'; +import { CustomColDef } from '../custom-aggrid/custom-aggrid-header.type'; import { FluxConventions } from '../dialogs/parameters/network-parameters'; -import { SpreadsheetEquipmentType } from './config/spreadsheet.type'; +import { SpreadsheetColDef, SpreadsheetEquipmentType } from './config/spreadsheet.type'; import SpreadsheetSave from './spreadsheet-save'; -import { CustomAggridAutocompleteFilterParams } from '../custom-aggrid/custom-aggrid-filters/custom-aggrid-autocomplete-filter'; +import { makeSpreadsheetAgGridColumn } from './config/column-aggrid-utils'; +import { toModificationOperation } from 'components/utils/utils'; +import { defaultColumnType } from './config/column-type-filter-config'; +import { useParameterState } from 'components/dialogs/parameters/parameters'; const useEditBuffer = (): [Record, (field: string, value: unknown) => void, () => void] => { //the data is fed and read during the edition validation process so we don't need to rerender after a call to one of available methods thus useRef is more suited @@ -167,12 +153,12 @@ const TableWrapper: FunctionComponent = ({ const gridRef = useRef(null); const timerRef = useRef(); const intl = useIntl(); - const { translate } = useLocalizedCountries(); const { snackError } = useSnackMessage(); const dispatch = useDispatch(); const [tabIndex, setTabIndex] = useState(0); const loadFlowStatus = useSelector((state: AppState) => state.computingStatus[ComputingType.LOAD_FLOW]); + const [languageLocal] = useParameterState(PARAM_LANGUAGE); const allDisplayedColumnsNames = useSelector((state: AppState) => state.tables.columnsNamesJson); const allLockedColumnsNames = useSelector((state: AppState) => state.allLockedColumnsNames); @@ -273,14 +259,6 @@ const TableWrapper: FunctionComponent = ({ ); }, [disabled, selectedColumnsNames, currentTabType, currentColumns]); - const { onSortChanged, sortConfig } = useAgGridSort(SPREADSHEET_SORT_STORE, currentTabName()); - - const { updateFilter, filterSelector } = useAggridLocalRowFilter(gridRef, { - filterType: SPREADSHEET_STORE_FIELD, - filterTab: currentTabName(), - filterStoreAction: setSpreadsheetFilter, - }); - const equipmentDefinition = useMemo( () => ({ type: currentTabType(), @@ -309,164 +287,24 @@ const TableWrapper: FunctionComponent = ({ formatFetchedEquipmentsHandler ); - // Function to get the columns that have isEnum filter set to true in customFilterParams - const getEnumFilterColumns = useCallback(() => { - return currentColumns().filter((c) => c.isEnum); - }, [currentColumns]); - - const generateEquipmentsFilterEnums = useCallback(() => { - if (!equipments) { - return {}; - } - const filterEnums: any = {}; - getEnumFilterColumns().forEach((column) => { - filterEnums[column.field ?? ''] = [ - ...new Set( - equipments - .map((equipment: any) => deepFindValue(equipment, column.field)) - .filter((value: any) => value != null) - ), - ]; - }); - return filterEnums; - }, [getEnumFilterColumns, equipments]); - - const filterEnums = useMemo(() => generateEquipmentsFilterEnums(), [generateEquipmentsFilterEnums]); - const enrichColumn = useCallback( - (column: CustomColDef) => { + (column: SpreadsheetColDef) => { 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; - }; - // redefine agGrid predicates to possibly invert sign depending on flux convention (called when we use useAggridLocalRowFilter). - columnExtended.agGridFilterParams = { - filterOptions: [ - { - displayKey: FILTER_NUMBER_COMPARATORS.GREATER_THAN_OR_EQUAL, - displayName: FILTER_NUMBER_COMPARATORS.GREATER_THAN_OR_EQUAL, - predicate: (filterValues: number[], cellValue: number) => { - const filterValue = filterValues.at(0); - if (filterValue === undefined) { - return false; - } - const transformedValue = applyFluxConvention(cellValue); - return transformedValue != null ? transformedValue >= filterValue : false; - }, - }, - { - displayKey: FILTER_NUMBER_COMPARATORS.LESS_THAN_OR_EQUAL, - displayName: FILTER_NUMBER_COMPARATORS.LESS_THAN_OR_EQUAL, - predicate: (filterValues: number[], cellValue: number) => { - const filterValue = filterValues.at(0); - if (filterValue === undefined) { - return false; - } - const transformedValue = applyFluxConvention(cellValue); - return transformedValue != null ? transformedValue <= filterValue : false; - }, - }, - ], - }; - } - } - - 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; - columnExtended.filterComponentParams = { - filterParams: { - updateFilter, - filterSelector, - ...columnExtended?.filterComponentParams?.filterParams, - }, - }; - - //Set sorting comparator for enum columns so it sorts the translated values instead of the enum values - if (columnExtended?.isEnum) { - 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; - }; - - columnExtended.comparator = (valueA: string, valueB: string) => { - const translatedValueA = getTranslatedOrOriginalValue(valueA); - const translatedValueB = getTranslatedOrOriginalValue(valueB); - - return translatedValueA.localeCompare(translatedValueB); - }; - - columnExtended.filterComponentParams = { - ...columnExtended.filterComponentParams, - filterEnums: filterEnums, - getEnumLabel: getTranslatedOrOriginalValue, - }; - } - - return makeAgGridCustomHeaderColumn({ + return makeSpreadsheetAgGridColumn({ headerName: columnExtended.headerName, field: columnExtended.field, - sortProps: { - onSortChanged, - sortConfig, - }, ...columnExtended, }); }, - [ - intl, - lockedColumnsNames, - updateFilter, - filterSelector, - filterEnums, - translate, - onSortChanged, - sortConfig, - loadFlowStatus, - applyFluxConvention, - ] + [intl, lockedColumnsNames] ); useEffect(() => { if (errorMessage) { @@ -477,14 +315,6 @@ const TableWrapper: FunctionComponent = ({ } }, [errorMessage, snackError]); - // Ensure initial sort is applied by including mergedColumnData in dependencies - useEffect(() => { - gridRef.current?.api?.applyColumnState({ - state: sortConfig, - defaultState: { sort: null }, - }); - }, [sortConfig, mergedColumnData]); - useEffect(() => { if (disabled || !equipments) { return; @@ -1245,6 +1075,10 @@ const TableWrapper: FunctionComponent = ({ setColumnData(generateTableColumns()); }, [generateTableColumns]); + useEffect(() => { + gridRef.current?.api?.setFilterModel(null); + }, [languageLocal]); + const topPinnedData = useMemo((): any[] | undefined => { if (editingData) { editingDataRef.current = { ...editingData }; @@ -1315,6 +1149,9 @@ const TableWrapper: FunctionComponent = ({ handleGridReady={handleGridReady} handleRowDataUpdated={handleRowDataUpdated} 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..40a88559fa 100644 --- a/src/components/spreadsheet/utils/cell-renderers.tsx +++ b/src/components/spreadsheet/utils/cell-renderers.tsx @@ -107,9 +107,7 @@ export const formatCell = (props: any) => { ? props.colDef.valueGetter(props, props.context.network) : props.colDef.valueGetter(props); } - if (props.applyFluxConvention) { - value = props.applyFluxConvention(value); - } + if (value != null && props.colDef.numeric && props.colDef.fractionDigits) { // only numeric rounded cells have a tooltip (their raw numeric value) tooltipValue = value; @@ -142,6 +140,7 @@ export const convertDuration = (duration: number) => { export const DefaultCellRenderer = (props: any) => { const cellValue = formatCell(props); + return ( { title={cellValue.tooltip ? cellValue.tooltip : cellValue.value} > @@ -161,6 +157,23 @@ export const DefaultCellRenderer = (props: any) => { ); }; +export const DefaultSpreadsheetCellRenderer = (params: any) => { + return ( + + + + + + ); +}; + export const MessageLogCellRenderer = ({ param, highlightColor, @@ -252,20 +265,17 @@ export const MessageLogCellRenderer = ({ ); }; -export const PropertiesCellRenderer = (props: any) => { - const cellValue = formatCell(props); +export const PropertiesCellRenderer = (params: any) => { // different properties are seperated with | // tooltip message contains properties in seperated lines return ( - {cellValue.value && cellValue.value.replaceAll(' | ', '\n')} - +
{params.value && params.value.replaceAll(' | ', '\n')}
} > - +
); diff --git a/src/components/spreadsheet/utils/constants.ts b/src/components/spreadsheet/utils/constants.ts index 5ebcdb6ae1..fcbe9d56b5 100644 --- a/src/components/spreadsheet/utils/constants.ts +++ b/src/components/spreadsheet/utils/constants.ts @@ -14,3 +14,32 @@ export const EDIT_COLUMN = 'edit'; export const DISPLAYED_COLUMNS_PARAMETER_PREFIX_IN_DATABASE = 'displayedColumns.'; export const LOCKED_COLUMNS_PARAMETER_PREFIX_IN_DATABASE = 'lockedColumns.'; export const REORDERED_COLUMNS_PARAMETER_PREFIX_IN_DATABASE = 'reorderedColumns.'; + +export const TEXT_TYPE = 'textType'; +export const NUMERIC_TYPE = 'numericType'; +export const NUMERIC_0_FRACTION_DIGITS_TYPE = 'numeric0FractionDigitsType'; +export const NUMERIC_1_FRACTION_DIGITS_TYPE = 'numeric1FractionDigitsType'; +export const NUMERIC_2_FRACTION_DIGITS_TYPE = 'numeric2FractionDigitsType'; +export const NUMERIC_5_FRACTION_DIGITS_TYPE = 'numeric5FractionDigitsType'; +export const NUMERIC_UNIT_TO_MICRO_UNIT_TYPE = 'numericUnitToMicroUnitType'; +export const NUMERIC_UNIT_TO_KILO_UNIT_TYPE = 'numericUnitToKiloUnitType'; + +export const NUMERIC_APPLY_FLUX_CONVENTION_TYPE = 'numericApplyFluxConventionType'; +export const NUMERIC_APPLY_FLUX_CONVENTION_1_FRACTION_DIGITS_TYPE = 'numericApplyFluxConvention1FractionDigitsType'; +export const NUMERIC_APPLY_FLUX_CONVENTION_2_FRACTION_DIGITS_TYPE = 'numericApplyFluxConvention2FractionDigitsType'; +export const NUMERIC_APPLY_FLUX_CONVENTION_5_FRACTION_DIGITS_TYPE = 'numericApplyFluxConvention5FractionDigitsType'; + +export const NUMERIC_CAN_BE_INVALIDATED_TYPE = 'numericCanBeInvalidatedType'; +export const ENUM_TYPE = 'enumType'; +export const BOOLEAN_TYPE = 'booleanType'; +export const COUNTRY_TYPE = 'countryType'; +export const ENERGY_SOURCE_ENUM_TYPE = 'energySourceEnumType'; +export const REGULATION_ENUM_TYPE = 'regulationEnumType'; +export const LOAD_ENUM_TYPE = 'loadEnumType'; +export const SHUNT_COMPENSATOR_ENUM_TYPE = 'shuntCompensatorEnumType'; +export const RATIO_REGULATION_MODES_ENUM_TYPE = 'ratioRegulationModesEnumType'; +export const SIDE_ENUM_TYPE = 'sideEnumType'; +export const PHASE_REGULATING_MODE_ENUM_TYPE = 'phaseRegulatingModeEnumType'; +export const NUMERIC_HIGH_TAP_POSITION_TYPE = 'numericHighTapPositionType'; +export const NUMERIC_SWITCHED_ON_SUSCEPTANCE_TYPE = 'numericSwitchedOnSusceptanceType'; +export const NUMERIC_SWITCHED_ON_Q_AT_NOMINAL_V_TYPE = 'numericSwitchedOnQAtNominalVType'; diff --git a/src/components/spreadsheet/utils/equipment-table-utils.ts b/src/components/spreadsheet/utils/equipment-table-utils.ts index eeaafce808..af75b93ba8 100644 --- a/src/components/spreadsheet/utils/equipment-table-utils.ts +++ b/src/components/spreadsheet/utils/equipment-table-utils.ts @@ -27,6 +27,7 @@ import { import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { Identifiable } from '@gridsuite/commons-ui'; import { CustomColDef } from '../../custom-aggrid/custom-aggrid-header.type'; +import { isNumericType } from '../config/column-type-filter-config'; type DynamicValidation = Record; @@ -368,9 +369,10 @@ export const deepUpdateValue = (obj: any, path: any, value: any) => { }; const isValueValid = (fieldVal: any, colDef: any, gridContext: any) => { - if (fieldVal === undefined || fieldVal === null || fieldVal === '' || (isNaN(fieldVal) && colDef.numeric)) { + const isNumeric = isNumericType(colDef.type); + if (fieldVal === undefined || fieldVal === null || fieldVal === '' || (isNaN(fieldVal) && isNumeric)) { let originalValue = deepFindValue(gridContext.dataToModify, colDef.field); - originalValue = colDef.numeric && isNaN(originalValue) ? undefined : originalValue; + originalValue = isNumeric && isNaN(originalValue) ? undefined : originalValue; // if the original value is not undefined, we don't let the user empty the field unless we have // another condition that verifies that the field can be empty (requiredOn, optional, etc.) @@ -383,7 +385,7 @@ const isValueValid = (fieldVal: any, colDef: any, gridContext: any) => { if (!isConditionFulfiled) { return false; } - } else if (colDef.numeric) { + } else if (isNumeric) { return false; } }