Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Jul 16, 2020
1 parent 8537c9c commit 850c8f7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/plugins/vis_type_vega/public/vega_inspector/vega_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ const serializeColumns = (item: Record<string, unknown>, columns: string[]) => {

return columns.reduce((row: Record<string, string>, column) => {
try {
row[column] = JSON.stringify(item[column]);
const cell = item[column];
row[column] = typeof cell === 'object' ? JSON.stringify(cell) : `${cell}`;
} catch (e) {
row[column] = nonSerializableFieldLabel;
}
return row;
}, {});
};

const mapColumns = (columns: string[]) => columns.map((column) => ({ id: column, schema: 'json' }));

export class VegaAdapter {
private debugValuesSubject = new ReplaySubject<DebugValues>();

Expand All @@ -86,7 +85,7 @@ export class VegaAdapter {
const columns = Object.keys(value[0]);
acc.push({
id: key,
columns: mapColumns(columns),
columns: columns.map((column) => ({ id: column, schema: 'json' })),
data: value.map((item: Record<string, unknown>) => serializeColumns(item, columns)),
});
}
Expand Down Expand Up @@ -120,17 +119,19 @@ export class VegaAdapter {
filter((debugValues) => Boolean(debugValues)),
map((debugValues) => {
const runtimeScope = getVegaRuntimeScope(debugValues);
const columns = [vegaAdapterSignalLabel, vegaAdapterValueLabel];

return {
columns: mapColumns(columns),
columns: [
{ id: vegaAdapterSignalLabel, schema: 'text' },
{ id: vegaAdapterValueLabel, schema: 'json' },
],
data: Object.keys(runtimeScope.signals).map((key: string) =>
serializeColumns(
{
[columns[0]]: key,
[columns[1]]: runtimeScope.signals[key].value,
[vegaAdapterSignalLabel]: key,
[vegaAdapterValueLabel]: runtimeScope.signals[key].value,
},
columns
[vegaAdapterSignalLabel, vegaAdapterValueLabel]
)
),
};
Expand Down

0 comments on commit 850c8f7

Please sign in to comment.