Skip to content

Commit

Permalink
Merge pull request #141 from Sanketika-Obsrv/datasetname-fix
Browse files Browse the repository at this point in the history
Datasetname fix
  • Loading branch information
manjudr authored Nov 13, 2024
2 parents db1bbdc + 387425e commit ca0ea89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion web-console-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "react-scripts build --no-cache",
"postbuild": "mkdir build/console && mv build/static build/console/static",
"test": "react-scripts test",
"eject": "react-scripts eject",
Expand Down
23 changes: 16 additions & 7 deletions web-console-v2/src/pages/StepsPages/Ingestion/Ingestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const Ingestion = () => {
const [data, setData] = useState(dataState);

const [files, setFiles] = useState(filesState);
const [isDatasetExistChecking, setIsDatasetExistChecking] = useState(false);

const [highlightedSection, setHighlightedSection] = useState<string | null>(null);
const [fileErrors, setFileErrors] = useState<any>(null);
Expand Down Expand Up @@ -112,7 +113,7 @@ const Ingestion = () => {
queryParams: readDatasetQueryParams
});
const { data: datasetExistsData, refetch: refetchExists } = useFetchDatasetExists({
datasetId: datasetId
datasetId
});

const {
Expand Down Expand Up @@ -212,21 +213,26 @@ const Ingestion = () => {

const fetchDataset = (id: string) => {
refetchExists().then(response => {
if (response.isSuccess) {
if (response.isSuccess && !_.startsWith(response.data, '<!doctype html>')) {
setNameError('Dataset already exists');
} else {
setNameError('');
}
}).catch(error => {
console.error('Error fetching dataset:', error);
}).finally(() =>{
setIsDatasetExistChecking(false)
})
}
const debouncedFetchDataset = useMemo(
() => _.debounce(fetchDataset, 800), []
() => {
return _.debounce(fetchDataset, 800)
}, []
);

useEffect(() => {
if (datasetIdParam === '<new>' && datasetId) {
setIsDatasetExistChecking(true);
debouncedFetchDataset(datasetId);
}
}, [datasetId]);
Expand Down Expand Up @@ -415,7 +421,11 @@ const Ingestion = () => {
}, [datasetName])

const nameRegex = /^[^!@#$%^&*()+{}[\]:;<>,?~\\|]*$/;
const handleNameChange = (newValue: any) => {
const handleNameChange = (newValue: any, isBlur=false) => {
if(isBlur && newValue) {
setIsDatasetExistChecking(true);
debouncedFetchDataset(newValue)
}
if (nameRegex.test(newValue)) {
setDatasetName(newValue);
if(datasetIdParam === '<new>') {
Expand Down Expand Up @@ -501,7 +511,7 @@ const Ingestion = () => {
label={'Dataset Name'}
value={datasetName}
onChange={(e) => handleNameChange(e.target.value)}
onBlur={(e) => handleNameChange(e.target.value)}
onBlur={(e) => handleNameChange(e.target.value, true)}
required
variant="outlined"
fullWidth
Expand Down Expand Up @@ -587,7 +597,6 @@ const Ingestion = () => {
expand={isHelpSectionOpen}
/>
</Box>

{/* Fixed action button at the bottom */}
<Box
className={`${styles.actionContainer}`}
Expand All @@ -607,7 +616,7 @@ const Ingestion = () => {
label: datasetId !== '' ? 'Proceed' : 'Create Schema',
variant: 'contained',
color: 'primary',
disabled: datasetIdParam === '<new>' && (!_.isEmpty(nameError) || isEmpty(datasetId) || isEmpty(files) || (datasetName.length < 4 || datasetName.length > 100))
disabled: datasetIdParam === '<new>' && (!_.isEmpty(nameError) || isEmpty(datasetId) || isEmpty(files) || (datasetName.length < 4 || datasetName.length > 100 || isDatasetExistChecking))
}
]}
onClick={onSubmit}
Expand Down

0 comments on commit ca0ea89

Please sign in to comment.