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

Toast on CustomPanels #415

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 10 additions & 4 deletions .cypress/integration/3_panels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Creating visualizations', () => {
});
});

describe('Testing panels table', () => {
describe.only('Testing panels table', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the .only, commented code and console.log additions were part of cypress debugging. We can remove these.

beforeEach(() => {
eraseTestPanels();
moveToPanelHome();
Expand Down Expand Up @@ -567,6 +567,7 @@ const eraseLegacyPanels = () => {
'osd-xsrf': true,
},
}).then((response) => {
console.log("legacy panels to erase", response.body)
response.body.panels.map((panel) => {
cy.request({
method: 'DELETE',
Expand Down Expand Up @@ -596,6 +597,7 @@ const eraseSavedObjectPaenls = () => {
},
})
.then((response) => {
console.log("saved objects to erase", response.body)
response.body.saved_objects.map((soPanel) => {
cy.request({
method: 'DELETE',
Expand All @@ -605,6 +607,9 @@ const eraseSavedObjectPaenls = () => {
'content-type': 'application/json;charset=UTF-8',
'osd-xsrf': true,
},
}).then((response) => {
const deletedId = response;
console.log('erased SO Panel', response)
});
});
});
Expand Down Expand Up @@ -681,9 +686,10 @@ const openActionsDropdown = () => {
};

const selectThePanel = () => {
cy.get('.euiCheckbox__input[title="Select this row"]').then(() => {
cy.get('.euiCheckbox__input[title="Select this row"]').check({ force: true });
});
// cy.get('.euiCheckbox__input[title="Select this row"]').then(() => {
cy.get('.euiCheckbox__input[title="Select this row"]').check({ force: true });
cy.get('.euiTableRow-isSelected').should('exist')
// });
};

const expectToastWith = (title) => {
Expand Down
5 changes: 5 additions & 0 deletions common/types/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CoreStart, ToastsStart } from '../../../../src/core/public';

export interface ObservabilityAppServices extends CoreStart {
toasts: ToastsStart;
}
46 changes: 26 additions & 20 deletions public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { EventAnalytics } from './event_analytics';
import { Home as MetricsHome } from './metrics/index';
import { Main as NotebooksHome } from './notebooks/components/main';
import { Home as TraceAnalyticsHome } from './trace_analytics/home';
import { ObservabilityAppServices } from '../../common/types/shared';
import { OpenSearchDashboardsContextProvider } from '../../../../src/plugins/opensearch_dashboards_react/public';

interface ObservabilityAppDeps {
CoreStartProp: CoreStart;
Expand All @@ -28,6 +30,7 @@ interface ObservabilityAppDeps {
timestampUtils: any;
queryManager: QueryManager;
startPage: string;
services: ObservabilityAppServices;
}

// for cypress to test redux store
Expand All @@ -53,6 +56,7 @@ export const App = ({
timestampUtils,
queryManager,
startPage,
services,
}: ObservabilityAppDeps) => {
const { chrome, http, notifications, savedObjects: coreSavedObjects } = CoreStartProp;
const parentBreadcrumb = {
Expand All @@ -65,26 +69,28 @@ export const App = ({
return (
<Provider store={store}>
<I18nProvider>
<MetricsListener http={http}>
<ModuleComponent
http={http}
chrome={chrome}
notifications={notifications}
CoreStartProp={CoreStartProp}
DepsStart={DepsStart}
DashboardContainerByValueRenderer={
DepsStart.dashboard.DashboardContainerByValueRenderer
}
pplService={pplService}
dslService={dslService}
savedObjects={savedObjects}
timestampUtils={timestampUtils}
queryManager={queryManager}
parentBreadcrumb={parentBreadcrumb}
parentBreadcrumbs={[parentBreadcrumb]}
setBreadcrumbs={chrome.setBreadcrumbs}
/>
</MetricsListener>
<OpenSearchDashboardsContextProvider services={services}>
<MetricsListener http={http}>
<ModuleComponent
http={http}
chrome={chrome}
notifications={notifications}
CoreStartProp={CoreStartProp}
DepsStart={DepsStart}
DashboardContainerByValueRenderer={
DepsStart.dashboard.DashboardContainerByValueRenderer
}
pplService={pplService}
dslService={dslService}
savedObjects={savedObjects}
timestampUtils={timestampUtils}
queryManager={queryManager}
parentBreadcrumb={parentBreadcrumb}
parentBreadcrumbs={[parentBreadcrumb]}
setBreadcrumbs={chrome.setBreadcrumbs}
/>
</MetricsListener>
</OpenSearchDashboardsContextProvider>
</I18nProvider>
</Provider>
);
Expand Down
36 changes: 36 additions & 0 deletions public/components/common/toast/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { useOpenSearchDashboards } from '../../../../../../src/plugins/opensearch_dashboards_react/public';
import { ToastInputFields } from '../../../../../../src/core/public';
import { ObservabilityAppServices } from '../../../../common/types/shared';

type Color = 'success' | 'primary' | 'warning' | 'danger' | undefined;

export const useToast = () => {
const {
services: { toasts },
} = useOpenSearchDashboards<ObservabilityAppServices>();

const setToast = (title: string, color: Color = 'success', text?, side?: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the side parameter, if not being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side is used when toast during flyout. So unless toast on right-side is OK while visualization flyout and others are active, only then could we remove it.

Side is being passed-through on OSD API

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something here. Can you please explain how are you using/passing down the side parameter in this function?

const newToast: ToastInputFields = {
id: new Date().toISOString(),
title,
text,
};
switch (color) {
case 'danger': {
toasts.addDanger(newToast);
break;
}
case 'warning': {
toasts.addWarning(newToast);
break;
}
default: {
toasts.addSuccess(newToast);
break;
}
}
};

return { setToast };
};
Loading