-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Dataset creation header is now uneditable and holds proper default values #21557
Changes from 7 commits
df99293
dfc8ec9
c0e47d8
ac9d80a
f27495b
d7b2969
96235fe
e9f6eb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,21 +59,23 @@ const renderOverlay = () => ( | |
|
||
export default function Header({ | ||
setDataset, | ||
datasetName, | ||
title, | ||
schema, | ||
}: { | ||
setDataset: React.Dispatch<DSReducerActionType>; | ||
datasetName: string; | ||
title: string; | ||
schema?: string | null | undefined; | ||
}) { | ||
const editableTitleProps = { | ||
title: datasetName, | ||
placeholder: t('Add the name of the dataset'), | ||
title: schema ? title : t('New dataset'), | ||
placeholder: t('New dataset'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are using t'(New dataset') twice here, it may be worth defining a const with that value and using it in both places. If you export that const you could also use it in the test file so that if someone changes the value later you don't have to keep three separate string literals in sync manually. export const DEFAULT_TITLE = t(New dataset); Then use that on line 70, 71, and in line 51 of Header.test.tsx There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in |
||
onSave: (newDatasetName: string) => { | ||
setDataset({ | ||
type: DatasetActionType.changeDataset, | ||
payload: { name: 'dataset_name', value: newDatasetName }, | ||
}); | ||
}, | ||
canEdit: true, | ||
canEdit: false, | ||
label: t('dataset name'), | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,11 @@ export default function AddDataset() { | |
>(datasetReducer, null); | ||
|
||
const HeaderComponent = () => ( | ||
<Header setDataset={setDataset} datasetName={dataset?.dataset_name ?? ''} /> | ||
<Header | ||
setDataset={setDataset} | ||
title={dataset?.table_name ?? 'New dataset'} | ||
eschutho marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to wrap in a t('New dataset') If making the title prop optional like mentioned in comment on Header/index.tsx then this could be simplified to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in |
||
schema={dataset?.schema} | ||
/> | ||
); | ||
|
||
const LeftPanelComponent = () => ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,18 +36,12 @@ describe('DatasetLayout', () => { | |
const mockSetDataset = jest.fn(); | ||
|
||
const waitForRender = () => | ||
waitFor(() => | ||
render(<Header setDataset={mockSetDataset} datasetName="" />), | ||
); | ||
waitFor(() => render(<Header setDataset={mockSetDataset} title="" />)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this the same as having no title thus the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The title can't have nullish values because of the component that uses it: PageHeaderWithActions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the other comments I left might address this and allow the title="" to be removed |
||
|
||
it('renders a Header when passed in', async () => { | ||
await waitForRender(); | ||
|
||
expect( | ||
screen.getByRole('textbox', { | ||
name: /dataset name/i, | ||
}), | ||
).toBeVisible(); | ||
expect(screen.getByTestId('editable-title')).toBeVisible(); | ||
}); | ||
|
||
it('renders a LeftPanel when passed in', async () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why the usage of title here is tied to if schema is defined? If you make title optional, then set a default value for title as t('New dataset') could the conditional logic here could be removed?
export const DEFAULT_TITLE = t(New dataset); export default function Header({ setDataset, title = DEFAULT_TITLE, }: { setDataset: React.Dispatch<DSReducerActionType>; title?: string; }) { const editableTitleProps = { title, placeholder: DEFAULT_TITLE
It looks like the only use of schema prop is this case so changing this logic might also make the prop unnecessary and simplify the component's interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in
this commit