From e4aa7fb26846c7eb1828d8c882ff2ba23e856dfc Mon Sep 17 00:00:00 2001 From: mcbrewster <37322608+mcbrewster@users.noreply.github.com> Date: Tue, 20 Aug 2019 21:40:47 -0600 Subject: [PATCH] Web-console: fix alerts from lgtm (#8346) * fix alerts from lgtm * remove unordered imports * fix introduced alert * move getExpanded to renderSchemaSelector * use getDerivedStateFromProps * use prevState * add semi colons, remove unused imports * fixes --- web-console/README.md | 5 +- web-console/script/build | 1 + web-console/script/licenses | 201 +++++++++--------- .../datasource-columns-table.tsx | 2 +- .../__snapshots__/external-link.spec.tsx.snap | 1 + .../external-link/external-link.tsx | 2 +- .../components/show-history/show-history.tsx | 6 +- .../__snapshots__/show-log.spec.tsx.snap | 37 +++- .../src/components/show-log/show-log.tsx | 19 +- .../supervisor-statistics-table.tsx | 2 +- web-console/src/console-application.tsx | 2 - .../__snapshots__/about-dialog.spec.tsx.snap | 3 + ...inator-dynamic-config-dialog.spec.tsx.snap | 1 + .../datasource-table-action-dialog.tsx | 25 --- ...erload-dynamic-config-dialog.spec.tsx.snap | 1 + .../views/datasource-view/datasource-view.tsx | 18 +- .../views/load-data-view/load-data-view.tsx | 2 - .../src/views/lookups-view/lookups-view.tsx | 8 +- .../query-view/column-tree/column-tree.tsx | 26 ++- .../src/views/query-view/query-view.tsx | 6 +- .../query-view/run-button/run-button.tsx | 3 - .../src/views/segments-view/segments-view.tsx | 8 +- .../src/views/servers-view/servers-view.tsx | 6 +- .../src/views/task-view/tasks-view.tsx | 8 +- .../src/visualization/stacked-bar-chart.tsx | 21 +- web-console/webpack.config.js | 12 +- 26 files changed, 225 insertions(+), 201 deletions(-) diff --git a/web-console/README.md b/web-console/README.md index 0d8c7a47b59..0f13ce886da 100644 --- a/web-console/README.md +++ b/web-console/README.md @@ -27,8 +27,8 @@ This is the unified Druid web console that servers as a data management layer fo 2. Install the modules with `npm install` 3. Run `npm start` will start in development mode and will proxy druid requests to `localhost:8888` -**Note:** you can provide an environment variable to proxy to a different Druid host like so: `druid_host=1.2.3.4:8888 npm start` - +**Note:** you can provide an environment variable to proxy to a different Druid host like so: `druid_host=1.2.3.4:8888 npm start` +**Note:** you can provide an environment variable use webpack-bundle-analyzer as a plugin in the build script or like so: `BUNDLE_ANALYZER_PLUGIN='TRUE' npm start` ## Description of the directory structure @@ -50,7 +50,6 @@ Generated/copied dynamically - `pages/` - The files for the older coordinator console - `coordinator-console/` - Files for the coordinator console - ## List of non SQL data reading APIs used ``` diff --git a/web-console/script/build b/web-console/script/build index 253ebc3a153..46c2f815ed3 100755 --- a/web-console/script/build +++ b/web-console/script/build @@ -29,6 +29,7 @@ PATH="./target/node:$PATH" ./script/create-sql-function-doc.js echo "Transpiling ReactTable CSS..." PATH="./target/node:$PATH" ./node_modules/.bin/stylus lib/react-table.styl -o lib/react-table.css +# add BUNDLE_ANALYZER_PLUGIN='TRUE' here to enable webpack-bundle-analyzer as a plugin echo "Webpacking everything..." PATH="./target/node:$PATH" NODE_ENV=production ./node_modules/.bin/webpack -c webpack.config.js diff --git a/web-console/script/licenses b/web-console/script/licenses index 19b0fb3efbf..6f0d7688ad1 100755 --- a/web-console/script/licenses +++ b/web-console/script/licenses @@ -60,116 +60,119 @@ function injectConsoleLicenses(consoleLicenses) { // Write out the new file fs.writeFileSync( LICENSES_FILE, - [ - beforeLines.join('\n'), - consoleLicenses.join(SEPARATOR), - afterLines.join('\n') - ].join('\n') + [beforeLines.join('\n'), consoleLicenses.join(SEPARATOR), afterLines.join('\n')].join('\n'), ); } -checker.init({ - start: '.', - production: true -}, function(err, packages) { - if (err) { - console.log('err', err); - return; - } - - const mapped = Object.keys(packages).sort().map(p => { - const m = p.match(/^(.+)@(\d+\.\d+\.\d+.*)$/); - if (!m) throw new Error(`Malformed name@version`); - const name = m[1]; - if (name === 'web-console') return null; // This is me! - - const version = m[2]; - const meta = packages[p]; - let { publisher, licenses, licenseFile } = meta; - if (!licenses) throw new Error(`Package '${p} does not have a licenses`); - - let properLicenseName; // Map the licenses to their proper name - let licenseExt; // Map the licenses to the right extension - switch (licenses) { - case 'MIT': - properLicenseName = 'MIT License'; - licenseExt = 'MIT'; - break; - - case 'Apache-2.0': - properLicenseName = 'Apache License version 2.0'; - licenseExt = 'A2'; - break; - - case 'BSD-3-Clause': - properLicenseName = 'BSD-3-Clause License'; - licenseExt = 'BSD3'; - break; - - default: - throw new Error(`Unknown license '${licenses}' in ${p}`); +checker.init( + { + start: '.', + production: true, + }, + function(err, packages) { + if (err) { + console.log('err', err); + return; } - const simpleName = name.replace('/', '-'); - const licenseDest = `licenses/bin/${simpleName}.${licenseExt}` + const mapped = Object.keys(packages) + .sort() + .map(p => { + const m = p.match(/^(.+)@(\d+\.\d+\.\d+.*)$/); + if (!m) throw new Error(`Malformed name@version`); + const name = m[1]; + if (name === 'web-console') return null; // This is me! - let hasLicense = false; - if (licenseExt !== 'A2') { - if (licenseFile && licenseFile.match(/\/license(?:\.\w+)?/i)) { - // If the file ends with license.ext? then copy it over - try { - fs.copyFileSync(licenseFile, `../${licenseDest}`); - hasLicense = true; - } catch (e) { - console.log(`Could not copy license for '${p}': ${JSON.stringify(meta)}`); + const version = m[2]; + const meta = packages[p]; + let { publisher, licenses, licenseFile } = meta; + if (!licenses) throw new Error(`Package '${p} does not have a licenses`); + + let properLicenseName; // Map the licenses to their proper name + let licenseExt; // Map the licenses to the right extension + switch (licenses) { + case 'MIT': + properLicenseName = 'MIT License'; + licenseExt = 'MIT'; + break; + + case 'Apache-2.0': + properLicenseName = 'Apache License version 2.0'; + licenseExt = 'A2'; + break; + + case 'BSD-3-Clause': + properLicenseName = 'BSD-3-Clause License'; + licenseExt = 'BSD3'; + break; + + default: + throw new Error(`Unknown license '${licenses}' in ${p}`); } - } else { - // See if the license is already there (manually) keep it - try { - fs.statSync(`../${licenseDest}`); - hasLicense = true; - } catch (e) { - console.log(`Could not find license for '${p}': ${JSON.stringify(meta)}`); + + const simpleName = name.replace('/', '-'); + const licenseDest = `licenses/bin/${simpleName}.${licenseExt}`; + + let hasLicense = false; + if (licenseExt !== 'A2') { + if (licenseFile && licenseFile.match(/\/license(?:\.\w+)?/i)) { + // If the file ends with license.ext? then copy it over + try { + fs.copyFileSync(licenseFile, `../${licenseDest}`); + hasLicense = true; + } catch (e) { + console.log(`Could not copy license for '${p}': ${JSON.stringify(meta)}`); + } + } else { + // See if the license is already there (manually) keep it + try { + fs.statSync(`../${licenseDest}`); + hasLicense = true; + } catch (e) { + console.log(`Could not find license for '${p}': ${JSON.stringify(meta)}`); + } + } } - } - } - if (!publisher && hasLicense) { - // Extract copyright from license - const licenseText = fs.readFileSync(`../${licenseDest}`, 'utf-8'); - const m = licenseText.match(/(?:^|\n)\s*Copyright(?: (?:\(c\)|©))?(?: 2[0-9]{3}(?:-\w+)?,?)? ([^0-9][^\n]*)\n/m); - if (m) { - publisher = m[1] - .replace(/All rights reserved./i, '') - .replace(/[0-9-]{4,9}/, '') - .trim(); - } - } + if (!publisher && hasLicense) { + // Extract copyright from license + const licenseText = fs.readFileSync(`../${licenseDest}`, 'utf-8'); + const m = licenseText.match( + /(?:^|\n)\s*Copyright(?: (?:\(c\)|©))?(?: 2[0-9]{3}(?:-\w+)?,?)? ([^0-9][^\n]*)\n/m, + ); + if (m) { + publisher = m[1] + .replace(/All rights reserved./i, '') + .replace(/[0-9-]{4,9}/, '') + .trim(); + } + } - if (!publisher) { - // Hand coded copyrights - if (name === 'asap') publisher = 'Contributors' - if (name === 'diff-match-patch') publisher = 'Google' - } + if (!publisher) { + // Hand coded copyrights + if (name === 'asap') publisher = 'Contributors'; + if (name === 'diff-match-patch') publisher = 'Google'; + } - if (!publisher) { - console.log(`No license for '${name}' ('${licenseDest}')`); - } + if (!publisher) { + console.log(`No license for '${name}' ('${licenseDest}')`); + } - // Make our blob - const lines = [ - `name: "${name}"`, - `license_category: binary`, - `module: web-console`, - `license_name: ${properLicenseName}`, - publisher ? `copyright: ${publisher}` : null, - `version: ${version}`, - hasLicense ? `license_file_path: ${licenseDest}` : null, - ]; + // Make our blob + const lines = [ + `name: "${name}"`, + `license_category: binary`, + `module: web-console`, + `license_name: ${properLicenseName}`, + publisher ? `copyright: ${publisher}` : null, + `version: ${version}`, + hasLicense ? `license_file_path: ${licenseDest}` : null, + ]; - return lines.filter(Boolean).join('\n'); - }).filter(Boolean); - - injectConsoleLicenses(mapped); -}); + return lines.filter(Boolean).join('\n'); + }) + .filter(Boolean); + injectConsoleLicenses(mapped); + }, +); diff --git a/web-console/src/components/datasource-columns-table/datasource-columns-table.tsx b/web-console/src/components/datasource-columns-table/datasource-columns-table.tsx index e2ef567295a..d494fb9928d 100644 --- a/web-console/src/components/datasource-columns-table/datasource-columns-table.tsx +++ b/web-console/src/components/datasource-columns-table/datasource-columns-table.tsx @@ -105,7 +105,7 @@ export class DatasourceColumnsTable extends React.PureComponent< return (