Skip to content

Commit 154a34e

Browse files
authored
Merge branch 'main' into contingencyListByFilter
2 parents af23c4d + 752654e commit 154a34e

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gridsuite/commons-ui",
3-
"version": "0.120.0",
3+
"version": "0.120.1",
44
"description": "common react components for gridsuite applications",
55
"author": "gridsuite team",
66
"homepage": "https://github.com/gridsuite",

src/components/inputs/reactHookForm/agGridTable/csvUploader/CsvUploader.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import React, { useMemo, useState } from 'react';
2020
import { FormattedMessage, useIntl } from 'react-intl';
2121
import CsvDownloader from 'react-csv-downloader';
2222
import { useWatch } from 'react-hook-form';
23-
import { FieldConstants } from '../../../../../utils/constants/fieldConstants';
24-
import { CancelButton } from '../../utils/CancelButton';
23+
import { FieldConstants, GsLang, LANG_FRENCH } from '../../../../../utils';
24+
import { CancelButton } from '../../utils';
2525

2626
export interface CsvUploaderProps {
2727
name: string;
@@ -34,6 +34,7 @@ export interface CsvUploaderProps {
3434
validateData: (rows: string[][]) => boolean;
3535
getDataFromCsv: any;
3636
useFieldArrayOutput: any;
37+
language: GsLang;
3738
}
3839

3940
export function CsvUploader({
@@ -47,6 +48,7 @@ export function CsvUploader({
4748
validateData = () => true,
4849
getDataFromCsv,
4950
useFieldArrayOutput,
51+
language,
5052
}: Readonly<CsvUploaderProps>) {
5153
const watchTableValues = useWatch({ name });
5254
const { append, replace } = useFieldArrayOutput;
@@ -178,7 +180,11 @@ export function CsvUploader({
178180
<Grid container spacing={2}>
179181
<Grid container item>
180182
<Grid item xs={6}>
181-
<CsvDownloader datas={data} filename={fileName} separator=",">
183+
<CsvDownloader
184+
datas={data}
185+
filename={fileName}
186+
separator={language === LANG_FRENCH ? ';' : ','}
187+
>
182188
<Button variant="contained">
183189
<FormattedMessage id="GenerateCSV" />
184190
</Button>
@@ -194,6 +200,7 @@ export function CsvUploader({
194200
config={{
195201
// We use | for multi values in one cell, then we remove it from the default value for this config, to avoid delimiter autodetection
196202
delimitersToGuess: [',', ' ', ';', RECORD_SEP, UNIT_SEP],
203+
delimiter: language === LANG_FRENCH ? ';' : ',',
197204
}}
198205
>
199206
{({ getRootProps, acceptedFile }: any) => (

src/hooks/use-unique-name-validation.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,42 @@ export function useUniqueNameValidation({
8787

8888
// We have to use an useEffect because the name can change from outside of this component (when we upload a case file for instance)
8989
useEffect(() => {
90-
const trimmedValue = value?.trim?.();
91-
if (!trimmedValue && isDirty) {
92-
clearErrors('root.isValidating');
93-
setError(name, {
94-
type: 'validate',
95-
message: 'nameEmpty',
96-
});
97-
return;
90+
const trimmedValue = value.trim();
91+
92+
if (selectedDirectory) {
93+
debouncedHandleCheckName(trimmedValue);
9894
}
9995

100-
if (!isDirty || defaultFieldValue?.trim?.() === trimmedValue) {
96+
// if the name is unchanged, we don't do custom validation
97+
if (!isDirty) {
10198
clearErrors(name);
10299
return;
103100
}
104-
105-
setError('root.isValidating', {
106-
type: 'validate',
107-
message: 'cantSubmitWhileValidating',
108-
});
109-
110-
if (directory) {
101+
if (trimmedValue) {
102+
clearErrors(name);
103+
setError('root.isValidating', {
104+
type: 'validate',
105+
message: 'cantSubmitWhileValidating',
106+
});
111107
debouncedHandleCheckName(trimmedValue);
108+
} else {
109+
clearErrors('root.isValidating');
110+
setError(name, {
111+
type: 'validate',
112+
message: 'nameEmpty',
113+
});
112114
}
113-
}, [value, debouncedHandleCheckName, setError, clearErrors, name, isDirty, defaultFieldValue, directory]);
115+
}, [
116+
value,
117+
debouncedHandleCheckName,
118+
setError,
119+
clearErrors,
120+
name,
121+
isDirty,
122+
defaultFieldValue,
123+
directory,
124+
selectedDirectory,
125+
]);
114126

115127
return {
116128
isValidating,

0 commit comments

Comments
 (0)