Skip to content

Commit 1ab0f0a

Browse files
opensearch-trigger-bot[bot]joshuarrrr
authored andcommitted
[D&D] Adds Bar line and Area charts to Wizard (opensearch-project#2266) (opensearch-project#2291)
Description * Adds Bar line and Area charts to Wizard * Adds resizable right nav to Wizard * E2E tests for bar chart and chart switching Issues Resolved: opensearch-project#1616 opensearch-project#1617 opensearch-project#1618 Co-authored-by: Josh Romero <rmerqg@amazon.com> Signed-off-by: Ashwin Pc <ashwinpc@amazon.com>
1 parent 3e7e41d commit 1ab0f0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1094
-88
lines changed

config/opensearch_dashboards.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,12 @@
223223
# Set the value of this setting to true to start exploring wizard
224224
# functionality in Visualization.
225225
# wizard.enabled: false
226+
# csp.strict: false
227+
# csp.script_src: https://www.google-analytics.com https://ssl.google-analytics.com
228+
# csp.img_src: https://www.google-analytics.com
229+
# csp.connect_src: https://www.google-analytics.com
230+
231+
csp.rules:
232+
- "script-src 'unsafe-eval' 'unsafe-inline' 'self' https://www.google-analytics.com https://ssl.google-analytics.com"
233+
- "img-src 'unsafe-eval' 'unsafe-inline' 'self' data: https://www.google-analytics.com"
234+
- "connect-src 'unsafe-eval' 'unsafe-inline' 'self' https://www.google-analytics.com"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
"re2": "^1.15.4",
189189
"react": "^16.14.0",
190190
"react-dom": "^16.12.0",
191+
"react-ga": "^3.3.1",
191192
"react-input-range": "^1.3.0",
192193
"react-router": "^5.2.1",
193194
"react-use": "^13.27.0",
@@ -454,4 +455,4 @@
454455
"node": "14.20.0",
455456
"yarn": "^1.21.1"
456457
}
457-
}
458+
}

src/plugins/google_analytic/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INLINE_RUNTIME_CHUNK=false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@elastic/eslint-config-kibana', 'plugin:@elastic/eui/recommended'],
4+
rules: {
5+
'@osd/eslint/require-license-header': 'off',
6+
},
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"prefix": "googleAnalytic",
3+
"paths": {
4+
"googleAnalytic": "."
5+
},
6+
"translations": ["translations/ja-JP.json"]
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# googleAnalytic
2+
3+
A OpenSearch Dashboards plugin
4+
5+
---
6+
7+
## Development
8+
9+
See the [OpenSearch Dashboards contributing
10+
guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/CONTRIBUTING.md) for instructions
11+
setting up your development environment.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const PLUGIN_ID = 'googleAnalytic';
2+
export const PLUGIN_NAME = 'googleAnalytic';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "googleAnalytic",
3+
"version": "1.0.0",
4+
"opensearchDashboardsVersion": "opensearchDashboards",
5+
"server": false,
6+
"ui": true,
7+
"requiredPlugins": ["navigation"],
8+
"optionalPlugins": []
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import ReactGA from 'react-ga';
4+
import { AppMountParameters, CoreStart } from '../../../core/public';
5+
import { AppPluginStartDependencies } from './types';
6+
import { GoogleAnalyticApp } from './components/app';
7+
8+
const TRACKING_ID = 'UA-20742809-1'; // YOUR_OWN_TRACKING_ID
9+
// eslint-disable-next-line no-console
10+
console.log('huanji debug');
11+
ReactGA.initialize(TRACKING_ID);
12+
13+
export const renderApp = (
14+
{ notifications, http }: CoreStart,
15+
{ navigation }: AppPluginStartDependencies,
16+
{ appBasePath, element }: AppMountParameters
17+
) => {
18+
ReactDOM.render(
19+
<GoogleAnalyticApp
20+
basename={appBasePath}
21+
notifications={notifications}
22+
http={http}
23+
navigation={navigation}
24+
/>,
25+
element
26+
);
27+
28+
return () => ReactDOM.unmountComponentAtNode(element);
29+
};
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import React, { useState } from 'react';
2+
import { i18n } from '@osd/i18n';
3+
import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
4+
import { BrowserRouter as Router } from 'react-router-dom';
5+
6+
import {
7+
EuiButton,
8+
EuiHorizontalRule,
9+
EuiPage,
10+
EuiPageBody,
11+
EuiPageContent,
12+
EuiPageContentBody,
13+
EuiPageContentHeader,
14+
EuiPageHeader,
15+
EuiTitle,
16+
EuiText,
17+
} from '@elastic/eui';
18+
19+
import { CoreStart } from '../../../../core/public';
20+
import { NavigationPublicPluginStart } from '../../../navigation/public';
21+
22+
import { PLUGIN_ID, PLUGIN_NAME } from '../../common';
23+
24+
interface GoogleAnalyticAppDeps {
25+
basename: string;
26+
notifications: CoreStart['notifications'];
27+
http: CoreStart['http'];
28+
navigation: NavigationPublicPluginStart;
29+
}
30+
31+
export const GoogleAnalyticApp = ({
32+
basename,
33+
notifications,
34+
http,
35+
navigation,
36+
}: GoogleAnalyticAppDeps) => {
37+
// Use React hooks to manage state.
38+
const [timestamp, setTimestamp] = useState<string | undefined>();
39+
40+
const onClickHandler = () => {
41+
setTimestamp(new Date().toISOString());
42+
notifications.toasts.addSuccess(PLUGIN_NAME);
43+
};
44+
45+
// Render the application DOM.
46+
// Note that `navigation.ui.TopNavMenu` is a stateful component exported on the `navigation` plugin's start contract.
47+
return (
48+
<Router basename={basename}>
49+
<I18nProvider>
50+
<>
51+
<navigation.ui.TopNavMenu
52+
appName={PLUGIN_ID}
53+
showSearchBar={true}
54+
useDefaultBehaviors={true}
55+
/>
56+
<EuiPage restrictWidth="1000px">
57+
<EuiPageBody component="main">
58+
<EuiPageHeader>
59+
<EuiTitle size="l">
60+
<h1>
61+
<FormattedMessage
62+
id="googleAnalytic.helloWorldText"
63+
defaultMessage="{name}"
64+
values={{ name: PLUGIN_NAME }}
65+
/>
66+
</h1>
67+
</EuiTitle>
68+
</EuiPageHeader>
69+
<EuiPageContent>
70+
<EuiPageContentHeader>
71+
<EuiTitle>
72+
<h2>
73+
<FormattedMessage
74+
id="googleAnalytic.congratulationsTitle"
75+
defaultMessage="Congratulations, you have successfully created a new OpenSearch Dashboards Plugin!"
76+
/>
77+
</h2>
78+
</EuiTitle>
79+
</EuiPageContentHeader>
80+
<EuiPageContentBody>
81+
<EuiText>
82+
<p>
83+
<FormattedMessage
84+
id="googleAnalytic.content"
85+
defaultMessage="Look through the generated code and check out the plugin development documentation."
86+
/>
87+
</p>
88+
<EuiHorizontalRule />
89+
<p>
90+
<FormattedMessage
91+
id="googleAnalytic.timestampText"
92+
defaultMessage="Last timestamp: {time}"
93+
values={{ time: timestamp ? timestamp : 'Unknown' }}
94+
/>
95+
</p>
96+
<EuiButton type="primary" size="s" onClick={onClickHandler}>
97+
<FormattedMessage id="googleAnalytic.buttonText" defaultMessage="Click me" />
98+
</EuiButton>
99+
</EuiText>
100+
</EuiPageContentBody>
101+
</EuiPageContent>
102+
</EuiPageBody>
103+
</EuiPage>
104+
</>
105+
</I18nProvider>
106+
</Router>
107+
);
108+
};

0 commit comments

Comments
 (0)