Skip to content

Commit

Permalink
update as per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
meowcodes committed May 4, 2020
1 parent bf215b8 commit 29fa3a4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions datahub/webapp/components/AppAdmin/AppAdmin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
flex-grow: 1;
text-align: left;
overflow-y: hidden;
overflow-x: hidden;
.AdminForm-button-box {
display: flex;
justify-content: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ const DataDocChartComposerComponent: React.FunctionComponent<
values.xIndex,
]);

const tableData: any[][] = React.useMemo(() => {
if (tableTab === 'original') {
return statementResultData;
} else {
return chartData;
}
}, [tableTab, statementResultData, chartData]);

// getting redux state
const queryCellOptions = useSelector((state: IStoreState) => {
const cellList = state.dataDoc.dataDocById[dataDocId].cells;
Expand Down Expand Up @@ -782,7 +774,11 @@ const DataDocChartComposerComponent: React.FunctionComponent<
dataDOM = (
<div className="DataDocChartComposer-data">
<StatementResultTable
data={tableData}
data={
tableTab === 'original'
? statementResultData
: chartData
}
paginate={true}
maxNumberOfRowsToShow={5}
/>
Expand Down
28 changes: 21 additions & 7 deletions datahub/webapp/lib/chart/chart-data-transformation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cloneDeep, range } from 'lodash';
import { ChartDataAggType } from 'const/dataDocChart';
import { sortTable } from './chart-utils';
import { sortTable, getValueDataType } from './chart-utils';

const emptyCellValue = 'No Value';

Expand Down Expand Up @@ -228,17 +228,26 @@ function aggregateData(
return aggregatedData;
}

export function sortData(
export function sortTableWithDefaultIdx(
data: any[][],
idx: number,
ascending: boolean,
xIdx: number
) {
const sortIdx = idx ?? (isNaN(data[0][xIdx]) ? undefined : 0);
if (sortIdx != null) {
return sortTable(data, sortIdx, ascending);
if (idx != null) {
// if idx is provided then call sortTable as is
return sortTable(data, idx, ascending);
} else {
return data;
// if idx is not provided then default idx to the xIndex of the table
// only sort if the column type for that index is either 'date' 'datetime' or 'number'
if (
getValueDataType(data[0][xIdx]) === 'string' ||
getValueDataType(data[0][xIdx]) === null
) {
return data;
} else {
return sortTable(data, xIdx, ascending);
}
}
}

Expand Down Expand Up @@ -283,6 +292,11 @@ export function transformData(

return [
transformedData[0],
...sortData(transformedData.slice(1), sortIdx, sortAsc, xAxisIdx),
...sortTableWithDefaultIdx(
transformedData.slice(1),
sortIdx,
sortAsc,
xAxisIdx
),
];
}

0 comments on commit 29fa3a4

Please sign in to comment.