Skip to content

Commit

Permalink
Migrate notifications frontend plugin to OpenSearch Dashboards 1.15 (o…
Browse files Browse the repository at this point in the history
…pensearch-project#1)

* Migrate frontend to Opensearch

* Add readme for dashboards notifications

* Move notifications-kibana-plugin to dashboards-notifications

* Remove opendistro in dashboards notifications

* Update documents for repo

* rename kibana

* Address comments
  • Loading branch information
joshuali925 authored and ansjcy committed Jan 9, 2023
1 parent e4e5664 commit 00e7f9a
Show file tree
Hide file tree
Showing 149 changed files with 15,422 additions and 9 deletions.
18 changes: 18 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": { "node": "10" }
}
],
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-modules-commonjs",
["@babel/plugin-transform-runtime", { "regenerator": true }],
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
]
}
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
extends: '@elastic/kibana'

settings:
import/resolver:
'@osd/eslint-import-resolver-kibana':
rootPackageName: 'notifications-dashboards'
pluginPaths:
- .
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: 🐛 Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: 'bug, untriaged, Beta'
labels: bug
assignees: ''
---

Expand Down
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
npm-debug.log*
node_modules
/build/
/public/app.css
.idea/
yarn-error.log
/coverage/
.DS_Store
/cypress/screenshots/
/cypress/videos/
target
3 changes: 3 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*.{ts,tsx,js,jsx,json,css,md}": ["prettier --write", "git add"]
}
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.vscode
build
coverage
node_modules
npm-debug.log
yarn.lock
*.md
*.lock
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 80,
"bracketSpacing": true
}
65 changes: 57 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
## My Project
# OpenSearch Dashboards Notifications

TODO: Fill this README out!
Dashboards Notifications plugin provides an interface that helps users to manage and view notifications using the OpenSearch Notifications plugin.

Be sure to:
## Documentation

* Change the title in this README
* Edit your repository description on GitHub
Please see our technical [documentation](https://opendistro.github.io/for-elasticsearch-docs/) to learn more about its features.

## Security
## Setup

See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
1. Download OpenSearch for the version that matches the [OpenSearch Dashboards version specified in package.json](./package.json#L7).
1. Download the OpenSearch Dashboards source code for the [version specified in package.json](./package.json#L7) you want to set up.

1. Change your node version to the version specified in `.node-version` inside the OpenSearch Dashboards root directory.
1. Create a `plugins` directory inside the OpenSearch Dashboards source code directory, if `plugins` directory doesn't exist.
1. Check out this package from version control into the `plugins` directory.
```
git clone git@github.com:opensearch-project/notifications.git plugins --no-checkout
cd plugins
echo 'dashboards-notifications/*' >> .git/info/sparse-checkout
git config core.sparseCheckout true
git checkout dev
```
1. Run `yarn osd bootstrap` inside `OpenSearch-Dashboards/plugins/dashboards-notifications`.

Ultimately, your directory structure should look like this:

```md
.
├── OpenSearch Dashboards
│ └── plugins
│ └── dashboards-notifications
```

## Build

To build the plugin's distributable zip simply run `yarn build`.

Example output: `./build/notificationsDashboards*.zip`


## Run

- `yarn start`

Starts OpenSearch Dashboards and includes this plugin. OpenSearch Dashboards will be available on `localhost:5601`.

- `yarn test`

Runs the plugin unit tests.

## Contributing to OpenSearch Dashboards Notifications

We welcome you to get involved in development, documentation, testing the Notifications plugin. See our [CONTRIBUTING.md](./../CONTRIBUTING.md) and join in.

## Bugs, Enhancements or Questions

Please file an issue to report any bugs you may find, enhancements you may need or questions you may have [here](https://github.com/opensearch-project/dashboards-notifications/issues).

## License

This project is licensed under the Apache-2.0 License.
This code is licensed under the Apache 2.0 License.

## Copyright

Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
46 changes: 46 additions & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

export const PLUGIN_ID = 'notificationsDashboards';
export const PLUGIN_NAME = 'notifications-dashboards';

export enum SORT_DIRECTION {
ASC = 'asc',
DESC = 'desc',
}

export const BASE_API_PATH = '/api/notifications';
export const NODE_API = Object.freeze({
NOTIFICATIONS: `${BASE_API_PATH}/notifications`,
_SEARCH: `${BASE_API_PATH}/_search`,
_INDICES: `${BASE_API_PATH}/_indices`,
_MAPPINGS: `${BASE_API_PATH}/_mappings`,
APPLY_POLICY: `${BASE_API_PATH}/applyPolicy`,
EDIT_ROLLOVER_ALIAS: `${BASE_API_PATH}/editRolloverAlias`,
POLICIES: `${BASE_API_PATH}/policies`,
ROLLUPS: `${BASE_API_PATH}/rollups`,
MANAGED_INDICES: `${BASE_API_PATH}/managedIndices`,
RETRY: `${BASE_API_PATH}/retry`,
CHANGE_POLICY: `${BASE_API_PATH}/changePolicy`,
REMOVE_POLICY: `${BASE_API_PATH}/removePolicy`,
});

export const REQUEST = Object.freeze({
PUT: 'PUT',
DELETE: 'DELETE',
GET: 'GET',
POST: 'POST',
HEAD: 'HEAD',
});
82 changes: 82 additions & 0 deletions models/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import { Direction } from '@elastic/eui';

export interface NotificationItem {
title: string;
channel: ChannelOverview; // those will be prepared by OpenSearch Dashboards server. UI model vs Backend Model
referenceId: string; // TODO: this should probably be sourcelink, which is created by OpenSearch Dashboards server using source + ref_id and a dictionary of plugin url
source: string;
severity: string;
status: { overview: string; detail: NotificationStatusDetail[] };
sentTime: number;
lastUpdatedTime: number;
}

export interface NotificationStatusDetail {
recipient: string; // if email, this will be email address.
statusCode: number;
statusText: string;
}

export interface ChannelOverview {
id: string;
name: string;
type: string;
}

export interface ChannelItemType {
id: string;
name: string;
enabled: boolean; // active or muted
type: string;
allowedFeatures: string[];
lastUpdatedTime: number;
destination: {
[type: string]: object;
};
description?: string;
}

export interface SenderItemType {
id: string;
name: string;
from: string; // outbound email address
host: string;
port: string;
method: ENCRYPTION_METHOD;
}

export interface RecipientGroupItemType {
id: string;
name: string;
email: Array<{ email: string }>;
description?: string;
}

export interface TableState<T> {
total: number;
from: number;
size: number;
search: string;
sortField: any; // keyof T
sortDirection: Direction;
selectedItems: T[];
items: T[];
loading: boolean;
}

export type ENCRYPTION_METHOD = 'SSL' | 'TSL';
10 changes: 10 additions & 0 deletions opensearch-dashboards-plugin-helpers.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"serverSourcePatterns": [
"package.json",
"tsconfig.json",
"yarn.lock",
".yarnrc",
"{lib,public,server,webpackShims,translations,utils,models,test}/**/*",
"!__tests__"
]
}
9 changes: 9 additions & 0 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "notificationsDashboards",
"version": "1.15.0.0",
"opensearchDashboardsVersion": "7.10.2",
"requiredPlugins": ["navigation", "data"],
"optionalPlugins": ["share"],
"server": true,
"ui": true
}
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "notifications-dashboards",
"version": "1.15.0.0",
"description": "OpenSearch Dashboards Notifications Plugin",
"license": "Apache-2.0",
"main": "index.ts",
"opensearchDashboards": {
"version": "7.10.2",
"templateVersion": "1.0.0"
},
"scripts": {
"osd": "node ../../scripts/osd",
"opensearch": "node ../../scripts/opensearch",
"lint": "eslint .",
"start": "yarn plugin_helpers start",
"build": "yarn plugin_helpers build",
"test": "../../node_modules/.bin/jest --config ./test/jest.config.js",
"cypress:run": "cypress run",
"cypress:open": "cypress open",
"plugin_helpers": "node ../../scripts/plugin_helpers"
},
"dependencies": {
"react-mde": "^10.2.1",
"showdown": "^1.9.1"
},
"devDependencies": {
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/showdown": "^1.9.3",
"enzyme-adapter-react-16": "^1.15.2",
"jest": "^26.4.2",
"jest-dom": "^4.0.0",
"@types/showdown": "^1.9.3"
}
}
47 changes: 47 additions & 0 deletions public/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter as Router, Route } from 'react-router-dom';
import { AppMountParameters, CoreStart } from '../../../src/core/public';
import { CoreServicesContext } from './components/coreServices';
import Main from './pages/Main';
import { NotificationService } from './services';
import { ServicesContext } from './services/services';
import { AppPluginStartDependencies } from './types';

export const renderApp = (coreStart: CoreStart, params: AppMountParameters) => {
const http = coreStart.http;
const notificationService = new NotificationService(http);
const services = { notificationService };

ReactDOM.render(
<Router>
<Route
render={(props) => (
<ServicesContext.Provider value={services}>
<CoreServicesContext.Provider value={coreStart}>
<Main {...props} />
</CoreServicesContext.Provider>
</ServicesContext.Provider>
)}
/>
</Router>,
params.element
);

return () => ReactDOM.unmountComponentAtNode(params.element);
};
Loading

0 comments on commit 00e7f9a

Please sign in to comment.