Skip to content
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(dashboard): add toast feedback to dashboard actions #18114

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ test('should refresh the charts', async () => {
await openDropdown();
userEvent.click(screen.getByText('Refresh dashboard'));
expect(mockedProps.forceRefreshAllCharts).toHaveBeenCalledTimes(1);
expect(mockedProps.addSuccessToast).toHaveBeenCalledTimes(1);
});

test('should show the properties modal', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class HeaderActionsDropdown extends React.PureComponent {
switch (key) {
case MENU_KEYS.REFRESH_DASHBOARD:
this.props.forceRefreshAllCharts();
this.props.addSuccessToast(t('Data refreshed'));
break;
case MENU_KEYS.EDIT_PROPERTIES:
this.props.showPropertiesModal();
Expand Down Expand Up @@ -276,6 +277,7 @@ class HeaderActionsDropdown extends React.PureComponent {
<Menu.Divider />
<Menu.Item key={MENU_KEYS.AUTOREFRESH_MODAL}>
<RefreshIntervalModal
addSuccessToast={this.props.addSuccessToast}
refreshFrequency={refreshFrequency}
refreshLimit={refreshLimit}
refreshWarning={refreshWarning}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const createProps = () => ({
onlyApply: false,
onHide: jest.fn(),
onSubmit: jest.fn(),
addSuccessToast: jest.fn(),
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ const PropertiesModal = ({
...moreOnSubmitProps,
};
if (onlyApply) {
addSuccessToast(t('Dashboard properties updated'));
onSubmit(onSubmitProps);
onHide();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const defaultRefreshIntervalModalProps = {
refreshFrequency: 0,
onChange: jest.fn(),
editMode: true,
addSuccessToast: jest.fn(),
};

describe('RefreshIntervalModal - RTL', () => {
Expand Down Expand Up @@ -214,6 +215,7 @@ describe('RefreshIntervalModal - RTL', () => {
10,
editModeOnProps.editMode,
);
expect(editModeOnProps.addSuccessToast).toHaveBeenCalled();
});

it('should show warning message', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const RefreshWarningContainer = styled.div`
`;

type RefreshIntervalModalProps = {
addSuccessToast: (msg: string) => void;
triggerNode: JSX.Element;
refreshFrequency: number;
onChange: (refreshLimit: number, editMode: boolean) => void;
Expand Down Expand Up @@ -86,6 +87,7 @@ class RefreshIntervalModal extends React.PureComponent<
onSave() {
this.props.onChange(this.state.refreshFrequency, this.props.editMode);
this.modalRef.current?.close();
this.props.addSuccessToast(t('Refresh interval saved'));
}

onCancel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ test('Should "Force refresh"', () => {
userEvent.click(screen.getByRole('menuitem', { name: /Force refresh/ }));
expect(props.forceRefresh).toBeCalledTimes(1);
expect(props.forceRefresh).toBeCalledWith(371, 26);
expect(props.addSuccessToast).toBeCalledTimes(1);
});

test('Should "Maximize chart"', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class SliceHeaderControls extends React.PureComponent<
switch (key) {
case MENU_KEYS.FORCE_REFRESH:
this.refreshChart();
this.props.addSuccessToast(t('Data refreshed'));
break;
case MENU_KEYS.CROSS_FILTER_SCOPING:
this.setState({ showCrossFilterScopingModal: true });
Expand Down