Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
refactor(address code review comments): address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Conglei Shi committed Aug 13, 2019
1 parent ebc0774 commit 338d2cd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 33 deletions.
1 change: 1 addition & 0 deletions packages/superset-ui-plugin-chart-table/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class TableVis extends React.PureComponent<InternalTableProps, TableState> {
)}
<DataTable
data={dataToRender}
keys={dataToRender && dataToRender.length > 0 ? Object.keys(dataToRender[0].data) : []}
columnMetadata={columnMetadata}
zebra
rowHeight={heightType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function processColumns({

// Handle verbose names for percents
if (!label) {
if (key[0] === '%') {
if (key.length > 0 && key[0] === '%') {
const cleanedKey = key.substring(1);
label = `% ${verboseMap[cleanedKey] || cleanedKey}`;
formatFunction = formatPercent;
Expand Down
40 changes: 16 additions & 24 deletions packages/superset-ui-plugin-chart-table/src/processData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,24 @@ export default function processData({
timeseriesLimitMetric &&
((timeseriesLimitMetric as AdhocMetric).label || (timeseriesLimitMetric as string));

let processedData: {
data: PlainObject;
}[] = records.map((row: PlainObject) => ({
data: row,
}));
let processedRecords = records;

if (sortByKey) {
processedData = processedData.sort((a, b) => {
const delta = a.data[sortByKey] - b.data[sortByKey];
if (orderDesc) {
return -delta;
}

return delta;
});
if (metrics.indexOf(sortByKey) < 0) {
processedData = processedData.map(row => {
const data = { ...row.data };
delete data[sortByKey];

return {
data,
};
});
}
processedRecords = records
.slice()
.sort(
orderDesc ? (a, b) => b[sortByKey] - a[sortByKey] : (a, b) => a[sortByKey] - b[sortByKey],
);
}

return processedData;
return processedRecords.map(
sortByKey && metrics.indexOf(sortByKey) < 0
? row => {
const data = { ...row };
delete data[sortByKey];

return { data };
}
: row => ({ data: row }),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default function processMetrics({

return processedMetrics
.concat(processedPercentMetrics)
.filter(m => typeof records[0][m as string] === 'number');
.filter(m => typeof records[0][m] === 'number');
}
12 changes: 6 additions & 6 deletions packages/superset-ui-plugin-chart-table/src/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export type Cell = {
value: any;
};

const numberStyle: CSSProperties = {
marginLeft: 'auto',
marginRight: '4px',
zIndex: 10,
};

export const getRenderer = ({
column,
alignPositiveNegative,
Expand Down Expand Up @@ -83,12 +89,6 @@ export const getRenderer = ({
width: `${width}%`,
};

const numberStyle: CSSProperties = {
marginLeft: 'auto',
marginRight: '4px',
zIndex: 10,
};

return (
<div style={boxStyle}>
<div style={boxContainerStyle}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default [
alignPn: false,
colorPn: true,
includeSearch: true,
metrics: ['sum__num', 'trend'],
metrics: ['sum__num'],
orderDesc: true,
pageLength: 0,
percentMetrics: [],
Expand Down

0 comments on commit 338d2cd

Please sign in to comment.