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

AccordionTable columns broken if Data has numeric keys #236

Open
5 tasks done
Saladinek opened this issue Jan 29, 2020 · 2 comments
Open
5 tasks done

AccordionTable columns broken if Data has numeric keys #236

Saladinek opened this issue Jan 29, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@Saladinek
Copy link
Contributor

Bug Report

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version?
  • Did you check the FAQs to see if that helps you?
  • Are you reporting to the correct repository?
  • Did you perform a search in the issues?

For more information, see the CONTRIBUTING guide.

Versions

Precise-UI 1.0.0

Description

If data is passed to AccordionTable component and contains a key which can be interpreted as numeric value, the UI and logic breaks.

Steps to Reproduce

  1. Go to KitchenSink
  2. Use Following code:
const { AccordionTable } = require('precise-ui');
const style = { width: '200px', margin: '0 auto', textAlign: 'center' };
​
function getContent({index, data}) {
  return (
    <div style={style}>
      Details for row #
      <b>{index}</b>
    </div>
  );
}
​
function cellRenderer({key, value}) {
    console.log('Key', key);
    console.log('Value', value)
  return key === 'tag' ? <Tag>{value}</Tag> : value;
}
​
<AccordionTable
  indexed
  data={[
    {tag: 'A', value: 'Alpha', team: 'Alpha team', 1451: 'Random Value'},
    {tag: 'B', value: 'Bravo', team: 'Bravo team', 1451: 'Random Value'},
    {tag: 'C', value: 'Charlie', team: 'Charlie team', 1451: 'Random Value'},
    {tag: 'E', value: 'Echo', team: 'Echo team', 1451: 'Random Value'},
  ]}
  cellRenderer={cellRenderer}
  detailsRenderer={getContent} />
  1. Open Console
  2. Render AccordionTable

Expected behavior: Table has a column 1451 with value 'Random Value' on every row + cellRenderer returns proper key and value pair

Actual behavior: Column is added at the beginning of table + cellRenderer returns incorrect key and value pair

Environment details: Chrome, Win10

@herrkris
Copy link
Member

herrkris commented Feb 4, 2020

Hey @Saladinek, thank you for reporting this issue! Unfortunately this is impossible to fix with the current way Precise-UI handles the data property. The reason for that is, that the order for enumerating an object never really was defined, until ES 6. Every JavaScript method that enumerates an object obeys to the following rules in which order the keys are enumerated:

  1. Integer indicies in asc order
  2. String values in the order they were added
  3. Symbols in the order they were added

This means for your case that 1451 always comes first, except if you turn it into a string and prefix it with a 0 so it looks like this: '01451'. Then the order will stay the same.

@herrkris
Copy link
Member

herrkris commented Feb 4, 2020

More on ES6 traversal order of JavaScript objects: https://2ality.com/2015/10/property-traversal-order-es6.html

@FlorianRappl FlorianRappl added the bug Something isn't working label Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants