Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove link-button properties and create separate classes #2364

Merged

Conversation

DavideMininni-Fincons
Copy link
Contributor

@DavideMininni-Fincons DavideMininni-Fincons commented Jan 23, 2024

Preflight Checklist

Issue

This PR Closes #2212

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

See Review Guidelines for more information what is checked during review process.

Changes

Changes in this pull request:

  • A new class named SbbActionBaseElement has been created. This is used as a base class for all the button/link related components; in particular, the renderTemplate method must be implemented by all the derived classes, returning the inner template to render.

  • Two other base class have been created, named SbbButtonBaseElement and SbbLinkBaseElement, which both extends the SbbActionBaseElement class, and respectively implement the ButtonProperties and the LinkProperties interfaces. These two classes contains all the logic (attributes, interaction, render) related to the natives button and link re-implementation.

  • Four new mixins have been created, which permits adding the negative, disabled and icon behaviors to any custom component, plus a disabled mixin customized for action elements which also handles the tabindex and aria-disabled attribute's setting. The mixins have been used to replace the properties functionality wherever possible:

    // old code
    export class SbbAutocompleteElement extends SlotChildObserver(LitElement) {
       ...
       /** Negative coloring variant flag. */
       @property({ reflect: true, type: Boolean }) public negative = false;
       ...
    }
    
    // new code
    export class SbbAutocompleteElement extends SlotChildObserver(SbbNegativeMixin(LitElement)) {
       ...
    }
  • Each of the following component, which previously implemented the LinkButtonInterface, has been split in two separate components; the first one extends the SbbButtonBaseElement, the second one extends the SbbLinkBaseElement. The extension has been done by creating another mixin, generally named <Component>CommonElementMixin, which contains the shared logic (additional properties, styles, (dis)connectedCallback() and so on).

    // old code
    @customElement('sbb-header-action')
    export class SbbHeaderActionElement extends LitElement implements LinkButtonProperties {
      ...
    }
    
    // new code
    @customElement('sbb-header-button')
    export class SbbHeaderButtonElement extends SbbHeaderActionCommonElementMixin(SbbButtonBaseElement) {}
    
    @customElement('sbb-header-link')
    export class SbbHeaderLinkElement extends SbbHeaderActionCommonElementMixin(SbbLinkBaseElement) {}

    Affected components are:

    • sbb-button: split in sbb-button and sbb-button-link;
    • sbb-card-action: split in sbb-card-button and sbb-card-link;
    • sbb-link: split in sbb-link-button and sbb-link;
    • sbb-menu-action: split in sbb-menu-button and sbb-menu-link;
    • sbb-navigation-action: split in sbb-navigation-button and sbb-navigation-link.
  • The isStatic interface has been removed from codebase; for the button and the link, two new other components, named sbb-button-static and sbb-link-static, have been created to replace the button/link's isStatic functionality. The check for nested buttons / links has been removed too, so now consumers must check these cases, and possibly fix them using the two new static variants.

  • The static functionality is no longer available also in sbb-breadcrumb, sbb-teaser, sbb-teaser-hero.

  • Apart from the link-button case, these components have been extended from base class:

    • sbb-breadcrumb now extends SbbLinkBaseElement;
    • sbb-datepicker-next-day now extends SbbButtonBaseElement;
    • sbb-datepicker-previous-day now extends SbbButtonBaseElement;
    • sbb-expansion-panel-header now extends SbbButtonBaseElement;
    • sbb-form-field-clear now extends SbbButtonBaseElement;
    • sbb-tag now extends SbbButtonBaseElement;
    • sbb-teaser-hero now extends SbbLinkBaseElement;
    • sbb-teaser now extends SbbLinkBaseElement;
    • sbb-tooltip-trigger now extends SbbButtonBaseElement;

Browsers

I tested the build on the following browsers:

  • Firefox Desktop
  • Chrome Desktop
  • Edge Desktop
  • Safari Desktop
  • Chrome Mobile
  • Safari Mobile

Screen readers

I tested the build on the following browsers:

  • JAWS Firefox Desktop
  • JAWS Chrome Desktop
  • NVDA Firefox Desktop
  • NVDA Chrome Desktop
  • VoiceOver Safari Desktop
  • VoiceOver Chrome Desktop
  • VoiceOver Safari Mobile
  • Android Accessibility Suite Chrome Mobile

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Does this introduce a breaking change?

  • Yes
  • No

BREAKING CHANGES:
All of these components has been split in two, one with only-button and one with only-link behavior.

  • sbb-card-action: split in sbb-card-button and sbb-card-link;
  • sbb-menu-action: split in sbb-menu-button and sbb-menu-link;
  • sbb-navigation-action: split in sbb-navigation-button and sbb-navigation-link.

These components has been split in three, one with only-button and one with only-link behavior, plus a static variant.

  • sbb-button: split in sbb-button, sbb-button-link and sbb-button-static;
  • sbb-link: split in sbb-link, sbb-link-button and sbb-link-static.

Check your code and change accordingly, eg.

  • sbb-button with href set => change to sbb-button-link;
  • sbb-menu-action with name and form set => change to sbb-menu-button;
  • sbb-link with href set => no changes;
  • sbb-navigation-action with value set => change to sbb-navigation-button;
  • sbb-button with isStatic set to true => change to sbb-button-static;
  • sbb-link used within an anchor tag => change to sbb-link-static;
  • ...

Other information

@DavideMininni-Fincons
Copy link
Contributor Author

Hello @kyubisation
as mentioned some dailies ago, there's a problem with the react build.

I receive this error (on navigation, but time by time also on menu, card, etc):

Could not resolve "./navigation-action" from "src/react/navigation/index.ts"
file: /Users/davide.mininni/workspace/workspace_lyne/lyne-components/src/react/navigation/index.ts
error during build:
RollupError: Could not resolve "./navigation-action" from "src/react/navigation/index.ts"
    at error (file:///Users/davide.mininni/workspace/workspace_lyne/lyne-components/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
    at ModuleLoader.handleInvalidResolvedId (file:///Users/davide.mininni/workspace/workspace_lyne/lyne-components/node_modules/rollup/dist/es/shared/node-entry.js:18022:24)
    at file:///Users/davide.mininni/workspace/workspace_lyne/lyne-components/node_modules/rollup/dist/es/shared/node-entry.js:17982:26
error Command failed with exit code 1.

I added a new index.ts file in the -action folder, which exports both the newly created button and link component; then I import it in the main index.ts.
image

from my understanding of the src/react/vite.config.ts, I think this interfere with the dirInfo setting at line 110.
I tried to remove this new index, refactoring imports, but the error persists.
Any idea?

@kyubisation
Copy link
Contributor

I'll try to have a look.
Without having done a review; I think I would prefer the following structure for previous action elements:
e.g.

  • menu
    • common
    • menu-button
    • menu-link
    • menu

i.e. a flatter structure then nesting the action elements in menu/menu-action.

@jeripeierSBB @DavideMininni-Fincons What do you think?

@DavideMininni-Fincons
Copy link
Contributor Author

DavideMininni-Fincons commented Jan 24, 2024

I'll try to have a look. Without having done a review; I think I would prefer the following structure for previous action elements: e.g.

  • menu

    • common
    • menu-button
    • menu-link
    • menu

i.e. a flatter structure then nesting the action elements in menu/menu-action.

@jeripeierSBB @DavideMininni-Fincons What do you think?

I tried it and it solved the react build problem too, so even if i don't really like it due the position of the common folder, it's fine for me (I'm pushing the fix in a few moments).

edited: i forgot to write, but for sure there are still stuff to fix (eg, i created some new mixin but not sure about them, maybe can we merge common styles?, there are comments about migr hostAttributes, and so on), so any other addition/improvement is well accepted :)

@github-actions github-actions bot requested a deployment to preview-pr2364 January 24, 2024 17:11 In progress
@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@34d3dbb). Click here to learn what that means.

Files Patch % Lines
src/components/menu/menu/menu.ts 81.25% 6 Missing ⚠️
src/components/teaser-hero/teaser-hero.ts 92.59% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2364   +/-   ##
=======================================
  Coverage        ?   93.55%           
=======================================
  Files           ?      219           
  Lines           ?    22098           
  Branches        ?     2006           
=======================================
  Hits            ?    20674           
  Misses          ?     1389           
  Partials        ?       35           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot requested a deployment to preview-pr2364 January 24, 2024 17:40 In progress
@github-actions github-actions bot requested a deployment to preview-pr2364 January 25, 2024 09:56 In progress
@github-actions github-actions bot requested a deployment to preview-pr2364 January 25, 2024 10:16 In progress
@github-actions github-actions bot requested a deployment to preview-pr2364 January 25, 2024 10:52 In progress
@DavideMininni-Fincons
Copy link
Contributor Author

An example of how to use the new disabled and negative mixins has been done here:
https://github.com/lyne-design-system/lyne-components/compare/refactor/link-button-components-refactoring...refactor/link-button-components-refactoring-applying-mixins?expand=1

After the merge of this PR, a new PR from the 'refactor/link-button-components-refactoring-applying-mixins' branch can be created.

@DavideMininni-Fincons DavideMininni-Fincons force-pushed the refactor/link-button-components-refactoring branch from f41647d to c348e54 Compare January 29, 2024 09:08
@github-actions github-actions bot requested a deployment to preview-pr2364 January 29, 2024 09:17 In progress
Copy link
Contributor

@kyubisation kyubisation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work!

src/components/button/button-link/button-link.ts Outdated Show resolved Hide resolved
src/components/button/button-link/readme.md Outdated Show resolved Hide resolved
src/components/button/button/button.ts Outdated Show resolved Hide resolved
src/components/button/common/button-common.ts Outdated Show resolved Hide resolved
src/components/button/common/button-common.ts Outdated Show resolved Hide resolved
src/components/header/header-link/header-link.ts Outdated Show resolved Hide resolved
src/components/header/header/header.scss Outdated Show resolved Hide resolved
src/components/link/common/link-common.ts Outdated Show resolved Hide resolved
src/components/menu/menu-link/menu-link.ts Outdated Show resolved Hide resolved
@DavideMininni-Fincons DavideMininni-Fincons force-pushed the refactor/link-button-components-refactoring branch from c348e54 to 389e5d6 Compare January 30, 2024 09:36
@github-actions github-actions bot requested a deployment to preview-pr2364 January 30, 2024 09:47 In progress
src/components/button/button-link/button-link.ts Outdated Show resolved Hide resolved
src/components/button/button-link/button-link.ts Outdated Show resolved Hide resolved
src/components/button/button/button.ts Outdated Show resolved Hide resolved
src/components/button/button/button.stories.ts Outdated Show resolved Hide resolved
src/components/breadcrumb/breadcrumb/breadcrumb.ts Outdated Show resolved Hide resolved
src/components/card/card-link/card-link.ts Outdated Show resolved Hide resolved
src/components/card/card-link/card-link.ts Outdated Show resolved Hide resolved
src/components/core/common-behaviors/icon-name-mixin.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot requested a deployment to preview-pr2364 January 30, 2024 12:41 In progress
@github-actions github-actions bot temporarily deployed to preview-pr2364 January 30, 2024 14:56 Inactive
@github-actions github-actions bot temporarily deployed to preview-pr2364 January 30, 2024 16:53 Inactive
@github-actions github-actions bot temporarily deployed to preview-pr2364 January 30, 2024 17:11 Inactive
@DavideMininni-Fincons DavideMininni-Fincons force-pushed the refactor/link-button-components-refactoring branch from 9242911 to 0edc2f6 Compare January 31, 2024 18:03
@github-actions github-actions bot temporarily deployed to preview-pr2364 January 31, 2024 18:12 Inactive
@github-actions github-actions bot temporarily deployed to preview-pr2364 February 1, 2024 11:04 Inactive
@github-actions github-actions bot temporarily deployed to preview-pr2364 February 1, 2024 13:35 Inactive
@DavideMininni-Fincons DavideMininni-Fincons force-pushed the refactor/link-button-components-refactoring branch from dc807ac to f13ece2 Compare February 19, 2024 08:46
@DavideMininni-Fincons DavideMininni-Fincons merged commit 727f01c into main Feb 19, 2024
15 of 17 checks passed
@DavideMininni-Fincons DavideMininni-Fincons deleted the refactor/link-button-components-refactoring branch February 19, 2024 10:34
@github-actions github-actions bot added the pr: peer review required A peer review is required for this pull request label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: lead review approved Pull request has been approved by a lead review pr: peer review required A peer review is required for this pull request preview-available
Projects
None yet
4 participants