Skip to content

Commit

Permalink
Top n queries overview page (#7)
Browse files Browse the repository at this point in the history
* Add 2 tabs to home screen

Signed-off-by: Emily Guo <[email protected]>

* two tabs for query insights and configuration

Signed-off-by: Emily Guo <[email protected]>

* Breadcrumbs + restructuring

Signed-off-by: Emily Guo <[email protected]>

* Top n queries table + search

Signed-off-by: Emily Guo <[email protected]>

* search in general

Signed-off-by: Emily Guo <[email protected]>

* Search includes indices and time selection fully works

Signed-off-by: Emily Guo <[email protected]>

* Fix tabs display

Signed-off-by: Emily Guo <[email protected]>

* Remove unnecessary parts

Signed-off-by: Emily Guo <[email protected]>

* More cleanups

Signed-off-by: Emily Guo <[email protected]>

* Linted

Signed-off-by: Emily Guo <[email protected]>

* Unused import

Signed-off-by: Emily Guo <[email protected]>

* Update plugin version to be compatible with openSearchDashboards

Signed-off-by: Emily Guo <[email protected]>

* Resolving comments

Signed-off-by: Emily Guo <[email protected]>

* Switch to typescript

Signed-off-by: Emily Guo <[email protected]>

* Finish typescript updates

Signed-off-by: Emily Guo <[email protected]>

* Comments addressed with constants

Signed-off-by: Emily Guo <[email protected]>

* Restructuring changes

Signed-off-by: Emily Guo <[email protected]>

* linting issues and ensure working on no data

Signed-off-by: Emily Guo <[email protected]>

* Added all relevant changes to overview page

Signed-off-by: Emily Guo <[email protected]>

* Remove unnecessary parts

Signed-off-by: Emily Guo <[email protected]>

* Fix unit test

Signed-off-by: Emily Guo <[email protected]>

---------

Signed-off-by: Emily Guo <[email protected]>
Signed-off-by: Emily Guo <[email protected]>
Signed-off-by: Emily Guo <[email protected]>
  • Loading branch information
LilyCaroline17 authored Sep 4, 2024
1 parent ea632fc commit 4987001
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 218 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ yarn-error.log
.DS_Store
/cypress/screenshots/
/cypress/videos/
target
target
.eslintcache
2 changes: 1 addition & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "queryInsightsDashboards",
"version": "1.0.0",
"opensearchDashboardsVersion": "opensearchDashboards",
"opensearchDashboardsVersion": "3.0.0",
"server": true,
"ui": true,
"requiredPlugins": ["navigation"],
Expand Down
17 changes: 5 additions & 12 deletions public/application.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter as Router } from 'react-router-dom';
import { AppMountParameters, CoreStart } from '../../../src/core/public';
import { AppPluginStartDependencies } from './types';
import { QueryInsightsDashboardsApp } from './components/app';

export const renderApp = (
{ notifications, http }: CoreStart,
{ navigation }: AppPluginStartDependencies,
{ appBasePath, element }: AppMountParameters
) => {
export const renderApp = (core: CoreStart, { element }: AppMountParameters) => {
ReactDOM.render(
<QueryInsightsDashboardsApp
basename={appBasePath}
notifications={notifications}
http={http}
navigation={navigation}
/>,
<Router>
<QueryInsightsDashboardsApp core={core} />
</Router>,
element
);

Expand Down
69 changes: 0 additions & 69 deletions public/components/__snapshots__/app.test.tsx.snap

This file was deleted.

26 changes: 16 additions & 10 deletions public/components/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import React from 'react';
import { render } from '@testing-library/react';
import { coreMock } from '../../../../src/core/public/mocks';
import { MemoryRouter as Router } from 'react-router-dom';
import { QueryInsightsDashboardsApp } from './app';

describe('<QueryInsightsDashboardsApp /> spec', () => {
Expand All @@ -15,18 +17,22 @@ describe('<QueryInsightsDashboardsApp /> spec', () => {
serverBasePath: '/app/opensearch-dashboards',
},
};
const coreStart = coreMock.createStart();

const { container } = render(
<QueryInsightsDashboardsApp
basename="/"
http={mockHttpStart as any}
navigation={
{
ui: { TopNavMenu: () => null },
} as any
}
notifications={{} as any}
/>
<Router>
<QueryInsightsDashboardsApp
basename="/"
core={coreStart}
http={mockHttpStart as any}
navigation={
{
ui: { TopNavMenu: () => null },
} as any
}
notifications={{} as any}
/>
</Router>
);
expect(container).toMatchSnapshot();
});
Expand Down
121 changes: 5 additions & 116 deletions public/components/app.tsx
Original file line number Diff line number Diff line change
@@ -1,119 +1,8 @@
import React, { useState } from 'react';
import { i18n } from '@osd/i18n';
import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
import { BrowserRouter as Router } from 'react-router-dom';

import {
EuiButton,
EuiHorizontalRule,
EuiPage,
EuiPageBody,
EuiPageContent,
EuiPageContentBody,
EuiPageContentHeader,
EuiPageHeader,
EuiTitle,
EuiText,
} from '@elastic/eui';

import React from 'react';
import { Route } from 'react-router-dom';
import TopNQueries from '../pages/TopNQueries/TopNQueries';
import { CoreStart } from '../../../../src/core/public';
import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public';

import { PLUGIN_ID, PLUGIN_NAME } from '../../common';

interface QueryInsightsDashboardsAppDeps {
basename: string;
notifications: CoreStart['notifications'];
http: CoreStart['http'];
navigation: NavigationPublicPluginStart;
}

export const QueryInsightsDashboardsApp = ({
basename,
notifications,
http,
navigation,
}: QueryInsightsDashboardsAppDeps) => {
// Use React hooks to manage state.
const [timestamp, setTimestamp] = useState<string | undefined>();

const onClickHandler = () => {
// Use the core http service to make a response to the server API.
http.get('/api/query_insights_dashboards/example').then((res) => {
setTimestamp(res.time);
// Use the core notifications service to display a success message.
notifications.toasts.addSuccess(
i18n.translate('queryInsightsDashboards.dataUpdated', {
defaultMessage: 'Data updated',
})
);
});
};

// Render the application DOM.
// Note that `navigation.ui.TopNavMenu` is a stateful component exported on the `navigation` plugin's start contract.
return (
<Router basename={basename}>
<I18nProvider>
<>
<navigation.ui.TopNavMenu
appName={PLUGIN_ID}
showSearchBar={true}
useDefaultBehaviors={true}
/>
<EuiPage restrictWidth="1000px">
<EuiPageBody component="main">
<EuiPageHeader>
<EuiTitle size="l">
<h1>
<FormattedMessage
id="queryInsightsDashboards.helloWorldText"
defaultMessage="{name}"
values={{ name: PLUGIN_NAME }}
/>
</h1>
</EuiTitle>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentHeader>
<EuiTitle>
<h2>
<FormattedMessage
id="queryInsightsDashboards.congratulationsTitle"
defaultMessage="Congratulations, you have successfully created a new OpenSearch Dashboards Plugin!"
/>
</h2>
</EuiTitle>
</EuiPageContentHeader>
<EuiPageContentBody>
<EuiText>
<p>
<FormattedMessage
id="queryInsightsDashboards.content"
defaultMessage="Look through the generated code and check out the plugin development documentation."
/>
</p>
<EuiHorizontalRule />
<p>
<FormattedMessage
id="queryInsightsDashboards.timestampText"
defaultMessage="Last timestamp: {time}"
values={{ time: timestamp ? timestamp : 'Unknown' }}
/>
</p>
<EuiButton type="primary" size="s" onClick={onClickHandler}>
<FormattedMessage
id="queryInsightsDashboards.buttonText"
defaultMessage="Get data"
/>
</EuiButton>
</EuiText>
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
</EuiPage>
</>
</I18nProvider>
</Router>
);
export const QueryInsightsDashboardsApp = ({ core }: { core: CoreStart }) => {
return <Route render={() => <TopNQueries core={core} />} />;
};
Loading

0 comments on commit 4987001

Please sign in to comment.