From 2ba920ad4bb1d9ea803528749be078bbebc2a626 Mon Sep 17 00:00:00 2001 From: Sworup Shakya Date: Mon, 4 Apr 2022 12:16:13 +0545 Subject: [PATCH 01/98] Initial start --- .DS_Store | Bin 0 -> 6148 bytes .eslintrc.js | 7 + .github/workflows/ci.yml | 75 + .github/workflows/release.yml | 164 + .gitignore | 54 +- .prettierrc.js | 3 + .webpack/constants.js | 9 + .webpack/utils.js | 23 + .webpack/webpack.dev.conf.js | 206 + .webpack/webpack.prod.conf.js | 203 + CHANGELOG.md | 5 + backend/LICENSE => LICENSE | 0 Magefile.go | 17 + README.md | 55 +- backend/.gitignore | 50 - backend/.prettierrc.js | 3 - backend/.vscode/launch.json | 16 - backend/Magefile.go | 21 - backend/README.md | 9 - backend/debug.sh | 22 - backend/mage.go | 11 - backend/pkg/api/dashboard.go | 212 - backend/pkg/api/panel.go | 189 - backend/pkg/api/users.go | 60 - backend/pkg/auth/auth_config.go | 54 - backend/pkg/auth/email_config.go | 24 - backend/pkg/emailer/emailer.go | 49 - backend/pkg/main.go | 67 - backend/pkg/serve_options.go | 27 - backend/pkg/server/errors.go | 16 - backend/pkg/server/export_panel.go | 79 - backend/pkg/server/report_content.go | 131 - backend/pkg/server/report_group.go | 108 - backend/pkg/server/report_group_membership.go | 90 - backend/src/ConfigEditor.tsx | 14 - backend/src/DataSource.ts | 9 - backend/src/QueryEditor.tsx | 13 - backend/src/module.tsx | 12 - backend/src/plugin.json | 37 - backend/tsconfig.json | 10 - frontend/.prettierrc.js | 4 - frontend/LICENSE | 201 - frontend/README.md | 3 - frontend/jest.config.js | 8 - frontend/src/common/enums.ts | 22 - frontend/src/common/index.ts | 6 - frontend/src/common/types.ts | 138 - frontend/src/common/utils/checkers.ts | 17 - frontend/src/common/utils/options.ts | 14 - frontend/src/common/utils/parsers.ts | 7 - frontend/src/components/FieldInput.tsx | 51 - frontend/src/components/FieldSelect.tsx | 25 - .../components/Groups/EditReportGroupForm.tsx | 59 - .../Groups/EditReportGroupModal.tsx | 89 - .../Groups/EditReportScheduleModal.tsx | 101 - .../src/components/Groups/ReportGroupList.tsx | 39 - .../src/components/Groups/ReportGroupTab.tsx | 54 - frontend/src/components/RootPage.tsx | 47 - .../components/Schedules/EditScheduleForm.tsx | 157 - .../src/components/Schedules/PanelItem.tsx | 102 - .../src/components/Schedules/PanelList.tsx | 125 - .../Schedules/PanelVariableOption.tsx | 75 - .../Schedules/PanelVariableTextInput.tsx | 28 - .../components/Schedules/PanelVariables.tsx | 86 - .../Schedules/ReportSchedulesTab.tsx | 50 - .../src/components/Schedules/ScheduleList.tsx | 42 - .../components/Settings/AppConfiguration.tsx | 64 - .../src/components/Settings/DisabledState.tsx | 26 - frontend/src/components/index.ts | 4 - frontend/src/containers/AppDataContext.tsx | 6 - frontend/src/containers/ConfigPageFactory.tsx | 45 - frontend/src/containers/index.ts | 2 - frontend/src/hooks/index.ts | 9 - frontend/src/hooks/useDatasource.ts | 14 - frontend/src/hooks/useOptimisticMutation.ts | 37 - frontend/src/hooks/useTabs.ts | 35 - frontend/src/hooks/useToggle.ts | 11 - frontend/src/hooks/useWindowResize.ts | 29 - frontend/src/jest.config.js | 8 - frontend/src/module.ts | 25 - frontend/src/msupply_light_icon.svg | 4 - frontend/src/plugin.json | 60 - frontend/tsconfig.json | 10 - go.mod | 8 + go.sum | 659 + backend/jest.config.js => jest.config.js | 0 logo.png | Bin 3176 -> 0 bytes package.json | 53 + pkg/main.go | 24 + pkg/plugin/plugin.go | 194 + pkg/plugin/plugin_test.go | 30 + src/.DS_Store | Bin 0 -> 6148 bytes src/RootPage.tsx | 0 src/components/App.tsx | 19 + src/components/AppConfigForm.tsx | 335 + src/components/Pages/AppConfig.tsx | 29 + src/components/Pages/PageOne.tsx | 25 + src/components/Routes.tsx | 15 + src/components/SecretInput.tsx | 25 + src/constants.ts | 36 + src/context/index.ts | 3 + src/context/plugin.context.ts | 17 + src/img/.DS_Store | Bin 0 -> 6148 bytes .../src => src/img}/msupply_light_icon.svg | 0 .../translations => src/locales}/en.json | 0 .../translations => src/locales}/index.ts | 0 src/module.ts | 12 + src/plugin.json | 55 + src/routes/router.ts | 63 + {backend/src => src}/types.ts | 11 +- template.xlsx | Bin 10170 -> 0 bytes tsconfig.json | 12 + yarn.lock | 13627 ++++++++++++++++ 113 files changed, 15982 insertions(+), 3363 deletions(-) create mode 100644 .DS_Store create mode 100644 .eslintrc.js create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .prettierrc.js create mode 100644 .webpack/constants.js create mode 100644 .webpack/utils.js create mode 100644 .webpack/webpack.dev.conf.js create mode 100644 .webpack/webpack.prod.conf.js create mode 100644 CHANGELOG.md rename backend/LICENSE => LICENSE (100%) create mode 100644 Magefile.go delete mode 100644 backend/.gitignore delete mode 100644 backend/.prettierrc.js delete mode 100644 backend/.vscode/launch.json delete mode 100644 backend/Magefile.go delete mode 100644 backend/README.md delete mode 100755 backend/debug.sh delete mode 100644 backend/mage.go delete mode 100644 backend/pkg/api/dashboard.go delete mode 100644 backend/pkg/api/panel.go delete mode 100644 backend/pkg/api/users.go delete mode 100644 backend/pkg/auth/auth_config.go delete mode 100644 backend/pkg/auth/email_config.go delete mode 100644 backend/pkg/emailer/emailer.go delete mode 100644 backend/pkg/main.go delete mode 100644 backend/pkg/serve_options.go delete mode 100644 backend/pkg/server/errors.go delete mode 100644 backend/pkg/server/export_panel.go delete mode 100644 backend/pkg/server/report_content.go delete mode 100644 backend/pkg/server/report_group.go delete mode 100644 backend/pkg/server/report_group_membership.go delete mode 100644 backend/src/ConfigEditor.tsx delete mode 100644 backend/src/DataSource.ts delete mode 100644 backend/src/QueryEditor.tsx delete mode 100644 backend/src/module.tsx delete mode 100644 backend/src/plugin.json delete mode 100644 backend/tsconfig.json delete mode 100644 frontend/.prettierrc.js delete mode 100644 frontend/LICENSE delete mode 100644 frontend/README.md delete mode 100644 frontend/jest.config.js delete mode 100644 frontend/src/common/enums.ts delete mode 100644 frontend/src/common/index.ts delete mode 100644 frontend/src/common/types.ts delete mode 100644 frontend/src/common/utils/checkers.ts delete mode 100644 frontend/src/common/utils/options.ts delete mode 100644 frontend/src/common/utils/parsers.ts delete mode 100644 frontend/src/components/FieldInput.tsx delete mode 100644 frontend/src/components/FieldSelect.tsx delete mode 100644 frontend/src/components/Groups/EditReportGroupForm.tsx delete mode 100644 frontend/src/components/Groups/EditReportGroupModal.tsx delete mode 100644 frontend/src/components/Groups/EditReportScheduleModal.tsx delete mode 100644 frontend/src/components/Groups/ReportGroupList.tsx delete mode 100644 frontend/src/components/Groups/ReportGroupTab.tsx delete mode 100644 frontend/src/components/RootPage.tsx delete mode 100644 frontend/src/components/Schedules/EditScheduleForm.tsx delete mode 100644 frontend/src/components/Schedules/PanelItem.tsx delete mode 100644 frontend/src/components/Schedules/PanelList.tsx delete mode 100644 frontend/src/components/Schedules/PanelVariableOption.tsx delete mode 100644 frontend/src/components/Schedules/PanelVariableTextInput.tsx delete mode 100644 frontend/src/components/Schedules/PanelVariables.tsx delete mode 100644 frontend/src/components/Schedules/ReportSchedulesTab.tsx delete mode 100644 frontend/src/components/Schedules/ScheduleList.tsx delete mode 100644 frontend/src/components/Settings/AppConfiguration.tsx delete mode 100644 frontend/src/components/Settings/DisabledState.tsx delete mode 100644 frontend/src/components/index.ts delete mode 100644 frontend/src/containers/AppDataContext.tsx delete mode 100644 frontend/src/containers/ConfigPageFactory.tsx delete mode 100644 frontend/src/containers/index.ts delete mode 100644 frontend/src/hooks/index.ts delete mode 100644 frontend/src/hooks/useDatasource.ts delete mode 100644 frontend/src/hooks/useOptimisticMutation.ts delete mode 100644 frontend/src/hooks/useTabs.ts delete mode 100644 frontend/src/hooks/useToggle.ts delete mode 100644 frontend/src/hooks/useWindowResize.ts delete mode 100644 frontend/src/jest.config.js delete mode 100644 frontend/src/module.ts delete mode 100644 frontend/src/msupply_light_icon.svg delete mode 100644 frontend/src/plugin.json delete mode 100644 frontend/tsconfig.json create mode 100644 go.mod create mode 100644 go.sum rename backend/jest.config.js => jest.config.js (100%) delete mode 100644 logo.png create mode 100644 package.json create mode 100644 pkg/main.go create mode 100644 pkg/plugin/plugin.go create mode 100644 pkg/plugin/plugin_test.go create mode 100644 src/.DS_Store create mode 100644 src/RootPage.tsx create mode 100644 src/components/App.tsx create mode 100644 src/components/AppConfigForm.tsx create mode 100644 src/components/Pages/AppConfig.tsx create mode 100644 src/components/Pages/PageOne.tsx create mode 100644 src/components/Routes.tsx create mode 100644 src/components/SecretInput.tsx create mode 100644 src/constants.ts create mode 100644 src/context/index.ts create mode 100644 src/context/plugin.context.ts create mode 100644 src/img/.DS_Store rename {backend/src => src/img}/msupply_light_icon.svg (100%) rename {frontend/src/common/translations => src/locales}/en.json (100%) rename {frontend/src/common/translations => src/locales}/index.ts (100%) create mode 100644 src/module.ts create mode 100644 src/plugin.json create mode 100644 src/routes/router.ts rename {backend/src => src}/types.ts (69%) delete mode 100644 template.xlsx create mode 100644 tsconfig.json create mode 100644 yarn.lock diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9e13546680a44eef5b3aedf62bb852a2759eb867 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8rihq>V2^w8)i>8pDae^&S4a$jvr29ne2NL2)R7>LoZqkqIu{gavobb>L??#k!8K^ep7UM zy}T*1ey7zG-F_#}>&EV0``~zdd;gF<=1z3+16OX3n;q0J39`8D7=A@GP;Z+ zBnF59Vt^R`p release_notes.md + echo "::set-output name=path::release_notes.md" + + - name: Check package version + run: if [ "v${{ steps.metadata.outputs.plugin-version }}" != "${{ steps.metadata.outputs.github-tag }}" ]; then printf "\033[0;31mPlugin version doesn't match tag name\033[0m\n"; exit 1; fi + + - name: Package plugin + id: package-plugin + run: | + mv dist ${{ steps.metadata.outputs.plugin-id }} + zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r + md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }} + echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)" + + - name: Lint plugin + run: | + git clone https://github.com/grafana/plugin-validator + pushd ./plugin-validator/pkg/cmd/plugincheck + go install + popd + plugincheck ${{ steps.metadata.outputs.archive }} + + - name: Create release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + body_path: ${{ steps.changelog.outputs.path }} + draft: true + + - name: Add plugin to release + id: upload-plugin-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./${{ steps.metadata.outputs.archive }} + asset_name: ${{ steps.metadata.outputs.archive }} + asset_content_type: application/zip + + - name: Add checksum to release + id: upload-checksum-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./${{ steps.metadata.outputs.archive-checksum }} + asset_name: ${{ steps.metadata.outputs.archive-checksum }} + asset_content_type: text/plain + + - name: Publish to Grafana.com + run: | + echo A draft release has been created for your plugin. Please review and publish it. Then submit your plugin to grafana.com/plugins by opening a PR to https://github.com/grafana/grafana-plugin-repository with the following entry: + echo + echo '{ "id": "${{ steps.metadata.outputs.plugin-id }}", "type": "${{ steps.metadata.outputs.plugin-type }}", "url": "https://github.com/${{ github.repository }}", "versions": [ { "version": "${{ steps.metadata.outputs.plugin-version }}", "commit": "${{ github.sha }}", "url": "https://github.com/${{ github.repository }}", "download": { "any": { "url": "https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive }}", "md5": "${{ steps.package-plugin.outputs.checksum }}" } } } ] }' | jq . diff --git a/.gitignore b/.gitignore index 6db947a..b315310 100644 --- a/.gitignore +++ b/.gitignore @@ -1,52 +1,30 @@ -########################## -# Application specfic -########################## -# config/config.js - -########################## -# General -########################## - -##### -# OS X temporary files -# -# c.f. http://www.westwind.com/reference/os-x/invisibles.html -.DS_Store - -# c.f. http://www.westwind.com/reference/os-x/invisibles.html -.Trashes - -# c.f. http://www.westwind.com/reference/os-x/invisibles.html -*.swp - -##### -# Node stuff -# # Logs logs *.log npm-debug.log* +yarn-debug.log* +yarn-error.log* + +node_modules/ # Runtime data pids *.pid *.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov # Coverage directory used by tools like istanbul coverage -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -*/dist -*/gpx_* - -# Dependency directory -# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git -node_modules +# Compiled binary addons (https://nodejs.org/api/addons.html) +dist/ +artifacts/ +work/ +ci/ +e2e-results/ -**/dist \ No newline at end of file +# Editor +.idea diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..21cece8 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,3 @@ +module.exports = { + ...require("./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json"), +}; \ No newline at end of file diff --git a/.webpack/constants.js b/.webpack/constants.js new file mode 100644 index 0000000..6ea37e4 --- /dev/null +++ b/.webpack/constants.js @@ -0,0 +1,9 @@ +const SOURCE_DIR = 'src'; +const DIST_DIR = 'dist'; +const ENTRY_FILE = `${SOURCE_DIR}/module.ts`; + +module.exports = { + SOURCE_DIR, + DIST_DIR, + ENTRY_FILE, +}; diff --git a/.webpack/utils.js b/.webpack/utils.js new file mode 100644 index 0000000..2a3054d --- /dev/null +++ b/.webpack/utils.js @@ -0,0 +1,23 @@ +const fs = require('fs'); +const path = require('path'); +const { SOURCE_DIR } = require('./constants'); + +module.exports = { + getPackageJson, + getPluginId, + hasReadme, +}; + +function getPackageJson() { + return require(path.resolve(process.cwd(), 'package.json')); +} + +function getPluginId() { + const { id } = require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`)); + + return id; +} + +function hasReadme() { + return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md')); +} diff --git a/.webpack/webpack.dev.conf.js b/.webpack/webpack.dev.conf.js new file mode 100644 index 0000000..e4a6701 --- /dev/null +++ b/.webpack/webpack.dev.conf.js @@ -0,0 +1,206 @@ +const path = require('path'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin'); +const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); +const LiveReloadPlugin = require('webpack-livereload-plugin'); +const { getPackageJson, getPluginId, hasReadme } = require('./utils'); +const { SOURCE_DIR, DIST_DIR, ENTRY_FILE } = require('./constants'); + +module.exports = { + mode: 'development', + + // Compile for browsers + target: 'web', + + // The "root dir" for the source code + context: path.join(process.cwd(), SOURCE_DIR), + + // Source map type + devtool: 'source-map', + + entry: { + module: path.resolve(process.cwd(), ENTRY_FILE), + }, + + output: { + filename: '[name].js', + path: path.resolve(process.cwd(), DIST_DIR), + libraryTarget: 'amd', + publicPath: '/', + }, + + // Don't show hints (e.g. asset size is over 250kb) + performance: { hints: false }, + + // External packages + // (these are going to be provided by the Grafana runtime) + externals: [ + 'lodash', + 'jquery', + 'moment', + 'slate', + 'emotion', + '@emotion/react', + '@emotion/css', + 'prismjs', + 'slate-plain-serializer', + '@grafana/slate-react', + 'react', + 'react-dom', + 'react-redux', + 'redux', + 'rxjs', + 'd3', + 'angular', + '@grafana/ui', + '@grafana/runtime', + '@grafana/data', + + // Mark packages as external in case their name starts with the "grafana/" prefix + // @ts-ignore + ({ request }, callback) => { + const prefix = 'grafana/'; + const hasPrefix = (request) => request.indexOf(prefix) === 0; + const stripPrefix = (request) => request.substr(prefix.length); + + if (hasPrefix(request)) { + return callback(null, stripPrefix(request)); + } + + // @ts-ignore + callback(); + }, + ], + + // Order modules and chunks by occurance + optimization: { chunkIds: 'total-size', moduleIds: 'size' }, + + plugins: [ + // Copy static files + new CopyWebpackPlugin({ + patterns: [ + // If src/README.md exists use it; otherwise the root README + // To `compiler.options.output` + { from: hasReadme() ? 'README.md' : '../README.md', to: '.', force: true }, + { from: 'plugin.json', to: '.' }, + { from: '../LICENSE', to: '.' }, + { from: '../CHANGELOG.md', to: '.', force: true }, + { from: '**/*.json', to: '.' }, // TODO + { from: '**/*.svg', to: '.', noErrorOnMissing: true }, // Optional + { from: '**/*.png', to: '.', noErrorOnMissing: true }, // Optional + { from: '**/*.html', to: '.', noErrorOnMissing: true }, // Optional + { from: 'img/**/*', to: '.', noErrorOnMissing: true }, // Optional + { from: 'libs/**/*', to: '.', noErrorOnMissing: true }, // Optional + { from: 'static/**/*', to: '.', noErrorOnMissing: true }, // Optional + ], + }), + + // Replace certain template-variables in the README and plugin.json + new ReplaceInFileWebpackPlugin([ + { + dir: DIST_DIR, + files: ['plugin.json', 'README.md'], + rules: [ + { + search: /\%VERSION\%/g, + replace: getPackageJson().version, + }, + { + search: /\%TODAY\%/g, + replace: new Date().toISOString().substring(0, 10), + }, + { + search: /\%PLUGIN_ID\%/g, + replace: getPluginId(), + }, + ], + }, + ]), + + // Move type checking and ESLint linting to separate processes + new ForkTsCheckerWebpackPlugin({ + typescript: { + configFile: path.resolve(process.cwd(), 'tsconfig.json'), + }, + }), + + // Add live reload functionality. Requires