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

fix(BTable): Pass through original records to slots when primary key is defined #1869

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

dwgray
Copy link
Contributor

@dwgray dwgray commented Apr 28, 2024

Describe the PR

For use cases when row items are defined as functional objects, it's convenient for the original object to be passed through to the scoped slots. The object still has to not contain loops and correctly transform through the JSON.parse(JSON.stringify()) loop, but it is returned to the client code intact.

The requirements for this to work are:

  1. The table must contain a primary-key property
  2. The object keys must not contain "." - I don't believe this is an issue, because the use case for this kind of pass-through is well-behaved typescript objects, which should have property names containing "."

If this is acceptable, I'll get documentation including the limitations (and probably some stuff around it) in as a follow-up PR.

Small replication

Included in the test cases in the PR.

PR checklist

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

  • Bugfix 🐛 - fix(...)
  • Feature - feat(...)
  • ARIA accessibility - fix(...)
  • Documentation update - docs(...)
  • Other (please describe)

The PR fulfills these requirements:

  • Pull request title and all commits follow the Conventional Commits convention or has an override in this pull request body This is very important, as the CHANGELOG is generated from these messages, and determines the next version type. Pull requests that do not follow conventional commits or do not have an override will be denied

Copy link

stackblitz bot commented Apr 28, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

if (
typeof item === 'object' &&
item !== null &&
Object.keys(item).some((key) => key.includes('.'))
Copy link
Contributor Author

@dwgray dwgray Apr 28, 2024

Choose a reason for hiding this comment

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

This takes care of passing through the original objects to BTableLite except in the case where the a key contains "." - I believe this is an acceptable compromise as the use case for maintaining the object is well-behaved typescript objects, which shouldn't contain "." in property names. It also has the benefit of not transforming object arbitrarily if they're "normal" objects.

@@ -273,6 +273,26 @@ watch(
}
)

const itemMap = computed(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This depends on having a primary key defined. That's fine for my use case (and I think in general for the kind of case that I think would be important for enabling the pass through) - I don't see a more general way to do this, but if I'm missing something obvious, I'd be happy to take another un at it. I'll also document this capability and its limitations in a follow-up PR (and probably get some more of the surrounding table docs added).

@dwgray dwgray marked this pull request as ready for review April 29, 2024 18:25
@VividLemon VividLemon merged commit bd5541f into bootstrap-vue-next:main Apr 30, 2024
3 checks passed
@github-actions github-actions bot mentioned this pull request Apr 30, 2024
xvaara added a commit to xvaara/bootstrap-vue-next that referenced this pull request May 22, 2024
* upstream/main: (23 commits)
  feat(BInput): Alias BFormInput to BInput
  fix(nuxt): dont teleport everything to #teleports -- selectively teleport based on body fixes bootstrap-vue-next#1898
  chore: release main
  feat(nuxt): allow passthrough options to createBootstrap plugin
  chore: release main (bootstrap-vue-next#1894)
  feat: implmenet a use defaults system WIP fixes bootstrap-vue-next#1607  (bootstrap-vue-next#1889)
  docs(BCheckBox*): Small changes to get documentation to parity (bootstrap-vue-next#1873)
  docs: Add component reference link in the page table of contents sidebar
  fixed BTableLite item _showDetails
  BTable delete selection when primary-key
  chore: release main
  feat(BTable): add change event -- replaces bv `modelValue` see bootstrap-vue-next#1775 (comment)
  chore: release main
  fix(BTable): selectedItems not clearing values properly fixes bootstrap-vue-next#1878 (bootstrap-vue-next#1879)
  chore: release main (bootstrap-vue-next#1874)
  fix(BTable): Pass through original records to slots in most circumstances (bootstrap-vue-next#1869)
  chore: release main (bootstrap-vue-next#1867)
  feat(BTable): Allow dot in sortby key
  fix: update dependencies to fix a bug in vue compiler (bootstrap-vue-next#1866)
  chore: release main (bootstrap-vue-next#1859)
  ...
@dwgray dwgray deleted the table-items branch June 11, 2024 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants