Skip to content

Commit

Permalink
#7804 handle date object in column name
Browse files Browse the repository at this point in the history
  • Loading branch information
piorek committed Sep 26, 2018
1 parent 16fc3cd commit e099bea
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion js/notebook/src/tableDisplay/dataGrid/model/selectors/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import * as moment from 'moment-timezone/builds/moment-timezone-with-data';
import {createSelector} from "reselect";
import {DataModel} from "@phosphor/datagrid";
import {
Expand All @@ -39,7 +40,36 @@ import IHihglighterState from "../../interface/IHighlighterState";

export const DEFAULT_INDEX_COLUMN_NAME = 'index';

export const selectColumnNames = createSelector(selectRawColumnNames, names => names.map(name => name !== null ? String(name) : null));

const processColumnName = (name) => {
if (name === null) {
return name;
}

if (!Array.isArray(name)) {
return String(name);
}

const isDate = (value) => {
return value instanceof Object &&
value.hasOwnProperty('type') &&
value.hasOwnProperty('timestamp') &&
value.type === "Date";
};

return name.reduce((prev, curr, index, arr) => {
let processed = isDate(curr) ?
moment(curr.timestamp).format('YYYY-MM-DD') :
String(curr);

return `${prev} ${processed}`;
}, '');
};

export const selectColumnNames = createSelector(
selectRawColumnNames,
names => names.map(processColumnName)
);

export const selectBodyColumnNames = createSelector(
[selectColumnNames, selectHasIndex],
Expand Down

0 comments on commit e099bea

Please sign in to comment.