Skip to content

Commit c7e5e7c

Browse files
committed
clean code and use simple click to edit profile
Signed-off-by: David BRAQUART <[email protected]>
1 parent ad0c954 commit c7e5e7c

File tree

5 files changed

+25
-52
lines changed

5 files changed

+25
-52
lines changed

src/pages/groups/add-group-dialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '@mui/material';
1919
import { FormattedMessage } from 'react-intl';
2020
import { Controller, useForm } from 'react-hook-form';
21-
import { ManageAccounts } from '@mui/icons-material';
21+
import { Groups } from '@mui/icons-material';
2222
import { GroupInfos, UserAdminSrv } from '../../services';
2323
import { useSnackMessage } from '@gridsuite/commons-ui';
2424
import { GridTableRef } from '../../components/Grid';
@@ -99,7 +99,7 @@ const AddGroupDialog: FunctionComponent<AddGroupDialogProps> = (props) => {
9999
InputProps={{
100100
startAdornment: (
101101
<InputAdornment position="start">
102-
<ManageAccounts />
102+
<Groups />
103103
</InputAdornment>
104104
),
105105
}}

src/pages/profiles/modification/linked-path-display.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ const LinkedPathDisplay: FunctionComponent<LinkedPathDisplayProps> = (props) =>
3030
id: props.nameKey,
3131
}) +
3232
' : ' +
33-
(props.value
34-
? props.value
35-
: intl.formatMessage({
36-
id:
37-
props.linkValidity === false
38-
? 'linked.path.display.invalidLink'
39-
: 'linked.path.display.noLink',
40-
}))}
33+
(props.value ??
34+
intl.formatMessage({
35+
id:
36+
props.linkValidity === false
37+
? 'linked.path.display.invalidLink'
38+
: 'linked.path.display.noLink',
39+
}))}
4140
</Typography>
4241
);
4342
};

src/pages/profiles/modification/profile-modification-dialog.tsx

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,10 @@ import yup from '../../../utils/yup-config';
2121
import { yupResolver } from '@hookform/resolvers/yup';
2222
import { useForm } from 'react-hook-form';
2323
import { FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react';
24-
import { CustomMuiDialog, useSnackMessage } from '@gridsuite/commons-ui';
24+
import { CustomMuiDialog, FetchStatus, useSnackMessage } from '@gridsuite/commons-ui';
2525
import { UserAdminSrv, UserProfile } from '../../../services';
2626
import { UUID } from 'crypto';
2727

28-
// TODO remove FetchStatus when exported in commons-ui (available soon)
29-
enum FetchStatus {
30-
IDLE = 'IDLE',
31-
FETCHING = 'FETCHING',
32-
FETCH_SUCCESS = 'FETCH_SUCCESS',
33-
FETCH_ERROR = 'FETCH_ERROR',
34-
}
35-
3628
export interface ProfileModificationDialogProps {
3729
profileId: UUID | undefined;
3830
open: boolean;
@@ -47,7 +39,7 @@ const ProfileModificationDialog: FunctionComponent<ProfileModificationDialogProp
4739
onUpdate,
4840
}) => {
4941
const { snackError } = useSnackMessage();
50-
const [dataFetchStatus, setDataFetchStatus] = useState<FetchStatus>(FetchStatus.IDLE);
42+
const [dataFetchStatus, setDataFetchStatus] = useState<string>(FetchStatus.IDLE);
5143

5244
const formSchema = yup
5345
.object()
@@ -115,27 +107,15 @@ const ProfileModificationDialog: FunctionComponent<ProfileModificationDialogProp
115107
setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
116108
reset({
117109
[PROFILE_NAME]: response.name,
118-
[LOADFLOW_PARAM_ID]: response.loadFlowParameterId ? response.loadFlowParameterId : undefined,
119-
[SECURITY_ANALYSIS_PARAM_ID]: response.securityAnalysisParameterId
120-
? response.securityAnalysisParameterId
121-
: undefined,
122-
[SENSITIVITY_ANALYSIS_PARAM_ID]: response.sensitivityAnalysisParameterId
123-
? response.sensitivityAnalysisParameterId
124-
: undefined,
125-
[SHORTCIRCUIT_PARAM_ID]: response.shortcircuitParameterId
126-
? response.shortcircuitParameterId
127-
: undefined,
128-
[VOLTAGE_INIT_PARAM_ID]: response.voltageInitParameterId
129-
? response.voltageInitParameterId
130-
: undefined,
110+
[LOADFLOW_PARAM_ID]: response.loadFlowParameterId ?? undefined,
111+
[SECURITY_ANALYSIS_PARAM_ID]: response.securityAnalysisParameterId ?? undefined,
112+
[SENSITIVITY_ANALYSIS_PARAM_ID]: response.sensitivityAnalysisParameterId ?? undefined,
113+
[SHORTCIRCUIT_PARAM_ID]: response.shortcircuitParameterId ?? undefined,
114+
[VOLTAGE_INIT_PARAM_ID]: response.voltageInitParameterId ?? undefined,
131115
[USER_QUOTA_CASE_NB]: response.maxAllowedCases,
132116
[USER_QUOTA_BUILD_NB]: response.maxAllowedBuilds,
133-
[SPREADSHEET_CONFIG_COLLECTION_ID]: response.spreadsheetConfigCollectionId
134-
? response.spreadsheetConfigCollectionId
135-
: undefined,
136-
[NETWORK_VISUALIZATION_PARAMETERS_ID]: response.networkVisualizationParameterId
137-
? response.networkVisualizationParameterId
138-
: undefined,
117+
[SPREADSHEET_CONFIG_COLLECTION_ID]: response.spreadsheetConfigCollectionId ?? undefined,
118+
[NETWORK_VISUALIZATION_PARAMETERS_ID]: response.networkVisualizationParameterId ?? undefined,
139119
});
140120
})
141121
.catch((error) => {

src/pages/profiles/profiles-page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FunctionComponent, useCallback, useRef, useState } from 'react';
99
import { Grid } from '@mui/material';
1010
import { GridTableRef } from '../../components/Grid';
1111
import { UserProfile } from '../../services';
12-
import { RowDoubleClickedEvent } from 'ag-grid-community';
12+
import { RowClickedEvent } from 'ag-grid-community';
1313
import ProfileModificationDialog from './modification/profile-modification-dialog';
1414
import { UUID } from 'crypto';
1515
import ProfilesTable from './profiles-table';
@@ -33,7 +33,7 @@ const ProfilesPage: FunctionComponent = () => {
3333
handleCloseProfileModificationDialog();
3434
}, [gridContext, handleCloseProfileModificationDialog]);
3535

36-
const onRowDoubleClicked = useCallback((event: RowDoubleClickedEvent<UserProfile>) => {
36+
const onRowClicked = useCallback((event: RowClickedEvent<UserProfile>) => {
3737
if (event.data) {
3838
setEditingProfileId(event.data.id);
3939
setOpenProfileModificationDialog(true);
@@ -51,7 +51,7 @@ const ProfilesPage: FunctionComponent = () => {
5151
/>
5252
<ProfilesTable
5353
gridRef={gridRef}
54-
onRowDoubleClicked={onRowDoubleClicked}
54+
onRowClicked={onRowClicked}
5555
setOpenAddProfileDialog={setOpenAddProfileDialog}
5656
/>
5757
<AddProfileDialog gridRef={gridRef} open={openAddProfileDialog} setOpen={setOpenAddProfileDialog} />

src/pages/profiles/profiles-table.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ import { useIntl } from 'react-intl';
1010
import { Cancel, CheckCircle, ManageAccounts, RadioButtonUnchecked } from '@mui/icons-material';
1111
import { GridButton, GridButtonDelete, GridTable, GridTableRef } from '../../components/Grid';
1212
import { UserAdminSrv, UserProfile } from '../../services';
13-
import {
14-
ColDef,
15-
GetRowIdParams,
16-
RowDoubleClickedEvent,
17-
SelectionChangedEvent,
18-
TextFilterParams,
19-
} from 'ag-grid-community';
13+
import { ColDef, GetRowIdParams, RowClickedEvent, SelectionChangedEvent, TextFilterParams } from 'ag-grid-community';
2014
import { useSnackMessage } from '@gridsuite/commons-ui';
2115
import DeleteConfirmationDialog from '../common/delete-confirmation-dialog';
2216

@@ -31,7 +25,7 @@ const defaultColDef: ColDef<UserProfile> = {
3125

3226
export interface ProfilesTableProps {
3327
gridRef: RefObject<GridTableRef<UserProfile>>;
34-
onRowDoubleClicked: (event: RowDoubleClickedEvent<UserProfile>) => void;
28+
onRowClicked: (event: RowClickedEvent<UserProfile>) => void;
3529
setOpenAddProfileDialog: (open: boolean) => void;
3630
}
3731

@@ -43,7 +37,7 @@ const ProfilesTable: FunctionComponent<ProfilesTableProps> = (props) => {
4337
const [showDeletionDialog, setShowDeletionDialog] = useState(false);
4438

4539
function getRowId(params: GetRowIdParams<UserProfile>): string {
46-
return params.data.id ? params.data.id : '';
40+
return params.data.id ?? '';
4741
}
4842

4943
const onSelectionChanged = useCallback(
@@ -139,7 +133,7 @@ const ProfilesTable: FunctionComponent<ProfilesTableProps> = (props) => {
139133
headerCheckbox: true,
140134
hideDisabledCheckboxes: false,
141135
}}
142-
onRowDoubleClicked={props.onRowDoubleClicked}
136+
onRowClicked={props.onRowClicked}
143137
onSelectionChanged={onSelectionChanged}
144138
>
145139
<GridButton

0 commit comments

Comments
 (0)