Skip to content

Commit 29997c2

Browse files
authored
Migrate utils into typescript (#2443)
Signed-off-by: achour94 <[email protected]>
1 parent ed0dd5d commit 29997c2

12 files changed

+47
-44
lines changed

src/components/custom-aggrid/custom-aggrid-header.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { mergeSx } from '../utils/functions';
3131
import { useLocalizedCountries } from 'components/utils/localized-countries-hook';
3232
import CustomAggridBooleanFilter from './custom-aggrid-filters/custom-aggrid-boolean-filter';
3333
import CustomAggridDurationFilter from './custom-aggrid-filters/custom-aggrid-duration-filter';
34-
import { countDecimalPlaces } from '../../utils/rounding.js';
34+
import { countDecimalPlaces } from '../../utils/rounding';
3535
import { computeTolerance } from '../../hooks/use-aggrid-local-row-filter';
3636
import { useSnackMessage } from '@gridsuite/commons-ui';
3737

src/components/dialogs/export-dialog.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { isBlankOrEmpty } from 'components/utils/validation-functions';
3333
import TextField from '@mui/material/TextField';
3434
import { useSelector } from 'react-redux';
3535
import { useParameterState } from './parameters/parameters.jsx';
36-
import { PARAM_DEVELOPER_MODE } from '../../utils/config-params.js';
36+
import { PARAM_DEVELOPER_MODE } from '../../utils/config-params';
3737

3838
const STRING_LIST = 'STRING_LIST';
3939

src/hooks/use-aggrid-local-row-filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const computeTolerance = (value: undefined | null | number | string | str
3636
if (isNumber(value)) {
3737
decimalPrecision = countDecimalPlaces(value);
3838
} else {
39-
decimalPrecision = countDecimalPlacesFromString(value);
39+
decimalPrecision = countDecimalPlacesFromString(value as string);
4040
}
4141
// tolerance is multiplied by 0.5 to simulate the fact that the database value is rounded (in the front, from the user viewpoint)
4242
// more than 13 decimal after dot will likely cause rounding errors due to double precision
File renamed without changes.
File renamed without changes.

src/utils/colors.js renamed to src/utils/colors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
export function getNominalVoltageColor(nominalVoltage) {
8+
export function getNominalVoltageColor(nominalVoltage: number): number[] {
99
if (nominalVoltage >= 300) {
1010
return [255, 0, 0];
1111
} else if (nominalVoltage >= 170 && nominalVoltage < 300) {

src/utils/compute-title.js renamed to src/utils/compute-title.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,16 @@ const MAX_TITLE_LENGTH = 300;
99
const MAX_STUDY_NAME_LENGTH = 200;
1010
const SEPARATOR = ' | ';
1111

12-
export const computeFullPath = (parents) => {
13-
let path = '';
14-
15-
for (let i = 0; i < parents.length; i++) {
16-
path = '/' + parents[i] + path;
17-
}
18-
19-
return path;
12+
export const computeFullPath = (parents: string[]) => {
13+
return parents.reduce((path, parent) => `${path}/${parent}`, '');
2014
};
2115

22-
const computePath = (parents, maxAllowedPathSize) => {
16+
const computePath = (parents: string[], maxAllowedPathSize: number) => {
2317
let testedPath = '';
2418
let path = '';
2519

26-
for (let i = 0; i < parents.length; i++) {
27-
testedPath += '/' + parents[i];
20+
for (const parent of parents) {
21+
testedPath += '/' + parent;
2822
if (testedPath.length > maxAllowedPathSize) {
2923
return '...' + path;
3024
}
@@ -35,23 +29,23 @@ const computePath = (parents, maxAllowedPathSize) => {
3529
return path;
3630
};
3731

38-
const computePageTitleWithFirstDirectory = (pageTitle, parents) => {
32+
const computePageTitleWithFirstDirectory = (pageTitle: string, parents: string[]) => {
3933
return pageTitle + (parents.length > 1 ? '...' : '') + '/' + parents[0];
4034
};
4135

42-
const computePageTitleWithFullPath = (pageTitle, parents) => {
36+
const computePageTitleWithFullPath = (pageTitle: string, parents: string[]) => {
4337
const maxAllowedPathSize = MAX_TITLE_LENGTH - pageTitle.length - '...'.length;
4438

4539
pageTitle = pageTitle + computePath(parents, maxAllowedPathSize);
4640

4741
return pageTitle;
4842
};
4943

50-
const limitChar = (str, limit) => {
44+
const limitChar = (str: string, limit: number) => {
5145
return str.length > limit ? str.substring(0, limit) + '...' : str;
5246
};
5347

54-
export const computePageTitle = (appName, studyName, parents) => {
48+
export const computePageTitle = (appName: string, studyName?: string | null, parents?: string[] | null) => {
5549
if (!studyName) {
5650
return appName;
5751
}

src/utils/config-params.js renamed to src/utils/config-params.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ export const PARAM_SA_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD = 'highVoltageAbsoluteThre
4040
export const MAP_BASEMAP_MAPBOX = 'mapbox';
4141
export const MAP_BASEMAP_CARTO = 'carto';
4242
export const MAP_BASEMAP_CARTO_NOLABEL = 'cartonolabel';
43-
export const basemap_style_theme_key = (basemap) => basemap + 'Style';
43+
export const basemap_style_theme_key = (basemap: string) => basemap + 'Style';
4444

4545
const COMMON_CONFIG_PARAMS_NAMES = new Set([PARAM_THEME, PARAM_LANGUAGE]);
4646

47-
export function getAppName(paramName) {
47+
export function getAppName(paramName: string) {
4848
return COMMON_CONFIG_PARAMS_NAMES.has(paramName) ? COMMON_APP_NAME : APP_NAME;
4949
}
5050

@@ -54,6 +54,6 @@ const PARAM_SA_PROPORTIONAL_THRESHOLD = new Set([
5454
PARAM_SA_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD,
5555
]);
5656

57-
export const isProportionalSAParam = (param) => {
57+
export const isProportionalSAParam = (param: string) => {
5858
return PARAM_SA_PROPORTIONAL_THRESHOLD.has(param);
5959
};

src/utils/dialogs.jsx renamed to src/utils/dialogs.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,29 @@ import { FormattedMessage } from 'react-intl';
1111
import DialogContent from '@mui/material/DialogContent';
1212
import DialogActions from '@mui/material/DialogActions';
1313
import Button from '@mui/material/Button';
14-
import PropTypes from 'prop-types';
1514
import { CancelButton } from '@gridsuite/commons-ui';
15+
import { ReactElement } from 'react';
16+
import { SxProps, Theme } from '@mui/material';
1617

17-
const SelectOptionsDialog = ({ open, onClose, onClick, title, child, style, validateKey }) => {
18+
interface SelectOptionsDialogProps {
19+
open: boolean;
20+
onClose: () => void;
21+
onClick: () => void;
22+
title: string;
23+
child: ReactElement;
24+
style?: SxProps<Theme>;
25+
validateKey?: string;
26+
}
27+
28+
const SelectOptionsDialog = ({
29+
open,
30+
onClose,
31+
onClick,
32+
title,
33+
child,
34+
style,
35+
validateKey,
36+
}: SelectOptionsDialogProps) => {
1837
const handleClose = () => {
1938
onClose();
2039
};
@@ -26,21 +45,11 @@ const SelectOptionsDialog = ({ open, onClose, onClick, title, child, style, vali
2645
<DialogActions>
2746
<CancelButton onClick={handleClose} />
2847
<Button onClick={onClick} variant="outlined">
29-
<FormattedMessage id={validateKey || 'validate'} />
48+
<FormattedMessage id={validateKey ?? 'validate'} />
3049
</Button>
3150
</DialogActions>
3251
</Dialog>
3352
);
3453
};
3554

36-
SelectOptionsDialog.propTypes = {
37-
open: PropTypes.bool.isRequired,
38-
onClose: PropTypes.func.isRequired,
39-
onClick: PropTypes.func.isRequired,
40-
title: PropTypes.string.isRequired,
41-
child: PropTypes.element.isRequired,
42-
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
43-
validateKey: PropTypes.string,
44-
};
45-
4655
export { SelectOptionsDialog };
File renamed without changes.

0 commit comments

Comments
 (0)