Skip to content

Commit

Permalink
Merge branch 'main' into handle_maintenance_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelHedhili authored Feb 8, 2024
2 parents c7391e4 + 8b3514c commit 3c39568
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const CriteriaBasedForm = ({ equipments, defaultValues }) => {
shouldOpenPopup={openConfirmationPopup}
resetOnConfirmation={handleResetOnConfirmation}
message={'changeTypeMessage'}
validateButtonLabel={'button.changeType'}
/>
);

Expand Down
1 change: 0 additions & 1 deletion src/components/dialogs/delete-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const DeleteDialog = ({
itemName: (
<OverflowableText
text={items[0].elementName}
style={{ marginLeft: '1%' }}
tooltipSx={styles.tooltip}
/>
),
Expand Down
107 changes: 107 additions & 0 deletions src/components/dialogs/filter/expert/expert-filter-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export const EXPERT_FILTER_EQUIPMENTS = {
id: 'SHUNT_COMPENSATOR',
label: 'ShuntCompensators',
},
LINE: {
id: 'LINE',
label: 'Lines',
},
};

export const ENERGY_SOURCE_OPTIONS = [
Expand Down Expand Up @@ -292,6 +296,90 @@ export const FIELDS_OPTIONS = {
dataType: DataType.NUMBER,
inputType: 'number',
},
CONNECTED_1: {
name: FieldType.CONNECTED_1,
label: 'terminal1Connected',
dataType: DataType.BOOLEAN,
valueEditorType: 'switch',
},
CONNECTED_2: {
name: FieldType.CONNECTED_2,
label: 'terminal2Connected',
dataType: DataType.BOOLEAN,
valueEditorType: 'switch',
},
VOLTAGE_LEVEL_ID_1: {
name: FieldType.VOLTAGE_LEVEL_ID_1,
label: 'voltageLevelId1',
dataType: DataType.STRING,
},
VOLTAGE_LEVEL_ID_2: {
name: FieldType.VOLTAGE_LEVEL_ID_2,
label: 'voltageLevelId2',
dataType: DataType.STRING,
},
NOMINAL_VOLTAGE_1: {
name: FieldType.NOMINAL_VOLTAGE_1,
label: 'nominalVoltage1Or',
dataType: DataType.NUMBER,
inputType: 'number',
},
NOMINAL_VOLTAGE_2: {
name: FieldType.NOMINAL_VOLTAGE_2,
label: 'nominalVoltage2Ex',
dataType: DataType.NUMBER,
inputType: 'number',
},
COUNTRY_1: {
name: FieldType.COUNTRY_1,
label: 'country1',
dataType: DataType.ENUM,
valueEditorType: 'select',
defaultValue: 'AF',
},
COUNTRY_2: {
name: FieldType.COUNTRY_2,
label: 'country2',
dataType: DataType.ENUM,
valueEditorType: 'select',
defaultValue: 'AF',
},
SERIE_RESISTANCE: {
name: FieldType.SERIE_RESISTANCE,
label: 'seriesResistance',
dataType: DataType.NUMBER,
inputType: 'number',
},
SERIE_REACTANCE: {
name: FieldType.SERIE_REACTANCE,
label: 'seriesReactance',
dataType: DataType.NUMBER,
inputType: 'number',
},
SHUNT_CONDUCTANCE_1: {
name: FieldType.SHUNT_CONDUCTANCE_1,
label: 'shuntConductance1',
dataType: DataType.NUMBER,
inputType: 'number',
},
SHUNT_CONDUCTANCE_2: {
name: FieldType.SHUNT_CONDUCTANCE_2,
label: 'shuntConductance2',
dataType: DataType.NUMBER,
inputType: 'number',
},
SHUNT_SUSCEPTANCE_1: {
name: FieldType.SHUNT_SUSCEPTANCE_1,
label: 'shuntSusceptance1',
dataType: DataType.NUMBER,
inputType: 'number',
},
SHUNT_SUSCEPTANCE_2: {
name: FieldType.SHUNT_SUSCEPTANCE_2,
label: 'shuntSusceptance2',
dataType: DataType.NUMBER,
inputType: 'number',
},
};

export const fields: Record<string, Field[]> = {
Expand Down Expand Up @@ -323,6 +411,7 @@ export const fields: Record<string, Field[]> = {
FIELDS_OPTIONS.COUNTRY,
FIELDS_OPTIONS.P0,
FIELDS_OPTIONS.Q0,
FIELDS_OPTIONS.CONNECTED,
],
SHUNT_COMPENSATOR: [
FIELDS_OPTIONS.ID,
Expand Down Expand Up @@ -364,4 +453,22 @@ export const fields: Record<string, Field[]> = {
FIELDS_OPTIONS.NAME,
FIELDS_OPTIONS.COUNTRY,
],
LINE: [
FIELDS_OPTIONS.ID,
FIELDS_OPTIONS.NAME,
FIELDS_OPTIONS.CONNECTED_1,
FIELDS_OPTIONS.CONNECTED_2,
FIELDS_OPTIONS.VOLTAGE_LEVEL_ID_1,
FIELDS_OPTIONS.VOLTAGE_LEVEL_ID_2,
FIELDS_OPTIONS.NOMINAL_VOLTAGE_1,
FIELDS_OPTIONS.NOMINAL_VOLTAGE_2,
FIELDS_OPTIONS.COUNTRY_1,
FIELDS_OPTIONS.COUNTRY_2,
FIELDS_OPTIONS.SERIE_RESISTANCE,
FIELDS_OPTIONS.SERIE_REACTANCE,
FIELDS_OPTIONS.SHUNT_CONDUCTANCE_1,
FIELDS_OPTIONS.SHUNT_CONDUCTANCE_2,
FIELDS_OPTIONS.SHUNT_SUSCEPTANCE_1,
FIELDS_OPTIONS.SHUNT_SUSCEPTANCE_2,
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function ExpertFilterForm() {
shouldOpenPopup={openConfirmationPopup}
resetOnConfirmation={handleResetOnConfirmation}
message={'changeTypeMessage'}
validateButtonLabel={'button.changeType'}
/>
</Grid>
{watchEquipmentType &&
Expand Down
34 changes: 31 additions & 3 deletions src/components/dialogs/filter/expert/expert-filter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ import {
RuleGroupTypeExport,
RuleTypeExport,
} from './expert-filter.type';
import { microUnitToUnit, unitToMicroUnit } from 'utils/conversion-utils';

type CustomRuleType = RuleType & { dataType: DataType };
type CustomRuleGroupType = RuleGroupType & { dataType: DataType };

const microUnits = [
FieldType.SHUNT_CONDUCTANCE_1,
FieldType.SHUNT_CONDUCTANCE_2,
FieldType.SHUNT_SUSCEPTANCE_1,
FieldType.SHUNT_SUSCEPTANCE_2,
];

const getDataType = (fieldName: string) => {
const field = Object.values(FIELDS_OPTIONS).find(
(field) => field.name === fieldName
Expand Down Expand Up @@ -93,6 +101,17 @@ export const getOperators = (fieldName: string, intl: IntlShape) => {
return defaultOperators;
};

function changeValueUnit(value: any, field: FieldType) {
if (microUnits.includes(field)) {
if (!Array.isArray(value)) {
return microUnitToUnit(value);
} else {
return value.map((a: number) => microUnitToUnit(a));
}
}
return value;
}

export function exportExpertRules(
query: CustomRuleGroupType
): RuleGroupTypeExport {
Expand All @@ -105,9 +124,11 @@ export function exportExpertRules(
)?.customName as OperatorType,
value:
!isValueAnArray && rule.operator !== OperatorType.EXISTS
? rule.value
? changeValueUnit(rule.value, rule.field as FieldType)
: undefined,
values: isValueAnArray ? rule.value : undefined,
values: isValueAnArray
? changeValueUnit(rule.value, rule.field as FieldType)
: undefined,
dataType: getDataType(rule.field) as DataType,
};
}
Expand Down Expand Up @@ -141,12 +162,19 @@ export function importExpertRules(
if (rule.dataType === DataType.NUMBER) {
return rule.values
.map((value) => parseFloat(value as string))
.map((numberValue) => {
return microUnits.includes(rule.field)
? unitToMicroUnit(numberValue)!
: numberValue;
})
.sort((a, b) => a - b);
} else {
return rule.values.sort();
}
} else {
return rule.value;
return microUnits.includes(rule.field)
? unitToMicroUnit(parseFloat(rule.value as string))
: rule.value;
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/components/dialogs/filter/expert/expert-filter.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ export enum FieldType {
SWITCHED_ON_Q_AT_NOMINAL_V = 'SWITCHED_ON_Q_AT_NOMINAL_V',
MAX_SUSCEPTANCE = 'MAX_SUSCEPTANCE',
SWITCHED_ON_SUSCEPTANCE = 'SWITCHED_ON_SUSCEPTANCE',
CONNECTED_1 = 'CONNECTED_1',
CONNECTED_2 = 'CONNECTED_2',
VOLTAGE_LEVEL_ID_1 = 'VOLTAGE_LEVEL_ID_1',
VOLTAGE_LEVEL_ID_2 = 'VOLTAGE_LEVEL_ID_2',
NOMINAL_VOLTAGE_1 = 'NOMINAL_VOLTAGE_1',
NOMINAL_VOLTAGE_2 = 'NOMINAL_VOLTAGE_2',
COUNTRY_1 = 'COUNTRY_1',
COUNTRY_2 = 'COUNTRY_2',
SERIE_RESISTANCE = 'SERIE_RESISTANCE',
SERIE_REACTANCE = 'SERIE_REACTANCE',
SHUNT_CONDUCTANCE_1 = 'SHUNT_CONDUCTANCE_1',
SHUNT_CONDUCTANCE_2 = 'SHUNT_CONDUCTANCE_2',
SHUNT_SUSCEPTANCE_1 = 'SHUNT_SUSCEPTANCE_1',
SHUNT_SUSCEPTANCE_2 = 'SHUNT_SUSCEPTANCE_2',
}

export enum DataType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ function ExplicitNamingFilterForm() {
shouldOpenPopup={openConfirmationPopup}
resetOnConfirmation={handleResetOnConfirmation}
message={'changeTypeMessage'}
validateButtonLabel={'button.changeType'}
/>
</Grid>
{watchEquipmentType && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/replace-with-script-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ReplaceWithScriptDialog = ({ id, open, onClose, onClick, title }) => {
<DialogActions>
<CancelButton onClick={handleClose} />
<Button onClick={handleClick} variant="outlined">
<FormattedMessage id="validate" />
<FormattedMessage id="button.replace" />
</Button>
</DialogActions>
</Dialog>
Expand Down
7 changes: 6 additions & 1 deletion src/components/utils/popup-confirmation-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CancelButton } from '@gridsuite/commons-ui';

const PopupConfirmationDialog = ({
message,
validateButtonLabel,
openConfirmationPopup,
setOpenConfirmationPopup,
handlePopupConfirmation,
Expand All @@ -37,11 +38,15 @@ const PopupConfirmationDialog = ({
<DialogActions>
<CancelButton onClick={() => setOpenConfirmationPopup(false)} />
<Button onClick={handlePopupConfirmation} variant="outlined">
<FormattedMessage id="validate" />
<FormattedMessage id={validateButtonLabel ?? 'validate'} />
</Button>
</DialogActions>
</Dialog>
);
};

PopupConfirmationDialog.defaultProps = {
validateButtonLabel: undefined,
};

export default PopupConfirmationDialog;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const InputWithPopupConfirmation = ({
shouldOpenPopup, // condition to open popup confirmation
resetOnConfirmation, // function to reset values in your form on confirmation,
message,
validateButtonLabel,
...props
}) => {
const [newValue, setNewValue] = useState(null);
Expand Down Expand Up @@ -47,9 +48,14 @@ const InputWithPopupConfirmation = ({
openConfirmationPopup={openPopup}
setOpenConfirmationPopup={setOpenPopup}
handlePopupConfirmation={handlePopupConfirmation}
validateButtonLabel={validateButtonLabel}
/>
</>
);
};

InputWithPopupConfirmation.defaultProps = {
validateButtonLabel: undefined,
};

export default InputWithPopupConfirmation;
1 change: 1 addition & 0 deletions src/components/utils/rqb-inputs/combinator-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const CombinatorSelector = (props: CombinatorSelectorProps) => {
<>
<PopupConfirmationDialog
message={'changeOperatorMessage'}
validateButtonLabel={'button.changeOperator'}
openConfirmationPopup={openPopup}
setOpenConfirmationPopup={setOpenPopup}
handlePopupConfirmation={handlePopupConfirmation}
Expand Down
6 changes: 5 additions & 1 deletion src/components/utils/rqb-inputs/value-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ const ValueEditor = (props: ValueEditorProps) => {
// No value needed for this operator
return null;
}
if (props.field === FieldType.COUNTRY) {
if (
[FieldType.COUNTRY, FieldType.COUNTRY_1, FieldType.COUNTRY_2].includes(
props.field as FieldType
)
) {
return <CountryValueEditor {...props} />;
}
if (
Expand Down
Loading

0 comments on commit 3c39568

Please sign in to comment.