Skip to content

Commit efcf393

Browse files
authored
Refactor: update language type to GsLang in country-related components (#834)
Signed-off-by: achour94 <[email protected]>
1 parent 879b4e9 commit efcf393

File tree

10 files changed

+20
-15
lines changed

10 files changed

+20
-15
lines changed

src/components/dialogs/customMuiDialog/CustomMuiDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SubmitButton } from '../../inputs/reactHookForm/utils/SubmitButton';
1414
import { CancelButton } from '../../inputs/reactHookForm/utils/CancelButton';
1515
import { CustomFormProvider } from '../../inputs/reactHookForm/provider/CustomFormProvider';
1616
import { PopupConfirmationDialog } from '../popupConfirmationDialog/PopupConfirmationDialog';
17+
import { GsLang } from '../../../utils';
1718

1819
export type CustomMuiDialogProps<T extends FieldValues = FieldValues> = DialogProps & {
1920
open: boolean;
@@ -28,7 +29,7 @@ export type CustomMuiDialogProps<T extends FieldValues = FieldValues> = DialogPr
2829
onCancel?: () => void;
2930
children: ReactNode;
3031
isDataFetching?: boolean;
31-
language?: string;
32+
language?: GsLang;
3233
confirmationMessageKey?: string;
3334
unscrollableFullHeight?: boolean;
3435
};

src/components/filter/FilterCreationDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { FilterType } from './constants/FilterConstants';
2424
import { MAX_CHAR_DESCRIPTION } from '../../utils/constants/uiConstants';
2525
import { EXPERT_FILTER_QUERY } from './expert/expertFilterConstants';
2626
import { FILTER_EQUIPMENTS_ATTRIBUTES } from './explicitNaming/ExplicitNamingFilterConstants';
27+
import { GsLang } from '../../utils';
2728

2829
const emptyFormData = {
2930
[FieldConstants.NAME]: '',
@@ -49,7 +50,7 @@ export interface FilterCreationDialogProps {
4950
open: boolean;
5051
onClose: () => void;
5152
activeDirectory?: UUID;
52-
language?: string;
53+
language?: GsLang;
5354
sourceFilterForExplicitNamingConversion?: {
5455
id: UUID;
5556
equipmentType: string;

src/components/filter/filter.type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { UUID } from 'crypto';
9-
import { FieldConstants } from '../../utils';
9+
import { FieldConstants, GsLang } from '../../utils';
1010
import { RuleGroupTypeExport } from './expert/expertFilter.type';
1111
import { EXPERT_FILTER_QUERY } from './expert/expertFilterConstants';
1212
import { FILTER_EQUIPMENTS_ATTRIBUTES } from './explicitNaming/ExplicitNamingFilterConstants';
@@ -43,7 +43,7 @@ export interface FilterEditionProps {
4343
[FILTER_EQUIPMENTS_ATTRIBUTES]?: EquipmentsFilter[];
4444
}>;
4545
activeDirectory?: UUID;
46-
language?: string;
46+
language?: GsLang;
4747
description?: string;
4848
}
4949

src/components/inputs/reactHookForm/provider/CustomFormProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { type FieldValues, FormProvider, type UseFormReturn } from 'react-hook-f
1010
import * as yup from 'yup';
1111
import { type ObjectSchema } from 'yup';
1212
import { getSystemLanguage } from '../../../../hooks/useLocalizedCountries';
13+
import { GsLang } from '../../../../utils';
1314

1415
type CustomFormContextProps<TFieldValues extends FieldValues = FieldValues> = {
1516
removeOptional?: boolean;
1617
validationSchema: ObjectSchema<TFieldValues>;
17-
language?: string;
18+
language?: GsLang;
1819
isNodeBuilt?: boolean;
1920
isUpdate?: boolean;
2021
};

src/components/inputs/reactHookForm/selectInputs/CountriesInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface CountryInputProps {
1818

1919
export function CountriesInput({ name, label }: Readonly<CountryInputProps>) {
2020
const { language } = useCustomFormContext();
21-
const { translate, countryCodes } = useLocalizedCountries(language);
21+
const { translate, countryCodes } = useLocalizedCountries(language!);
2222

2323
const translateOption = useCallback(
2424
(option: Option) => {

src/components/inputs/reactQueryBuilder/CountryValueEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function CountryValueEditor(props: ValueEditorProps) {
1818
const { value, handleOnChange, title } = props;
1919

2020
const { language } = useCustomFormContext();
21-
const { translate, countryCodes } = useLocalizedCountries(language);
21+
const { translate, countryCodes } = useLocalizedCountries(language!);
2222
const [favoriteCountryCodes, setFavoriteCountryCodes] = useState<string[]>([]);
2323
const [initialized, setInitialized] = useState<boolean>(false);
2424

src/components/parameters/common/parameters-edition-dialog-props.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import { UUID } from 'crypto';
99
import { User } from 'oidc-client';
10+
import { GsLang } from '../../../utils';
1011

1112
export interface ParametersEditionDialogProps {
1213
id: UUID;
@@ -16,7 +17,7 @@ export interface ParametersEditionDialogProps {
1617
name: string;
1718
description: string | null;
1819
activeDirectory: UUID;
19-
language?: string;
20+
language?: GsLang;
2021
user: User | null;
2122
enableDeveloperMode?: boolean;
2223
}

src/components/parameters/loadflow/load-flow-parameters-form.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import { UseLoadFlowParametersFormReturn } from './use-load-flow-parameters-form
1111
import LoadFlowParametersHeader from './load-flow-parameters-header';
1212
import LoadFlowParametersContent from './load-flow-parameters-content';
1313
import { CustomFormProvider } from '../../inputs';
14+
import { GsLang } from '../../../utils';
1415

1516
interface LoadFlowParametersFormProps {
1617
loadflowMethods: UseLoadFlowParametersFormReturn;
17-
language: string;
18+
language: GsLang;
1819
renderTitleFields?: () => ReactNode;
1920
renderActions?: () => ReactNode;
2021
}

src/components/parameters/loadflow/load-flow-parameters-inline.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { TreeViewFinderNodeProps } from '../../treeViewFinder';
1717
import { useSnackMessage } from '../../../hooks';
1818
import { SubmitButton } from '../../inputs';
1919
import { LabelledButton } from '../common/parameters';
20-
import { ElementType, mergeSx } from '../../../utils';
20+
import { ElementType, GsLang, mergeSx } from '../../../utils';
2121
import { LineSeparator } from '../common';
2222
import { DirectoryItemSelector } from '../../directoryItemSelector';
2323
import { fetchLoadFlowParameters } from '../../../services/loadflow';
@@ -34,7 +34,7 @@ export function LoadFlowParametersInline({
3434
enableDeveloperMode,
3535
}: Readonly<{
3636
studyUuid: UUID | null;
37-
language: string;
37+
language: GsLang;
3838
parametersBackend: UseParametersBackendReturnProps<ComputingType.LOAD_FLOW>;
3939
setHaveDirtyFields: Dispatch<SetStateAction<boolean>>;
4040
enableDeveloperMode: boolean;

src/hooks/useLocalizedCountries.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
99
import localizedCountries, { LocalizedCountries } from 'localized-countries';
1010
import countriesFr from 'localized-countries/data/fr';
1111
import countriesEn from 'localized-countries/data/en';
12-
import { LANG_ENGLISH, LANG_FRENCH, LANG_SYSTEM } from '../utils/langs';
12+
import { GsLang, GsLangUser, LANG_ENGLISH, LANG_FRENCH, LANG_SYSTEM } from '../utils/langs';
1313

1414
const supportedLanguages = [LANG_FRENCH, LANG_ENGLISH];
1515

1616
export const getSystemLanguage = () => {
1717
const systemLanguage = navigator.language.split(/[-_]/)[0];
18-
return supportedLanguages.includes(systemLanguage) ? systemLanguage : LANG_ENGLISH;
18+
return supportedLanguages.includes(systemLanguage as GsLangUser) ? (systemLanguage as GsLangUser) : LANG_ENGLISH;
1919
};
2020

21-
export const getComputedLanguage = (language: string | undefined) => {
21+
export const getComputedLanguage = (language: GsLang): GsLangUser => {
2222
return language === LANG_SYSTEM ? getSystemLanguage() : (language ?? LANG_ENGLISH);
2323
};
2424

25-
export const useLocalizedCountries = (language: string | undefined) => {
25+
export const useLocalizedCountries = (language: GsLang) => {
2626
const [localizedCountriesModule, setLocalizedCountriesModule] = useState<LocalizedCountries>();
2727

2828
// TODO FM this is disgusting, can we make it better ?

0 commit comments

Comments
 (0)