Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notebooks): use varying keys for breakdown filter #18596

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/src/queries/nodes/InsightViz/Breakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function Breakdown({ insightProps }: EditorFilterProps): JSX.Element {

return (
<TaxonomicBreakdownFilter
insightProps={insightProps}
breakdownFilter={breakdown}
display={display}
isTrends={isTrends}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { cohortsModel } from '~/models/cohortsModel'
import { isAllCohort, isCohort } from './taxonomicBreakdownFilterUtils'

import './BreakdownTag.scss'
import { insightLogic } from 'scenes/insights/insightLogic'

type EditableBreakdownTagProps = {
breakdown: string | number
Expand All @@ -21,10 +22,11 @@ type EditableBreakdownTagProps = {
}

export function EditableBreakdownTag({ breakdown, breakdownType, isTrends }: EditableBreakdownTagProps): JSX.Element {
const { insightProps } = useValues(insightLogic)
const [filterOpen, setFilterOpen] = useState(false)
const [menuOpen, setMenuOpen] = useState(false)

const logicProps = { breakdown, breakdownType, isTrends }
const logicProps = { insightProps, breakdown, breakdownType, isTrends }
const { shouldShowMenu } = useValues(breakdownTagLogic(logicProps))
const { removeBreakdown } = useActions(breakdownTagLogic(logicProps))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { BindLogic, useValues } from 'kea'
import { TaxonomicBreakdownButton } from 'scenes/insights/filters/BreakdownFilter/TaxonomicBreakdownButton'
import { BreakdownFilter } from '~/queries/schema'
import { ChartDisplayType } from '~/types'
import { ChartDisplayType, InsightLogicProps } from '~/types'
import { EditableBreakdownTag } from './BreakdownTag'
import { taxonomicBreakdownFilterLogic, TaxonomicBreakdownFilterLogicProps } from './taxonomicBreakdownFilterLogic'

export interface TaxonomicBreakdownFilterProps {
insightProps: InsightLogicProps
breakdownFilter?: BreakdownFilter | null
display?: ChartDisplayType | null
isTrends: boolean
Expand All @@ -14,13 +15,15 @@ export interface TaxonomicBreakdownFilterProps {
}

export function TaxonomicBreakdownFilter({
insightProps,
breakdownFilter,
display,
isTrends,
updateBreakdown,
updateDisplay,
}: TaxonomicBreakdownFilterProps): JSX.Element {
const logicProps: TaxonomicBreakdownFilterLogicProps = {
insightProps,
isTrends,
display,
breakdownFilter: breakdownFilter || {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { isURLNormalizeable } from './taxonomicBreakdownFilterUtils'
import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
import { cohortsModel } from '~/models/cohortsModel'
import { propertyFilterTypeToPropertyDefinitionType } from 'lib/components/PropertyFilters/utils'
import { InsightLogicProps } from '~/types'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'

export interface BreakdownTagLogicProps {
insightProps: InsightLogicProps
breakdown: string | number
breakdownType: string
isTrends: boolean
}

export const breakdownTagLogic = kea<breakdownTagLogicType>([
props({} as BreakdownTagLogicProps),
key(({ breakdown }) => breakdown),
key(({ insightProps, breakdown }) => `${keyForInsightLogicProps('new')(insightProps)}-${breakdown}`),
path((key) => ['scenes', 'insights', 'BreakdownFilter', 'breakdownTagLogic', key]),
connect(() => ({
values: [propertyDefinitionsModel, ['getPropertyDefinition'], cohortsModel, ['cohortsById']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { initKeaTests } from '~/test/init'
import { TaxonomicFilterGroup, TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'

import { taxonomicBreakdownFilterLogic } from './taxonomicBreakdownFilterLogic'
import { InsightLogicProps } from '~/types'

const taxonomicGroupFor = (
type: TaxonomicFilterGroupType,
Expand All @@ -20,6 +21,7 @@ const taxonomicGroupFor = (

const updateBreakdown = jest.fn()
const updateDisplay = jest.fn()
const insightProps: InsightLogicProps = { dashboardItemId: 'new' }

describe('taxonomicBreakdownFilterLogic', () => {
let logic: ReturnType<typeof taxonomicBreakdownFilterLogic.build>
Expand All @@ -31,6 +33,7 @@ describe('taxonomicBreakdownFilterLogic', () => {
describe('addBreakdown', () => {
it('sets breakdown for events', async () => {
logic = taxonomicBreakdownFilterLogic({
insightProps,
breakdownFilter: {},
isTrends: true,
updateBreakdown,
Expand All @@ -54,6 +57,7 @@ describe('taxonomicBreakdownFilterLogic', () => {

it('sets breakdown for cohorts', async () => {
logic = taxonomicBreakdownFilterLogic({
insightProps,
breakdownFilter: {
breakdown_type: 'cohort',
breakdown: ['all', 1],
Expand Down Expand Up @@ -84,6 +88,7 @@ describe('taxonomicBreakdownFilterLogic', () => {

it('sets breakdown for person properties', async () => {
logic = taxonomicBreakdownFilterLogic({
insightProps,
breakdownFilter: {},
isTrends: true,
updateBreakdown,
Expand All @@ -106,6 +111,7 @@ describe('taxonomicBreakdownFilterLogic', () => {

it('sets breakdown for group properties', async () => {
logic = taxonomicBreakdownFilterLogic({
insightProps,
breakdownFilter: {},
isTrends: true,
updateBreakdown,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { actions, connect, defaults, kea, listeners, path, props, reducers, selectors } from 'kea'
import { actions, connect, defaults, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import {
breakdownFilterToTaxonomicFilterType,
propertyFilterTypeToPropertyDefinitionType,
Expand All @@ -11,12 +11,14 @@ import {
} from 'lib/components/TaxonomicFilter/types'
import { BreakdownFilter } from '~/queries/schema'
import { isCohortBreakdown, isURLNormalizeable } from './taxonomicBreakdownFilterUtils'
import { BreakdownType, ChartDisplayType } from '~/types'
import { BreakdownType, ChartDisplayType, InsightLogicProps } from '~/types'

import type { taxonomicBreakdownFilterLogicType } from './taxonomicBreakdownFilterLogicType'
import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'

export type TaxonomicBreakdownFilterLogicProps = {
insightProps: InsightLogicProps
breakdownFilter: BreakdownFilter
display?: ChartDisplayType | null
isTrends: boolean
Expand All @@ -25,8 +27,9 @@ export type TaxonomicBreakdownFilterLogicProps = {
}

export const taxonomicBreakdownFilterLogic = kea<taxonomicBreakdownFilterLogicType>([
path(['scenes', 'insights', 'filters', 'BreakdownFilter', 'taxonomicBreakdownFilterLogic']),
props({} as TaxonomicBreakdownFilterLogicProps),
key((props) => keyForInsightLogicProps('new')(props.insightProps)),
path(['scenes', 'insights', 'filters', 'BreakdownFilter', 'taxonomicBreakdownFilterLogic']),
defaults({
// This is a hack to get `TaxonomicFilterGroupType` imported in `taxonomicBreakdownFilterLogicType.ts`
__ignore: null as TaxonomicFilterGroupType | null,
Expand Down
Loading