Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed May 19, 2020
1 parent 38a74f0 commit 356e473
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
19 changes: 11 additions & 8 deletions x-pack/plugins/pipeline_builder/public/nodes/calculated_column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const definition: NodeDefinition<CalculatedColumnState> = {
const value = inputs[inputNodeIds[0]]?.value;

const { outputColumnId, selectedFormula, formulaState } = node.state;
if (!outputColumnId || !selectedFormula || !formulaState) {
if (!outputColumnId || !selectedFormula || !formulaState || !value) {
return value;
}

Expand Down Expand Up @@ -149,18 +149,18 @@ const calculations: Record<
const groupTotals: Record<string, number> = {};

table.rows.forEach(row => {
if (groupTotals[row[formulaState.otherColumn]]) {
groupTotals[row[formulaState.otherColumn]] += row[state.formulaState.column];
if (groupTotals[row[state.formulaState.otherColumn]]) {
groupTotals[row[state.formulaState.otherColumn]] += row[state.formulaState.column];
} else {
groupTotals[row[formulaState.otherColumn]] = row[state.formulaState.column];
groupTotals[row[state.formulaState.otherColumn]] = row[state.formulaState.column];
}
});
return {
columns: table.columns.concat([{ id: state.outputColumnId, dataType: 'number' }]),
rows: table.rows.map(r => ({
...r,
[state.outputColumnId]:
r[state.formulaState.column] / groupTotals[row[formulaState.otherColumn]],
r[state.formulaState.column] / groupTotals[r[state.formulaState.otherColumn]],
})),
};
}
Expand All @@ -169,14 +169,17 @@ const calculations: Record<
columns: table.columns.concat([{ id: state.outputColumnId, dataType: 'number' }]),
rows: table.rows.map(r => ({
...r,
[state.outputColumnId]: r[state.formulaState.column] / row[formulaState.otherColumn],
[state.outputColumnId]: r[state.formulaState.column] / r[state.formulaState.otherColumn],
})),
};
}

return table;
},
renderEditor: (node, table, dispatch) => {
if (!table) {
return <>No columns available from table</>;
}
return (
<>
<EuiFormRow label="Column">
Expand Down Expand Up @@ -226,8 +229,8 @@ const calculations: Record<
<EuiFormRow label="Group by column">
<EuiSelect
options={[{ text: 'No column', value: '' }].concat(
table.columns
.filter(c => c.id !== node.state.formulaState.column)
table?.columns
.filter(c => c.id !== node.state.formulaState?.column)
.map(c => ({ text: c.label || c.id, value: c.id }))
)}
value={node.state.formulaState?.otherColumn ?? ''}
Expand Down
17 changes: 12 additions & 5 deletions x-pack/plugins/pipeline_builder/public/nodes/search_node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,19 @@ export const definition: NodeDefinition<SearchNodeState> = {
async run(node, inputs, inputNodeIds, deps) {
const { state } = node;
const fn = deps.http.post;
const result = await fn('/api/console/proxy', {
query: { path: state.path, method: state.method },
body: state.body,
});
try {
const result = await fn('/api/console/proxy', {
query: { path: state.path, method: state.method },
body: state.body,
});

return result;
return result;
} catch (e) {
throw new Error(`${e.body.error.reason}
On line ${e.body.error.line}:
${state.body.split('\n')[e.body.error.line - 1]}`);
}
},
};

Expand Down

0 comments on commit 356e473

Please sign in to comment.