Skip to content

Commit

Permalink
PR comment related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun-chaitanya committed Jul 26, 2023
1 parent 60a247a commit d60f811
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 36 deletions.
3 changes: 3 additions & 0 deletions frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ export const NON_VALUES_ON_SERIES_DISPLAY_TYPES = [
ChartDisplayType.WorldMap,
ChartDisplayType.BoldNumber,
]

/** Display types for which a percent stack view is available. */
export const PERCENT_STACK_VIEW_DISPLAY_TYPE = [
ChartDisplayType.ActionsBar,
ChartDisplayType.ActionsLineGraph,
ChartDisplayType.ActionsAreaGraph,
]

export enum OrganizationMembershipLevel {
Member = 1,
Admin = 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export const insightDisplayConfigLogic = kea<insightDisplayConfigLogicType>([
},
],
showPercentStackView: [
(s) => [s.isTrends, s.isLifecycle, s.display],
(isTrends, isLifecycle, display) =>
isTrends && display ? PERCENT_STACK_VIEW_DISPLAY_TYPE.includes(display) : isLifecycle,
(s) => [s.isTrends, s.display],
(isTrends, display) =>
isTrends && PERCENT_STACK_VIEW_DISPLAY_TYPE.includes(display || ChartDisplayType.ActionsLineGraph),
],
showUnit: [(s) => [s.supportsDisplay, s.isTrends], (supportsDisplay, isTrends) => supportsDisplay && isTrends],
showChart: [(s) => [s.supportsDisplay], (supportsDisplay) => supportsDisplay],
Expand Down
18 changes: 5 additions & 13 deletions frontend/src/queries/nodes/InsightViz/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,11 @@ export const getShowValueOnSeries = (query: InsightQueryNode): boolean | undefin
}

export const getShowPercentStackView = (query: InsightQueryNode): boolean | undefined => {
if (PERCENT_STACK_VIEW_DISPLAY_TYPE.includes(getDisplay(query) as ChartDisplayType)) {
if (isLifecycleQuery(query)) {
return query.lifecycleFilter?.show_percent_stack_view
} else if (isStickinessQuery(query)) {
return query.stickinessFilter?.show_percent_stack_view
} else if (isTrendsQuery(query)) {
return query.trendsFilter?.show_percent_stack_view
} else {
return undefined
}
} else {
return undefined
}
return PERCENT_STACK_VIEW_DISPLAY_TYPE.includes(
getDisplay(query) || (ChartDisplayType.ActionsLineGraph as ChartDisplayType)
) && isTrendsQuery(query)
? query.trendsFilter?.show_percent_stack_view
: undefined
}

export const getCachedResults = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useActions, useValues } from 'kea'
import { LemonCheckbox } from 'lib/lemon-ui/LemonCheckbox'
import { insightLogic } from '../insightLogic'
import { percentStackViewLogic } from './percentStackViewLogic'
import { trendsDataLogic } from 'scenes/trends/trendsDataLogic'

export function PercentStackView(): JSX.Element {
const { insightProps } = useValues(insightLogic)
const { showPercentStackView } = useValues(percentStackViewLogic(insightProps))
const { showPercentStackView } = useValues(trendsDataLogic(insightProps))
const { setShowPercentStackView } = useActions(percentStackViewLogic(insightProps))

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { actions, connect, kea, key, listeners, path, props, selectors } from 'kea'
import { InsightLogicProps, TrendsFilterType } from '~/types'
import { actions, connect, kea, key, listeners, path, props } from 'kea'
import { InsightLogicProps } from '~/types'
import { insightVizDataLogic } from '../insightVizDataLogic'
import { keyForInsightLogicProps } from '../sharedUtils'

Expand All @@ -11,26 +11,13 @@ export const percentStackViewLogic = kea<percentStackViewLogicType>([
path((key) => ['scenes', 'insights', 'EditorFilters', 'percentStackViewLogic', key]),

connect((props: InsightLogicProps) => ({
values: [insightVizDataLogic(props), ['isTrends', 'isStickiness', 'isLifecycle', 'insightFilter']],
actions: [insightVizDataLogic(props), ['updateInsightFilter']],
})),

actions({
setShowPercentStackView: (checked: boolean) => ({ checked }),
}),

selectors({
showPercentStackView: [
(s) => [s.isTrends, s.isStickiness, s.isLifecycle, s.insightFilter],
(isTrends, isStickiness, isLifecycle, insightFilter) => {
return !!(
(isTrends || isStickiness || isLifecycle) &&
(insightFilter as TrendsFilterType)?.show_percent_stack_view
)
},
],
}),

listeners(({ actions }) => ({
setShowPercentStackView: ({ checked }) => {
actions.updateInsightFilter({ show_percent_stack_view: checked })
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,9 @@ export function LineGraph_({
formatter: (value: number, context) => {
const data = context.chart.data as ExtendedChartData
const { datasetIndex, dataIndex } = context
if (showPercentStackView) {
return `${data.calculatedData?.[datasetIndex][dataIndex]}%`
const percentageValue = data.calculatedData?.[datasetIndex][dataIndex]
if (showPercentStackView && percentageValue) {
return formatYAxisLabel(trendsFilter, percentageValue)
}
return formatAggregationAxisValue(trendsFilter, value)
},
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,6 @@ export interface StickinessFilterType extends FilterType {
shown_as?: ShownAsValue
display?: ChartDisplayType
show_values_on_series?: boolean
show_percent_stack_view?: boolean
}
export interface FunnelsFilterType extends FilterType {
funnel_viz_type?: FunnelVizType // parameter sent to funnels API for time conversion code path
Expand Down Expand Up @@ -1722,7 +1721,6 @@ export interface RetentionFilterType extends FilterType {
export interface LifecycleFilterType extends FilterType {
shown_as?: ShownAsValue
show_values_on_series?: boolean
show_percent_stack_view?: boolean
toggledLifecycles?: LifecycleToggle[]
}

Expand Down

0 comments on commit d60f811

Please sign in to comment.