Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Gray out null (N/A) values
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Jan 14, 2021
1 parent f44549f commit 244eeed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions plugins/plugin-chart-table/src/Styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export default styled.div`
.dt-metric {
text-align: right;
}
.dt-is-null {
color: ${({ theme: { colors } }) => colors.grayscale.light1};
}
td.dt-is-filter {
cursor: pointer;
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/plugin-chart-table/src/TableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
// so we ask TS not to check.
accessor: ((datum: D) => datum[key]) as never,
Cell: ({ value }: { column: ColumnInstance<D>; value: DataRecordValue }) => {
const [isHtml, text] = formatValue(column, value);
const [isHtml, text, customClassName] = formatValue(column, value);
const style = {
background: valueRange
? cellBar({
Expand All @@ -236,7 +236,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
// show raw number in title in case of numeric values
title: typeof value === 'number' ? String(value) : undefined,
onClick: emitFilter && !valueRange ? () => toggleFilter(key, value) : undefined,
className: `${className}${
className: `${className} ${customClassName || ''} ${
isActiveFilterValue(key, value) ? ' dt-is-active-filter' : ''
}`,
style,
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-chart-table/src/buildQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function buildQuery(formData: TableChartFormData) {
operation: 'contribution',
options: {
columns: percentMetricLabels,
rename_columns: percentMetricLabels.map(x => `% ${x}`),
rename_columns: percentMetricLabels.map(x => `%${x}`),
},
},
];
Expand Down
12 changes: 6 additions & 6 deletions plugins/plugin-chart-table/src/utils/formatValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ function isProbablyHTML(text: string) {
return /<[^>]+>/.test(text);
}
/**
* Format text for cell value
* Format text for cell value.
*/
export default function formatValue(
{ formatter }: DataColumnMeta,
value: DataRecordValue,
): [boolean, string] {
): [boolean, string, string | null] {
if (value === null) {
return [false, 'N/A'];
return [false, 'N/A', 'dt-is-null'];
}
if (formatter) {
// in case percent metric can specify percent format in the future
return [false, formatter(value as number)];
return [false, formatter(value as number), null];
}
if (typeof value === 'string') {
return isProbablyHTML(value) ? [true, xss.process(value)] : [false, value];
return isProbablyHTML(value) ? [true, xss.process(value), null] : [false, value, null];
}
return [false, value.toString()];
return [false, value.toString(), null];
}

0 comments on commit 244eeed

Please sign in to comment.