From b83cd0d8830d1196ddb5f6494f53173c3573ea8f Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 6 Dec 2023 09:54:51 +0300 Subject: [PATCH] CB-4060 feat: remove data-testid attribute (#2166) Co-authored-by: mr-anton-t <42037741+mr-anton-t@users.noreply.github.com> --- .../src/FormControls/Checkboxes/Switch.tsx | 15 +-- .../core-blocks/src/FormControls/Combobox.tsx | 12 +- .../src/FormControls/InputField.tsx | 6 +- .../SnackbarMarkups/SnackbarBody.tsx | 10 +- .../SnackbarMarkups/SnackbarContent.tsx | 6 +- .../SnackbarMarkups/SnackbarFooter.tsx | 10 +- .../SnackbarMarkups/SnackbarStatus.tsx | 2 +- .../SnackbarMarkups/SnackbarWrapper.tsx | 2 +- .../packages/core-cli/configs/babel.config.js | 4 +- webapp/packages/core-cli/package.json | 3 - .../src/babel-plugins/TestingAttributes.ts | 122 ------------------ webapp/packages/core-cli/tsconfig.eslint.json | 10 -- webapp/packages/core-cli/tsconfig.json | 13 -- .../elementsTreeLimitRenderer.tsx | 2 +- 14 files changed, 23 insertions(+), 194 deletions(-) delete mode 100644 webapp/packages/core-cli/src/babel-plugins/TestingAttributes.ts delete mode 100644 webapp/packages/core-cli/tsconfig.eslint.json delete mode 100644 webapp/packages/core-cli/tsconfig.json diff --git a/webapp/packages/core-blocks/src/FormControls/Checkboxes/Switch.tsx b/webapp/packages/core-blocks/src/FormControls/Checkboxes/Switch.tsx index 53eff392f7..f2d0428593 100644 --- a/webapp/packages/core-blocks/src/FormControls/Checkboxes/Switch.tsx +++ b/webapp/packages/core-blocks/src/FormControls/Checkboxes/Switch.tsx @@ -72,12 +72,12 @@ export const Switch: SwitchType = observer(function Switch({ } return ( - -
-
-
-
-
+ +
+
+
+
+
- + {children}
diff --git a/webapp/packages/core-blocks/src/FormControls/Combobox.tsx b/webapp/packages/core-blocks/src/FormControls/Combobox.tsx index da3dfedde8..6de6b05ef0 100644 --- a/webapp/packages/core-blocks/src/FormControls/Combobox.tsx +++ b/webapp/packages/core-blocks/src/FormControls/Combobox.tsx @@ -293,13 +293,7 @@ export const Combobox: ComboboxType = observer(function Combobox({ - + {!filteredItems.length ? ( {translate('combobox_no_results_placeholder')} @@ -322,11 +316,11 @@ export const Combobox: ComboboxType = observer(function Combobox({ onClick={event => handleSelect(event.currentTarget.id)} > {iconSelector && ( -
+
{icon && typeof icon === 'string' ? : icon}
)} -
{valueSelector(item)}
+
{valueSelector(item)}
); }) diff --git a/webapp/packages/core-blocks/src/FormControls/InputField.tsx b/webapp/packages/core-blocks/src/FormControls/InputField.tsx index d539a096b8..38c8ac28ee 100644 --- a/webapp/packages/core-blocks/src/FormControls/InputField.tsx +++ b/webapp/packages/core-blocks/src/FormControls/InputField.tsx @@ -192,11 +192,7 @@ export const InputField: InputFieldType = observer
)} - {icon && ( -
- {icon} -
- )} + {icon &&
{icon}
}
{(description || passwordType) && {description}} diff --git a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarBody.tsx b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarBody.tsx index f1e3b6e82d..f0143e9d0c 100644 --- a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarBody.tsx +++ b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarBody.tsx @@ -17,14 +17,12 @@ interface Props { export const SnackbarBody: React.FC> = function SnackbarBody({ title, className, children }) { const styles = useS(style); return ( -
-
-

+
+
+

{title}

-
- {children} -
+
{children}
); diff --git a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarContent.tsx b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarContent.tsx index 2fcfa97835..a03a41b53f 100644 --- a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarContent.tsx +++ b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarContent.tsx @@ -15,9 +15,5 @@ interface Props { export const SnackbarContent: React.FC> = function SnackbarContent({ children, className }) { const styles = useS(style); - return ( -
- {children} -
- ); + return
{children}
; }; diff --git a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarFooter.tsx b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarFooter.tsx index b21d7b9258..9e12c1aa2a 100644 --- a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarFooter.tsx +++ b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarFooter.tsx @@ -19,13 +19,9 @@ export const SnackbarFooter: React.FC> = function const timeStringFromTimestamp = new Date(timestamp).toLocaleTimeString(); return ( -
- - {timeStringFromTimestamp} - -
- {children} -
+
+ {timeStringFromTimestamp} +
{children}
); }; diff --git a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarStatus.tsx b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarStatus.tsx index 5a8280c6d2..7cf0d70937 100644 --- a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarStatus.tsx +++ b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarStatus.tsx @@ -21,7 +21,7 @@ interface SnackbarStatusProps { export const SnackbarStatus: React.FC = function SnackbarStatus({ status, className }) { const styles = useS(style); return status === ENotificationType.Loading ? ( -
+
) : ( diff --git a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarWrapper.tsx b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarWrapper.tsx index 9ec5395fd7..55a5ec3e22 100644 --- a/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarWrapper.tsx +++ b/webapp/packages/core-blocks/src/Snackbars/SnackbarMarkups/SnackbarWrapper.tsx @@ -34,7 +34,7 @@ export const SnackbarWrapper: React.FC> = functio }, []); return ( -
+
{children} {!persistent && onClose && ( diff --git a/webapp/packages/core-cli/configs/babel.config.js b/webapp/packages/core-cli/configs/babel.config.js index e62889387d..6643caab6f 100644 --- a/webapp/packages/core-cli/configs/babel.config.js +++ b/webapp/packages/core-cli/configs/babel.config.js @@ -5,8 +5,6 @@ * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. */ -/* eslint-disable @typescript-eslint/no-var-requires */ -const testingAttributes = require('../dist/babel-plugins/TestingAttributes.js'); module.exports = api => { const devMode = !api.env('production'); @@ -28,6 +26,6 @@ module.exports = api => { }, ], ], - plugins: [[testingAttributes, {}], [require('@reshadow/babel'), {}], devMode && require.resolve('react-refresh/babel')].filter(Boolean), + plugins: [[require('@reshadow/babel'), {}], devMode && require.resolve('react-refresh/babel')].filter(Boolean), }; }; diff --git a/webapp/packages/core-cli/package.json b/webapp/packages/core-cli/package.json index d162469a1c..af5cf68f37 100644 --- a/webapp/packages/core-cli/package.json +++ b/webapp/packages/core-cli/package.json @@ -21,9 +21,6 @@ "core-cli-validate-dependencies": "./bin/validate-dependencies.js", "typescript-resolve-references": "./bin/typescript-resolve-references.js" }, - "scripts": { - "install": "tsc" - }, "engines": { "node": ">=16.0.0" }, diff --git a/webapp/packages/core-cli/src/babel-plugins/TestingAttributes.ts b/webapp/packages/core-cli/src/babel-plugins/TestingAttributes.ts deleted file mode 100644 index d5a814d96e..0000000000 --- a/webapp/packages/core-cli/src/babel-plugins/TestingAttributes.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2023 DBeaver Corp and others - * - * Licensed under the Apache License, Version 2.0. - * you may not use this file except in compliance with the License. - */ - -/** - * Based on https://github.com/akameco/babel-plugin-react-data-testid - */ -import type { NodePath, PluginObj, Visitor } from '@babel/core'; -import syntaxJsx from '@babel/plugin-syntax-jsx'; -import * as t from '@babel/types'; - -type FunctionType = t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression; - -function addTestIdAttribute(node: t.JSXOpeningElement, name: string): void { - if ( - t.isJSXIdentifier(node.name) && - node.name.name !== 'Fragment' && - node.name.name !== '_Fragment' && - !hasDataAttribute(node, DEFAULT_DATA_TESTID) - ) { - const dataAttribute = createDataAttribute(name, DEFAULT_DATA_TESTID); - const indexOf = node.attributes.findIndex(attribute => t.isJSXSpreadAttribute(attribute)); - if (indexOf !== -1) { - node.attributes.splice(indexOf, 0, dataAttribute); - } else { - node.attributes.push(dataAttribute); - } - } -} - -function nameForReactComponent(path: NodePath): t.Identifier | null { - const { parentPath } = path; - if (!t.isArrowFunctionExpression(path.node) && t.isIdentifier(path.node.id)) { - return path.node.id; - } - if (t.isVariableDeclarator(parentPath.node)) { - // @ts-expect-error expected - return parentPath.node.id; - } - return null; -} - -const DEFAULT_DATA_TESTID = 'data-testid'; - -function createDataAttribute(name: string, attributeName: string) { - return t.jsxAttribute(t.jsxIdentifier(attributeName), t.stringLiteral(name)); -} - -function hasDataAttribute(node: t.JSXOpeningElement, attributeName: string): boolean { - return node.attributes.some(attribute => t.isJSXAttribute(attribute) && t.isJSXIdentifier(attribute.name, { name: attributeName })); -} - -type VisitorState = { name: string }; - -const returnStatementVisitor: Visitor = { - JSXFragment(path) { - path.skip(); - }, - JSXElement(path, { name }) { - const openingElement = path.get('openingElement'); - - path.skip(); - - addTestIdAttribute(openingElement.node, name); - }, -}; - -const functionVisitor: Visitor = { - ReturnStatement(path, state) { - const arg = path.get('argument'); - if (!arg.isIdentifier()) { - path.traverse(returnStatementVisitor, state); - } - }, -}; - -function getElementName(node: t.JSXOpeningElement['name']): string { - if (t.isJSXNamespacedName(node)) { - return [getElementName(node.namespace), getElementName(node.name)].join(':'); - } - - if (t.isJSXIdentifier(node)) { - return node.name; - } - - return [getElementName(node.object), getElementName(node.property)].join('.'); -} - -export default function plugin(): PluginObj { - return { - name: 'cloudbeaver-data-testid', - inherits: syntaxJsx, - visitor: { - 'FunctionExpression|ArrowFunctionExpression|FunctionDeclaration': (p: NodePath) => { - const identifier = nameForReactComponent(p); - if (!identifier) { - return; - } - - if (p.isArrowFunctionExpression()) { - p.traverse(returnStatementVisitor, { name: identifier.name }); - } else { - p.traverse(functionVisitor, { name: identifier.name }); - } - }, - CallExpression(p) { - p.traverse({ - JSXOpeningElement({ node }) { - if (t.isJSXOpeningFragment(node)) { - return; - } - addTestIdAttribute(node, getElementName(node.name)); - }, - }); - }, - }, - } as PluginObj; -} diff --git a/webapp/packages/core-cli/tsconfig.eslint.json b/webapp/packages/core-cli/tsconfig.eslint.json deleted file mode 100644 index 8fdecd8c25..0000000000 --- a/webapp/packages/core-cli/tsconfig.eslint.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": [ - "src", - "tests", - "bin", - "configs" - ], - "exclude": ["**/node_modules", "**/lib"] -} \ No newline at end of file diff --git a/webapp/packages/core-cli/tsconfig.json b/webapp/packages/core-cli/tsconfig.json deleted file mode 100644 index 008f4e3574..0000000000 --- a/webapp/packages/core-cli/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "rootDir": "src", - "module": "CommonJS", - "outDir": "dist", - "moduleResolution": "node", - "esModuleInterop": true, - "emitDeclarationOnly": false, - "skipLibCheck": true - }, - "include": ["src/**/*"], - "exclude": ["node_modules/**/*", "dist/**/*", "tests/**/*"] -} diff --git a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/NavTreeLimitFilter/elementsTreeLimitRenderer.tsx b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/NavTreeLimitFilter/elementsTreeLimitRenderer.tsx index 68742c71cc..373403a62f 100644 --- a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/NavTreeLimitFilter/elementsTreeLimitRenderer.tsx +++ b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/NavTreeLimitFilter/elementsTreeLimitRenderer.tsx @@ -38,7 +38,7 @@ const NavTreeLimitMessage: NavigationNodeRendererComponent = observer(function N } return ( -
+
{translate('ui_load_more')}