Skip to content

Commit

Permalink
improve columnTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
anistouri committed Dec 17, 2024
1 parent 06ffdaf commit eb2f1e2
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 182 deletions.
47 changes: 21 additions & 26 deletions src/components/spreadsheet/config/column-type-filter-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CountryCellRenderer from '../utils/country-cell-render';
import { BooleanCellRenderer, DefaultCellRenderer } from '../utils/cell-renderers';
import EnumCellRenderer from '../utils/enum-cell-renderer';
import { Writable } from 'type-fest';
import RunningStatus from 'components/utils/running-status';

const contains = (target: string, lookingFor: string): boolean => {
if (target && lookingFor) {
Expand Down Expand Up @@ -55,12 +56,7 @@ const textType = {
maxNumConditions: 1,
filterOptions: [FILTER_TEXT_COMPARATORS.STARTS_WITH, FILTER_TEXT_COMPARATORS.CONTAINS],
},
cellRendererSelector: (props: any) => {
return {
component: DefaultCellRenderer,
props: props,
};
},
cellRenderer: DefaultCellRenderer,
sortable: true,
resizable: true,
};
Expand All @@ -72,28 +68,32 @@ const numericType = {
filterOptions: Object.values(FILTER_NUMBER_COMPARATORS),
debounceMs: 200,
},
cellRendererSelector: (props: any) => {
cellRenderer: DefaultCellRenderer,
sortable: true,
resizable: true,
};

const numericCanBeInvalidatedType = {
filter: 'agNumberColumnFilter',
filterParams: {
maxNumConditions: 1,
filterOptions: Object.values(FILTER_NUMBER_COMPARATORS),
debounceMs: 200,
},
cellRendererSelector: ({ context }: { context: any }) => {
return {
component: DefaultCellRenderer,
props: {
isValueInvalid: props.colDef.cellRendererParams.colisValueInvalid,
applyFluxConvention: props.context.applyFluxConvention,
params: {
isValueInvalid: context.loadFlowStatus !== RunningStatus.SUCCEED,
},
};
},

sortable: true,
resizable: true,
};

const booleanType = {
cellRendererSelector: ({ value }: { value: string }) => {
return {
component: BooleanCellRenderer,
props: {
value,
},
};
},
filter: 'agTextColumnFilter',
filterParams: {
caseSensitive: false,
Expand All @@ -108,19 +108,12 @@ const booleanType = {
},
debounceMs: 200,
},
cellRenderer: BooleanCellRenderer,
sortable: true,
resizable: true,
};

const countryType = {
cellRendererSelector: ({ value }: { value: string }) => {
return {
component: CountryCellRenderer,
params: {
value,
},
};
},
filter: 'agTextColumnFilter',
filterParams: {
caseSensitive: false,
Expand All @@ -136,13 +129,15 @@ const countryType = {
},
debounceMs: 200,
},
cellRenderer: CountryCellRenderer,
sortable: true,
resizable: true,
};

export const defaultColumnType = {
textType,
numericType,
numericCanBeInvalidatedType,
booleanType,
countryType,
};
22 changes: 15 additions & 7 deletions src/components/spreadsheet/config/equipment/battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from '
import type { SpreadsheetTabDefinition } from '../spreadsheet.type';
import { genericColumnOfPropertiesEditPopup } from '../common/column-properties';
import { booleanCellEditorConfig, numericalCellEditorConfig } from '../common/cell-editors';
import { BOOLEAN_TYPE, COUNTRY_TYPE, NUMERIC_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants';
import {
BOOLEAN_TYPE,
COUNTRY_TYPE,
NUMERIC_CAN_BE_INVALIDATED_TYPE,
NUMERIC_TYPE,
TEXT_TYPE,
} from 'components/spreadsheet/utils/constants';
import { SortWay } from 'hooks/use-aggrid-sort';

export const BATTERY_TAB_DEF = {
Expand Down Expand Up @@ -54,19 +60,21 @@ export const BATTERY_TAB_DEF = {
field: 'p',
numeric: true,
fractionDigits: 1,
type: NUMERIC_TYPE,
canBeInvalidated: true,
withFluxConvention: true,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
valueGetter: (params) => {
return params.context.applyFluxConvention(params.data.p);
},
getQuickFilterText: excludeFromGlobalFilter,
},
{
id: 'ReactivePower',
field: 'q',
numeric: true,
fractionDigits: 1,
type: NUMERIC_TYPE,
canBeInvalidated: true,
withFluxConvention: true,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
valueGetter: (params) => {
return params.context.applyFluxConvention(params.data.q);
},
getQuickFilterText: excludeFromGlobalFilter,
},
{
Expand Down
13 changes: 8 additions & 5 deletions src/components/spreadsheet/config/equipment/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import type { SpreadsheetTabDefinition } from '../spreadsheet.type';
import { EQUIPMENT_TYPES } from '../../../utils/equipment-types';
import { typeAndFetchers } from './common-config';
import { genericColumnOfProperties } from '../common/column-properties';
import { COUNTRY_TYPE, NUMERIC_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants';
import {
COUNTRY_TYPE,
NUMERIC_CAN_BE_INVALIDATED_TYPE,
NUMERIC_TYPE,
TEXT_TYPE,
} from 'components/spreadsheet/utils/constants';
import { SortWay } from 'hooks/use-aggrid-sort';

export const BUS_TAB_DEF = {
Expand All @@ -29,16 +34,14 @@ export const BUS_TAB_DEF = {
field: 'v',
numeric: true,
fractionDigits: 1,
canBeInvalidated: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
},
{
id: 'Angle',
field: 'angle',
numeric: true,
fractionDigits: 1,
canBeInvalidated: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
},
{
id: 'ConnectedComponent',
Expand Down
14 changes: 9 additions & 5 deletions src/components/spreadsheet/config/equipment/dangling-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { EQUIPMENT_TYPES } from '../../../utils/equipment-types';
import { excludeFromGlobalFilter, typeAndFetchers } from './common-config';
import { NOMINAL_V } from '../../../utils/field-constants';
import { genericColumnOfProperties } from '../common/column-properties';
import { BOOLEAN_TYPE, COUNTRY_TYPE, NUMERIC_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants';
import {
BOOLEAN_TYPE,
COUNTRY_TYPE,
NUMERIC_CAN_BE_INVALIDATED_TYPE,
NUMERIC_TYPE,
TEXT_TYPE,
} from 'components/spreadsheet/utils/constants';
import { SortWay } from 'hooks/use-aggrid-sort';

export const DANGLING_LINE_TAB_DEF = {
Expand Down Expand Up @@ -57,18 +63,16 @@ export const DANGLING_LINE_TAB_DEF = {
id: 'activePower',
field: 'p',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
id: 'ReactivePower',
field: 'q',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
Expand Down
24 changes: 17 additions & 7 deletions src/components/spreadsheet/config/equipment/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ import {
} from '../../utils/equipment-table-editors';
import type { EditableCallback, ValueGetterFunc } from 'ag-grid-community';
import { editableCellStyle, editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config';
import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants';
import {
BOOLEAN_TYPE,
COUNTRY_TYPE,
MEDIUM_COLUMN_WIDTH,
NUMERIC_CAN_BE_INVALIDATED_TYPE,
NUMERIC_TYPE,
TEXT_TYPE,
} from '../../utils/constants';
import { ENERGY_SOURCES, REGULATION_TYPES } from '../../../network/constants';
import { genericColumnOfPropertiesEditPopup } from '../common/column-properties';
import {
Expand Down Expand Up @@ -99,19 +106,22 @@ export const GENERATOR_TAB_DEF = {
field: 'p',
numeric: true,
fractionDigits: 1,
type: NUMERIC_TYPE,
canBeInvalidated: true,
withFluxConvention: true,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
valueGetter: (params) => {
return params.context.applyFluxConvention(params.data.p);
},
getQuickFilterText: excludeFromGlobalFilter,
},
{
id: 'ReactivePower',
field: 'q',
numeric: true,
fractionDigits: 1,
type: NUMERIC_TYPE,
canBeInvalidated: true,
withFluxConvention: true,

type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
valueGetter: (params) => {
return params.context.applyFluxConvention(params.data.p);
},
getQuickFilterText: excludeFromGlobalFilter,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import type { SpreadsheetTabDefinition } from '../spreadsheet.type';
import { EQUIPMENT_TYPES } from '../../../utils/equipment-types';
import { excludeFromGlobalFilter, typeAndFetchers } from './common-config';
import { genericColumnOfProperties } from '../common/column-properties';
import { BOOLEAN_TYPE, COUNTRY_TYPE, NUMERIC_TYPE, TEXT_TYPE } from 'components/spreadsheet/utils/constants';
import {
BOOLEAN_TYPE,
COUNTRY_TYPE,
NUMERIC_CAN_BE_INVALIDATED_TYPE,
NUMERIC_TYPE,
TEXT_TYPE,
} from 'components/spreadsheet/utils/constants';
import { SortWay } from 'hooks/use-aggrid-sort';

export const LCC_CONVERTER_STATION_TAB_DEF = {
Expand Down Expand Up @@ -55,18 +61,16 @@ export const LCC_CONVERTER_STATION_TAB_DEF = {
id: 'activePower',
field: 'p',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
id: 'ReactivePower',
field: 'q',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
Expand Down
25 changes: 15 additions & 10 deletions src/components/spreadsheet/config/equipment/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import type { SpreadsheetTabDefinition } from '../spreadsheet.type';
import { EQUIPMENT_TYPES } from '../../../utils/equipment-types';
import CountryCellRenderer from '../../utils/country-cell-render';
import { excludeFromGlobalFilter, typeAndFetchers } from './common-config';
import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants';
import {
BOOLEAN_TYPE,
COUNTRY_TYPE,
MEDIUM_COLUMN_WIDTH,
NUMERIC_CAN_BE_INVALIDATED_TYPE,
NUMERIC_TYPE,
TEXT_TYPE,
} from '../../utils/constants';
import { unitToMicroUnit } from '../../../../utils/unit-converter';
import { genericColumnOfProperties } from '../common/column-properties';
import { SortWay } from 'hooks/use-aggrid-sort';
Expand Down Expand Up @@ -72,37 +79,35 @@ export const LINE_TAB_DEF = {
id: 'ActivePowerSide1',
field: 'p1',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
withFluxConvention: true,
valueGetter: (params) => {
return params.context.applyFluxConvention(params.data.p1);
},
getQuickFilterText: excludeFromGlobalFilter,
},
{
id: 'ActivePowerSide2',
field: 'p2',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
id: 'ReactivePowerSide1',
field: 'q1',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
id: 'ReactivePowerSide2',
field: 'q2',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
Expand Down
15 changes: 10 additions & 5 deletions src/components/spreadsheet/config/equipment/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import type { ReadonlyDeep } from 'type-fest';
import type { SpreadsheetTabDefinition } from '../spreadsheet.type';
import { EQUIPMENT_TYPES } from '../../../utils/equipment-types';
import { editableColumnConfig, excludeFromGlobalFilter, typeAndFetchers } from './common-config';
import { BOOLEAN_TYPE, COUNTRY_TYPE, MEDIUM_COLUMN_WIDTH, NUMERIC_TYPE, TEXT_TYPE } from '../../utils/constants';
import {
BOOLEAN_TYPE,
COUNTRY_TYPE,
MEDIUM_COLUMN_WIDTH,
NUMERIC_CAN_BE_INVALIDATED_TYPE,
NUMERIC_TYPE,
TEXT_TYPE,
} from '../../utils/constants';
import { LOAD_TYPES } from '../../../network/constants';
import { genericColumnOfPropertiesEditPopup } from '../common/column-properties';
import { enumCellEditorConfig, numericalCellEditorConfig } from '../common/cell-editors';
Expand Down Expand Up @@ -66,18 +73,16 @@ export const LOAD_TAB_DEF = {
id: 'activePower',
field: 'p',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
id: 'ReactivePower',
field: 'q',
numeric: true,
type: NUMERIC_TYPE,
type: NUMERIC_CAN_BE_INVALIDATED_TYPE,
fractionDigits: 1,
canBeInvalidated: true,
getQuickFilterText: excludeFromGlobalFilter,
},
{
Expand Down
Loading

0 comments on commit eb2f1e2

Please sign in to comment.