8000 Fix eslint cyclomatic complexity issues in `assets/js/googlesitekit/components-gm2/Button.js` · Issue #10357 · google/site-kit-wp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Fix eslint cyclomatic complexity issues in assets/js/googlesitekit/components-gm2/Button.js #10357
Open
@ankitrox

Description

@ankitrox

Feature Description

The current value for maximum cyclomatic complexity is 15. Currently in assets/js/googlesitekit/components-gm2/Button.js, this is overridden with

  /* eslint complexity: [ "error", 19 ] */

Fix the eslint cyclomatic complexity issues in this file such that we do not need to override this rule in file-level and above file-level eslint rule can be removed.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  1. ESLint complexity overrides in assets/js/googlesitekit/components-gm2/Button.js are removed.

  2. Simplify the Button component to lower its complexity such that it is no no longer flagged by eslint.

Implementation Brief

  • Create a directory Button inside assets/js/googlesitekit/components-gm2/

    • Create index.js file inside the directory where the main Button component will reside.

    • Create a component SemanticButton. It should return ButtonTag (either <a> or <button>) as in the current component.

      <SemanticButton
      className={ classnames( 'mdc-button', className, {
      'mdc-button--raised': ! text && ! tertiary && ! callout,
      'mdc-button--danger': danger,
      'mdc-button--inverse': inverse,
      'mdc-button--tertiary': tertiary,
      'mdc-button--callout': callout,
      'mdc-button--callout-primary':
      callout || calloutStyle === 'primary',
      'mdc-button--callout-warning': calloutStyle === 'warning',
      'mdc-button--callout-error': calloutStyle === 'error',
      } ) }
      href={ disabled ? undefined : href }
      ref={ mergedRefs }
      disabled={ !! disabled }
      aria-label={ getAriaLabel() }
      target={ target || '_self' }
      role={ 'a' === SemanticButton ? 'button' : undefined }
      { ...extraProps }
      >
      { icon }
      { children && (
      <span className="mdc-button__label">{ children }</span>
      ) }
      { trailingIcon }
      </SemanticButton>

    • Accept all necessary props in the SemanticButton component which are being used as shown in above snippet.

    • Create a component MaybeTooltip in assets/js/googlesitekit/components-gm2/Button/ to indicate its conditionality, like this MaybePlaceholderTile.

  • Update the main Button component inside assets/js/googlesitekit/components-gm2/Button/index.js

    • Import the above created components in Button and use them in the render method.
  • Move the stories file for the Button component to the new Button folder.

  • Remove the old Button component and update the imports across code.

Test Coverage

  1. Write tests for new components.
  2. Fix any failing tests.

QA Brief

  • Ensure that Button stories are rendering properly.
  • A quick smoke test around the components which uses Button.

Changelog entry

Metadata

Metadata

Assignees

Labels

P2Low priorityQA: EngRequires specialized QA by an engineerTeam MIssues for Squad 2Type: EnhancementImprovement of an existing feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0