Skip to content

chore(table): break out code into helper modules and add additional tests #2805

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

Merged
merged 300 commits into from
Mar 12, 2019

Conversation

tmorehouse
Copy link
Member

@tmorehouse tmorehouse commented Mar 9, 2019

Description of Pull Request:

Breaking out helper functions into modules to make <b-table> a bit easier to maintain, and test individual helper functionality.

Also always adds ARIA roles to all elements rendered (not just in stacked mode), in case user overrides CSS semantics (i.e. via display: grid).

TO DO (in a future PR):

  • Test stacked layout
  • Test basic styling classes
  • Test responsive layout
  • Test filtering (including filter functions)
  • Migrate filtering into mixin
  • Migrate pagination into mixin
  • Migrate items into mixn

PR checklist:

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Enhancement to an existing feature
  • ARIA accessibility
  • Documentation update
  • Other, please describe: code organization

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact:

The PR fulfills these requirements:

  • It's submitted to the dev branch, not the master branch
  • When resolving a specific issue, it's referenced in the PR's title (i.e.
    fixes #xxxx[,#xxxx], where "xxxx" is the issue number)
  • The PR should address only one issue or feature. If adding multiple features or fixing a bug
    and adding a new feature, break them into separate PRs if at all possible.
  • PR titles should following the
    Conventional Commits naming convention (i.e.
    "fix(alert): not alerting during SSR render", "docs(badge): Updated pill examples, fix typos",
    "chore: fix typo in docs", etc). This is very important, as the CHANGELOG is generated
    from these messages.

If new features/enhancement/fixes are added or changed:

  • Includes documentation updates (including updating the component's package.json for slot and
    event changes)
  • New/updated tests are included and passing (if required)
  • Existing test suites are passing
  • The changes have not impacted the functionality of other components or directives
  • ARIA Accessibility has been taken into consideration (does it affect screen reader users or
    keyboard only users? clickable items should be in the tab index, etc)

If adding a new feature, or changing the functionality of an existing feature, the PR's
description above includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a
    suggestion issue first and wait for approval before working on it)

@codecov
Copy link

codecov bot commented Mar 9, 2019

Codecov Report

Merging #2805 into dev will increase coverage by 4.06%.
The diff coverage is 97.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #2805      +/-   ##
==========================================
+ Coverage   76.93%   80.99%   +4.06%     
==========================================
  Files         174      194      +20     
  Lines        3173     3199      +26     
  Branches      939      941       +2     
==========================================
+ Hits         2441     2591     +150     
+ Misses        532      441      -91     
+ Partials      200      167      -33
Impacted Files Coverage Δ
tests/utils.js 100% <ø> (+16.41%) ⬆️
src/mixins/id.js 100% <ø> (ø) ⬆️
...omponents/table/helpers/stringify-object-values.js 100% <100%> (ø)
src/components/table/helpers/mixin-caption.js 100% <100%> (ø)
src/components/table/helpers/mixin-empty.js 100% <100%> (ø)
.../components/table/helpers/text-selection-active.js 100% <100%> (ø)
src/components/table/helpers/mixin-colgroup.js 100% <100%> (ø)
src/components/table/helpers/mixin-provider.js 100% <100%> (ø)
src/components/table/helpers/mixin-selectable.js 100% <100%> (ø)
...omponents/table/helpers/stringify-record-values.js 100% <100%> (ø)
... and 36 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 172d876...9c46ff9. Read the comment docs.

@tmorehouse tmorehouse merged commit 0af78df into dev Mar 12, 2019
@tmorehouse tmorehouse deleted the tmorehouse/table-code branch March 12, 2019 06:56
@lianee
Copy link
Contributor

lianee commented Mar 18, 2019

commenting user-select: none; in _table.scss breaks selectable feature (especially range mode), and since it only applies to tables in selectable state, it shouldn't cause issue with the newly added #2801

@tmorehouse
Copy link
Member Author

Hmmm... but user select disables the ability to select text. Maybe this class should only be applied if there is at least one row selected first? and removed when no rows are selected?

@lianee
Copy link
Contributor

lianee commented Mar 18, 2019

Yes, it is the desired behavior of user-select.
I'm not sure of the usability of text selecting, when a table is in selectable state. This state makes the table an active UI object, like a button or a link, something probably not suitable for text selection.
Anyway, while it doesn't matter for single or multi modes, the lack of it in range mode disables shift-click because the recent 'text selected' abort of row-clicked, then making it impossible to do a shift-click range selection.
If you prefer to disable user-select only for range mode, then perhaps we could add a selector indicating the select-mode, so we could use a more specific CSS selector.

@tmorehouse
Copy link
Member Author

@lianee maybe a new class should be added to b-table table element, only when at least one row has been selected (i.e. b-table-selecting') which applies the user-select: none; (or a dynamic style added to all TRs)

 computed: {
    isSelecting() {
      return this.selectable &&
        this.selectMode === 'range' &&
        this.selectedRows &&
        this.selectedRows.some(v => v)
    }
 }

And if this.isSelecting returns true, then the class b-table-selecting is added to the table element.

@lianee
Copy link
Contributor

lianee commented Mar 18, 2019

I guess the 2 classes (selecting and mode) should be added, making it more versatile, then users could override the default behavior just with CSS.

@tmorehouse
Copy link
Member Author

@lianee check out PR #2865

@lianee
Copy link
Contributor

lianee commented Mar 18, 2019

@tmorehouse You were too fast for me ;)
I would have decoupled the two things with a b-table-selecting and a b-table-select-{mode} classes, but I'm ok with your solution, thank you.

@tmorehouse
Copy link
Member Author

We could stilldo so.ethjng similar forthe other two modes (adding classes when section is active).. just no user-select none.

And maybe add classes to say which mode is in use.

@lianee
Copy link
Contributor

lianee commented Mar 18, 2019

I don't know how to suggest changes to your PR, but what I was thinking is:
table.js:

'b-table-selecting': this.isSelecting,
[`b-table-select-${this.selectMode}`]: true

mixin-selectable.js:

    isSelecting() {
      return (
        this.selectable &&
        this.selectedRows &&
        this.selectedRows.some(Boolean)
      )
    }

_table.scss:

  &.b-table-selecting.b-table-select-range {
    > tbody > tr {
      user-select: none;
    }
  }

leaving the user the choice to apply user-select in any mode he wants, whether or not there is a selection in process.

But as I said, your solution works ok, range mode is now working as it should.

@tmorehouse
Copy link
Member Author

tmorehouse commented Mar 18, 2019

Could you put this as a comment on the new PR?

I can add it in later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants