Respect _labels=on even if first row has a null, closes #5

This commit is contained in:
Simon Willison 2018-06-27 08:17:42 -07:00
commit 64205f3333

View file

@ -72,9 +72,14 @@ class DatasetteVega extends Component {
fetch(url).then(r => r.json()).then(data => {
if (data.length > 1) {
// Set columns to first item's keys
const columns = Object.keys(data[0]).map(
key => (data[0][key] && data[0][key].label) ? `${key}.label` : key
);
const columns = Object.keys(data[0]).map(key => {
// Do ANY of these rows have a .label property?
if (data.filter(d => (d[key] || '').label !== undefined).length) {
return `${key}.label`;
} else {
return key;
}
});
this.setState({
columns: columns,
x_column: columns[0],