table icon indicating copy to clipboard operation
table copied to clipboard

Square brackets in strings used as an accessor prevent data from showing

Open Omortis opened this issue 8 years ago • 4 comments

What version of React-Table are you using?

[email protected]

What bug are you experiencing, or what feature are you proposing?

Any strings I use as an accessor that contain square brackets [] do not actually display in the react-table component. Many of our signal names represent vectors in hardware and are of the form:

EV_DATA[14]_POWER_DSP EV_DATA[9]_MASTER_POWER_SW

None of these strings work as accessors, the table just shows up empty for that column. I am going to write some code to strip these brackets out of the returned data (for now) - is there a regex somewhere in react-table that is tripping over these square brackets?

Use https://codesandbox.io/s/X6npLXPRW (by clicking the "Fork" button) to reproduce the issue.

https://rw3jqvrwn4.codesandbox.io/

I simply changed firstName to first[3]Name and it does not display the data in that column.

What are the steps to reproduce the issue?

Use a string of the form "SOMESTRING[14]_NAME" as an accessor with any data type.

Edit: having stripped out the [ and ] chars in the python backend all the data loads fine.

Omortis avatar Mar 20 '18 15:03 Omortis

Or you could just us a function-based accessor as shown in the doco. I don't use the string based nested accessor because the syntax is foreign. A function is much simpler.

gary-menzel avatar Mar 22 '18 23:03 gary-menzel

Not quite sure what you mean by "the syntax is foreign" but I will look into using a function-based accessor when I get back to that code this week.

Omortis avatar Mar 27 '18 13:03 Omortis

I had another look - I don't understand what you are trying to do. Why are you changing firstName to first[3]Name ? What are you expecting to achieve ? That syntax is not going to work in the example because first is not an array in the data and an array would still need a . after it to access any member (e.g. first[3].Name. So, even if the data were structured in that way, the accessor you provided still wouldn't work because of the missing ..

The data record would need to look something like this.....

{
   first: [
     { /* 0 element here */ },
     { /* 1 element here */ },
     { /* 2 element here */ },
     { // 3 element here
          First: 'some value'
     },
     { /* maybe more elements here */ },
   ]
   // more fields here
}

gary-menzel avatar Mar 27 '18 13:03 gary-menzel

I was trying to recreate the issue I hit (and succeeded). Many signal names I receive from hardware model analysis contain square brackets in the name and these square brackets break react-table somehow.

Yes, it does look like a raw array variable. I will look into the functional accessor. I was following the sample code for "String-based value accessors!" under the docs at https://github.com/react-tools/react-table#data as this was trivially easy to code. Maybe make a note in the docs that square brackets in string accessor names are specifically verboten?

Omortis avatar Mar 27 '18 14:03 Omortis