-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release InsightsTableV2 * release graphs new UI
- Loading branch information
1 parent
3264539
commit 75d50e3
Showing
4 changed files
with
11 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,2 @@ | ||
import React from 'react' | ||
import { Table } from 'antd' | ||
import { useActions, useValues } from 'kea' | ||
import { IndexedTrendResult, trendsLogic } from 'scenes/trends/trendsLogic' | ||
import { PHCheckbox } from 'lib/components/PHCheckbox' | ||
import { getChartColors } from 'lib/colors' | ||
import { FEATURE_FLAGS, MATHS } from 'lib/constants' | ||
import { cohortsModel } from '~/models/cohortsModel' | ||
import { CohortType } from '~/types' | ||
import { ColumnsType } from 'antd/lib/table' | ||
import { maybeAddCommasToInteger } from 'lib/utils' | ||
import { featureFlagLogic } from 'lib/logic/featureFlagLogic' | ||
import { InsightsTableV2 } from './InsightsTableV2' | ||
|
||
export function InsightsTable(props: InsightsTableProps): JSX.Element { | ||
const { featureFlags } = useValues(featureFlagLogic) | ||
return featureFlags[FEATURE_FLAGS.NEW_TOOLTIPS] ? <InsightsTableV2 {...props} /> : <InsightsTableV1 {...props} /> | ||
} | ||
|
||
function formatLabel(item: IndexedTrendResult): string { | ||
const name = item.action?.name || item.label | ||
const math = item.action?.math | ||
const mathLabel = math ? MATHS[math].name : '' | ||
const propNum = item.action?.properties.length | ||
const propLabel = propNum ? propNum + (propNum === 1 ? ' property' : ' properties') : '' | ||
return name + (mathLabel ? ' — ' + mathLabel : '') + (propLabel ? ' — ' + propLabel : '') | ||
} | ||
|
||
function formatBreakdownLabel(breakdown_value: string | number | undefined, cohorts: CohortType[]): string { | ||
if (breakdown_value && typeof breakdown_value == 'number') { | ||
return cohorts.filter((c) => c.id == breakdown_value)[0]?.name || breakdown_value.toString() | ||
} else if (typeof breakdown_value == 'string') { | ||
return breakdown_value === 'nan' ? 'Other' : breakdown_value | ||
} else { | ||
return '' | ||
} | ||
} | ||
|
||
interface InsightsTableProps { | ||
isLegend?: boolean // `true` -> Used as a supporting legend at the bottom of another graph; `false` -> used as it's own display | ||
showTotalCount?: boolean | ||
} | ||
|
||
function InsightsTableV1({ isLegend = true, showTotalCount = false }: InsightsTableProps): JSX.Element | null { | ||
const { indexedResults, visibilityMap, filters } = useValues(trendsLogic) | ||
const { toggleVisibility } = useActions(trendsLogic) | ||
const { cohorts } = useValues(cohortsModel) | ||
const isSingleEntity = indexedResults.length === 1 | ||
|
||
if (indexedResults.length === 0 || !indexedResults?.[0]?.data) { | ||
return null | ||
} | ||
|
||
// Build up columns to include. Order matters. | ||
const columns: ColumnsType<IndexedTrendResult> = [] | ||
|
||
if (isLegend) { | ||
columns.push({ | ||
title: '', | ||
render: function RenderCheckbox({}, item: IndexedTrendResult, index: number) { | ||
// legend will always be on insight page where the background is white | ||
return ( | ||
<PHCheckbox | ||
color={getChartColors('white')[index]} | ||
checked={visibilityMap[item.id]} | ||
onChange={() => toggleVisibility(item.id)} | ||
disabled={isSingleEntity} | ||
/> | ||
) | ||
}, | ||
fixed: 'left', | ||
width: 60, | ||
}) | ||
} | ||
|
||
columns.push({ | ||
title: 'Label', | ||
render: function RenderLabel({}, item: IndexedTrendResult) { | ||
return ( | ||
<span | ||
style={{ cursor: isSingleEntity ? undefined : 'pointer' }} | ||
onClick={() => !isSingleEntity && toggleVisibility(item.id)} | ||
> | ||
{formatLabel(item)} | ||
</span> | ||
) | ||
}, | ||
fixed: 'left', | ||
width: 150, | ||
}) | ||
|
||
if (showTotalCount) { | ||
columns.push({ | ||
title: 'Total', | ||
dataIndex: 'count', | ||
fixed: 'left', | ||
width: 100, | ||
}) | ||
} | ||
|
||
if (filters.breakdown) { | ||
columns.push({ | ||
title: 'Breakdown Value', | ||
render: function RenderBreakdownValue({}, item: IndexedTrendResult) { | ||
return formatBreakdownLabel(item.breakdown_value, cohorts) | ||
}, | ||
fixed: 'left', | ||
width: 150, | ||
}) | ||
} | ||
|
||
if (indexedResults && indexedResults.length > 0) { | ||
const valueColumns = indexedResults[0].data.map(({}, index: number) => ({ | ||
title: (indexedResults[0].labels || indexedResults[0].dates || indexedResults[0].days)[index], | ||
render: function RenderPeriod({}, item: IndexedTrendResult) { | ||
return maybeAddCommasToInteger(item.data[index]) | ||
}, | ||
})) | ||
|
||
columns.push(...valueColumns) | ||
} | ||
|
||
return ( | ||
<Table | ||
dataSource={indexedResults} | ||
columns={columns} | ||
size="small" | ||
rowKey="id" | ||
pagination={{ pageSize: 100, hideOnSinglePage: true }} | ||
style={{ marginTop: '1rem' }} | ||
scroll={indexedResults && indexedResults.length > 0 ? { x: indexedResults[0].data.length * 160 } : {}} | ||
data-attr="insights-table-graph" | ||
/> | ||
) | ||
} | ||
import { InsightsTable } from './InsightsTable' | ||
export { InsightsTable } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters