Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(insights): allow un-setting result customization color (#59101)

Thomas Obermüller997cdd9187e9
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/SeriesTab.tsx b/frontend/src/queries/nodes/DataVisualization/Components/SeriesTab.tsx
index 0e838e1c016f..0e833b40395b 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/SeriesTab.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/SeriesTab.tsx
@@ -683,6 +683,10 @@ const BreakdownSeries = ({
},
})
}}
+ onClearColorToken={() => {
+ const { [series.breakdownValue]: _removed, ...rest } = chartSettings.resultCustomizations ?? {}
+ updateChartSettings({ resultCustomizations: rest })
+ }}
/>
<span>{series.name ? series.name : '[No value]'}</span>
</div>
diff --git a/frontend/src/queries/nodes/InsightViz/ResultCustomizationsModal.tsx b/frontend/src/queries/nodes/InsightViz/ResultCustomizationsModal.tsx
index a5e55bddaf22..0780299ecdd5 100644
--- a/frontend/src/queries/nodes/InsightViz/ResultCustomizationsModal.tsx
+++ b/frontend/src/queries/nodes/InsightViz/ResultCustomizationsModal.tsx
@@ -1,9 +1,10 @@
import { useActions, useValues } from 'kea'
-import { LemonButton, LemonColorButton, LemonModal } from '@posthog/lemon-ui'
+import { LemonButton, LemonModal } from '@posthog/lemon-ui'
import { DataColorToken } from 'lib/colors'
import { EntityFilterInfo } from 'lib/components/EntityFilterInfo'
+import { LemonColorList } from 'lib/lemon-ui/LemonColor/LemonColorList'
import { dataThemeLogic } from 'scenes/dataThemeLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
@@ -23,7 +24,9 @@ export function ResultCustomizationsModal(): JSX.Element | null {
const { modalVisible, dataset, colorToken, resultCustomizationBy } = useValues(
resultCustomizationsModalLogic(insightProps)
)
- const { closeModal, setColorToken, save } = useActions(resultCustomizationsModalLogic(insightProps))
+ const { closeModal, setColorToken, clearColorToken, save } = useActions(
+ resultCustomizationsModalLogic(insightProps)
+ )
const { isTrends, isFunnels, querySource } = useValues(insightVizDataLogic)
@@ -63,21 +66,12 @@ export function ResultCustomizationsModal(): JSX.Element | null {
{isFunnels && <FunnelsInfo dataset={dataset as FlattenedFunnelStepByBreakdown} />}
<h3 className="l4 mt-2 mb-2">Color</h3>
- <div className="flex flex-wrap gap-1">
- {Object.keys(theme).map((key) => (
- <LemonColorButton
- key={key}
- colorToken={key as DataColorToken}
- type={key === colorToken ? 'secondary' : 'tertiary'}
- onClick={(e) => {
- e.preventDefault()
- e.stopPropagation()
-
- setColorToken(key as DataColorToken)
- }}
- />
- ))}
- </div>
+ <LemonColorList
+ colorTokens={Object.keys(theme) as DataColorToken[]}
+ selectedColorToken={colorToken}
+ onSelectColorToken={setColorToken}
+ onClearColorToken={clearColorToken}
+ />
</LemonModal>
)
}
diff --git a/frontend/src/queries/nodes/InsightViz/resultCustomizationsModalLogic.ts b/frontend/src/queries/nodes/InsightViz/resultCustomizationsModalLogic.ts
index f82281a860ed..6fb7c9602221 100644
--- a/frontend/src/queries/nodes/InsightViz/resultCustomizationsModalLogic.ts
+++ b/frontend/src/queries/nodes/InsightViz/resultCustomizationsModalLogic.ts
@@ -4,7 +4,12 @@ import { DataColorToken } from 'lib/colors'
import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
-import { getFunnelDatasetKey, getTrendResultCustomization, getTrendResultCustomizationKey } from 'scenes/insights/utils'
+import {
+ getFunnelDatasetKey,
+ getFunnelResultCustomization,
+ getTrendResultCustomization,
+ getTrendResultCustomizationKey,
+} from 'scenes/insights/utils'
import { trendsDataLogic } from 'scenes/trends/trendsDataLogic'
import { IndexedTrendResult } from 'scenes/trends/types'
@@ -35,6 +40,7 @@ export const resultCustomizationsModalLogic = kea<resultCustomizationsModalLogic
closeModal: true,
setColorToken: (token: DataColorToken) => ({ token }),
+ clearColorToken: true,
save: true,
}),
@@ -51,16 +57,26 @@ export const resultCustomizationsModalLogic = kea<resultCustomizationsModalLogic
null as DataColorToken | null,
{
setColorToken: (_, { token }) => token,
+ clearColorToken: () => null,
closeModal: () => null,
},
],
+ localColorTokenTouched: [
+ false,
+ {
+ setColorToken: () => true,
+ clearColorToken: () => true,
+ closeModal: () => false,
+ },
+ ],
}),
selectors({
modalVisible: [(s) => [s.dataset], (dataset): boolean => dataset !== null],
colorToken: [
- (s) => [s.localColorToken, s.colorTokenFromQuery],
- (localColorToken, colorTokenFromQuery): DataColorToken | null => localColorToken || colorTokenFromQuery,
+ (s) => [s.localColorToken, s.localColorTokenTouched, s.colorTokenFromQuery],
+ (localColorToken, localColorTokenTouched, colorTokenFromQuery): DataColorToken | null =>
+ localColorTokenTouched ? localColorToken : colorTokenFromQuery,
],
colorTokenFromQuery: [
(s) => [s.isTrends, s.isStickiness, s.isFunnels, s.getTrendsColorToken, s.getFunnelsColorToken, s.dataset],
@@ -107,11 +123,13 @@ export const resultCustomizationsModalLogic = kea<resultCustomizationsModalLogic
listeners(({ actions, values }) => ({
save: () => {
- if (values.localColorToken == null || values.dataset == null) {
+ if (!values.localColorTokenTouched || values.dataset == null) {
actions.closeModal()
return
}
+ const color = values.localColorToken ?? undefined
+
if (values.isTrends || values.isStickiness) {
const resultCustomizationKey = getTrendResultCustomizationKey(
values.resultCustomizationBy,
@@ -128,7 +146,7 @@ export const resultCustomizationsModalLogic = kea<resultCustomizationsModalLogic
[resultCustomizationKey]: {
...resultCustomization,
assignmentBy: values.resultCustomizationBy,
- color: values.localColorToken,
+ color,
},
},
} as Partial<TrendsFilter>)
@@ -136,12 +154,17 @@ export const resultCustomizationsModalLogic = kea<resultCustomizationsModalLogic
if (values.isFunnels) {
const resultCustomizationKey = getFunnelDatasetKey(values.dataset as FlattenedFunnelStepByBreakdown)
+ const resultCustomization = getFunnelResultCustomization(
+ values.dataset as FlattenedFunnelStepByBreakdown,
+ values.funnelsResultCustomizations
+ )
actions.updateInsightFilter({
resultCustomizations: {
...values.funnelsResultCustomizations,
[resultCustomizationKey]: {
+ ...resultCustomization,
assignmentBy: ResultCustomizationBy.Value,
- color: values.localColorToken,
+ color,
},
},
})