diff --git a/src/ui/units/datasets/containers/DatasetPage/DatasetPage.tsx b/src/ui/units/datasets/containers/DatasetPage/DatasetPage.tsx index fa9a0841d5..e4a1c2731b 100644 --- a/src/ui/units/datasets/containers/DatasetPage/DatasetPage.tsx +++ b/src/ui/units/datasets/containers/DatasetPage/DatasetPage.tsx @@ -39,7 +39,7 @@ class DatasetPage extends React.Component { workbookIdFromPath={this.props.workbookId} history={this.props.history} ytPath={this.ytPath} - isCreationProcess={isCreationProcess()} + isCreationProcess={isCreationProcess(location.pathname)} isAuto={this.isAuto} /> diff --git a/src/ui/units/datasets/helpers/utils.test.ts b/src/ui/units/datasets/helpers/utils.test.ts new file mode 100644 index 0000000000..0200b28561 --- /dev/null +++ b/src/ui/units/datasets/helpers/utils.test.ts @@ -0,0 +1,14 @@ +import {isCreationProcess} from './utils'; + +describe('dataset/helpers/isCreationProcess', () => { + test.each([ + ['', false], + ['/datasets/name', false], + ['/datasets/name-new', false], + ['/datasets/new-name', false], + ['/datasets/new', true], + ])('isCreationProcess (args: %j)', (pathname, expected) => { + const result = isCreationProcess(pathname); + expect(result).toEqual(expected); + }); +}); diff --git a/src/ui/units/datasets/helpers/utils.ts b/src/ui/units/datasets/helpers/utils.ts index 12af47a36e..eee12d165a 100644 --- a/src/ui/units/datasets/helpers/utils.ts +++ b/src/ui/units/datasets/helpers/utils.ts @@ -150,6 +150,7 @@ export default class DatasetUtils { } } -export function isCreationProcess() { - return /new$/.test(window.location.pathname); +export function isCreationProcess(pathname = '') { + const lastPathnamePart = pathname.split('/').filter(Boolean).slice(-1)[0]; + return lastPathnamePart === 'new'; } diff --git a/src/ui/units/datasets/store/constants.ts b/src/ui/units/datasets/store/constants.ts index 310dcbae09..9f080d8d21 100644 --- a/src/ui/units/datasets/store/constants.ts +++ b/src/ui/units/datasets/store/constants.ts @@ -23,7 +23,7 @@ const isDatasetTab = (value: unknown): value is DatasetTab => { }; const getCurrentTab = (): DatasetTab => { - const defaultTab = isCreationProcess() ? TAB_SOURCES : TAB_DATASET; + const defaultTab = isCreationProcess(location.pathname) ? TAB_SOURCES : TAB_DATASET; const queryTab = DatasetUtils.getQueryParam('tab'); if (isDatasetTab(queryTab)) {