Skip to content

Commit

Permalink
feat(dashboard): add toast feedback to dashboard actions (#18114)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored Jan 24, 2022
1 parent 9fa2812 commit d9eef8e
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 0 deletions.
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

0 comments on commit d9eef8e

Please sign in to comment.