-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
feat: Create dataset header component #21189
Changes from all commits
ee1eabd
4c1cdb7
c391dc9
0557fba
1389b8b
c3e3544
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 |
---|---|---|
|
@@ -17,7 +17,81 @@ | |
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import { t } from '@superset-ui/core'; | ||
import { PageHeaderWithActions } from 'src/components/PageHeaderWithActions'; | ||
import Button from 'src/components/Button'; | ||
import Icons from 'src/components/Icons'; | ||
import { Menu } from 'src/components/Menu'; | ||
import { TooltipPlacement } from 'src/components/Tooltip'; | ||
import { | ||
HeaderComponentStyles, | ||
disabledSaveBtnStyles, | ||
} from 'src/views/CRUD/data/dataset/styles'; | ||
import { | ||
DatasetActionType, | ||
DSReducerActionType, | ||
} from 'src/views/CRUD/data/dataset/AddDataset/types'; | ||
|
||
export default function Header() { | ||
return <div>Header</div>; | ||
const tooltipProps: { text: string; placement: TooltipPlacement } = { | ||
text: t('Select a database table and create dataset'), | ||
placement: 'bottomRight', | ||
}; | ||
|
||
const renderDisabledSaveButton = () => ( | ||
<Button | ||
buttonStyle="primary" | ||
tooltip={tooltipProps?.text} | ||
placement={tooltipProps?.placement} | ||
disabled | ||
css={disabledSaveBtnStyles} | ||
> | ||
<Icons.Save iconSize="m" /> | ||
{t('Save')} | ||
</Button> | ||
); | ||
|
||
const renderOverlay = () => ( | ||
<Menu> | ||
<Menu.Item>{t('Settings')}</Menu.Item> | ||
<Menu.Item>{t('Delete')}</Menu.Item> | ||
</Menu> | ||
); | ||
|
||
export default function Header({ | ||
setDataset, | ||
datasetName, | ||
}: { | ||
setDataset: React.Dispatch<DSReducerActionType>; | ||
datasetName: string; | ||
}) { | ||
const editableTitleProps = { | ||
title: datasetName, | ||
placeholder: t('Add the name of the dataset'), | ||
onSave: (newDatasetName: string) => { | ||
setDataset({ | ||
type: DatasetActionType.changeDataset, | ||
payload: { name: 'dataset_name', value: newDatasetName }, | ||
}); | ||
}, | ||
canEdit: true, | ||
label: t('dataset name'), | ||
}; | ||
|
||
return ( | ||
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. hey, quick question in regards to the save button. What happens, currently, when I press save? I believe that we have a state action that is supposed to put the name into state. Does it currently do that? 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. Good call, I have the data properly flowing now in |
||
<HeaderComponentStyles> | ||
<PageHeaderWithActions | ||
editableTitleProps={editableTitleProps} | ||
showTitlePanelItems={false} | ||
showFaveStar={false} | ||
faveStarProps={{ itemId: 1, saveFaveStar: () => {} }} | ||
titlePanelAdditionalItems={<></>} | ||
rightPanelAdditionalItems={renderDisabledSaveButton()} | ||
additionalActionsMenu={renderOverlay()} | ||
menuDropdownProps={{ | ||
disabled: true, | ||
}} | ||
tooltipProps={tooltipProps} | ||
/> | ||
</HeaderComponentStyles> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import { render, screen, waitFor } from 'spec/helpers/testing-library'; | ||
import DatasetLayout from 'src/views/CRUD/data/dataset/DatasetLayout'; | ||
import Header from 'src/views/CRUD/data/dataset/AddDataset/Header'; | ||
import LeftPanel from 'src/views/CRUD/data/dataset/AddDataset/LeftPanel'; | ||
|
@@ -33,10 +33,21 @@ describe('DatasetLayout', () => { | |
expect(layoutWrapper).toHaveTextContent(''); | ||
}); | ||
|
||
it('renders a Header when passed in', () => { | ||
render(<DatasetLayout header={Header()} />); | ||
const mockSetDataset = jest.fn(); | ||
|
||
expect(screen.getByText(/header/i)).toBeVisible(); | ||
const waitForRender = () => | ||
waitFor(() => | ||
render(<Header setDataset={mockSetDataset} datasetName="" />), | ||
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. add a test to make sure if 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. |
||
); | ||
|
||
it('renders a Header when passed in', async () => { | ||
await waitForRender(); | ||
|
||
expect( | ||
screen.getByRole('textbox', { | ||
name: /dataset name/i, | ||
}), | ||
).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.
should there be a test for when someone passes in a name?
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.
Can do! Added in
this commit
.