-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into xvello/replay-overflow-capture
- Loading branch information
Showing
25 changed files
with
289 additions
and
169 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
ee/clickhouse/views/test/__snapshots__/test_clickhouse_experiment_secondary_results.ambr
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
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
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
96 changes: 96 additions & 0 deletions
96
frontend/src/lib/components/UpgradeModal/upgradeModalLogic.ts
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { actions, connect, kea, listeners, path, reducers, selectors } from 'kea' | ||
import { featureFlagLogic } from 'lib/logic/featureFlagLogic' | ||
import { eventUsageLogic } from 'lib/utils/eventUsageLogic' | ||
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic' | ||
import { userLogic } from 'scenes/userLogic' | ||
|
||
import { AvailableFeature } from '~/types' | ||
|
||
import type { upgradeModalLogicType } from './upgradeModalLogicType' | ||
|
||
export type GuardAvailableFeatureFn = ( | ||
featureKey: AvailableFeature, | ||
featureAvailableCallback?: () => void, | ||
options?: { | ||
guardOnCloud?: boolean | ||
guardOnSelfHosted?: boolean | ||
currentUsage?: number | ||
isGrandfathered?: boolean | ||
} | ||
) => boolean | ||
|
||
export const upgradeModalLogic = kea<upgradeModalLogicType>([ | ||
path(['lib', 'components', 'UpgradeModal', 'upgradeModalLogic']), | ||
connect(() => ({ | ||
values: [preflightLogic, ['preflight'], featureFlagLogic, ['featureFlags'], userLogic, ['hasAvailableFeature']], | ||
})), | ||
actions({ | ||
showUpgradeModal: (featureKey: AvailableFeature, currentUsage?: number, isGrandfathered?: boolean) => ({ | ||
featureKey, | ||
currentUsage, | ||
isGrandfathered, | ||
}), | ||
hideUpgradeModal: true, | ||
}), | ||
reducers({ | ||
upgradeModalFeatureKey: [ | ||
null as AvailableFeature | null, | ||
{ | ||
showUpgradeModal: (_, { featureKey }) => featureKey, | ||
hideUpgradeModal: () => null, | ||
}, | ||
], | ||
upgradeModalFeatureUsage: [ | ||
null as number | null, | ||
{ | ||
showUpgradeModal: (_, { currentUsage }) => currentUsage ?? null, | ||
hideUpgradeModal: () => null, | ||
}, | ||
], | ||
upgradeModalIsGrandfathered: [ | ||
null as boolean | null, | ||
{ | ||
showUpgradeModal: (_, { isGrandfathered }) => isGrandfathered ?? null, | ||
hideUpgradeModal: () => null, | ||
}, | ||
], | ||
}), | ||
selectors(({ actions }) => ({ | ||
guardAvailableFeature: [ | ||
(s) => [s.preflight, s.hasAvailableFeature], | ||
(preflight, hasAvailableFeature): GuardAvailableFeatureFn => { | ||
return (featureKey, featureAvailableCallback, options): boolean => { | ||
const { | ||
guardOnCloud = true, | ||
guardOnSelfHosted = true, | ||
currentUsage, | ||
isGrandfathered, | ||
} = options || {} | ||
let featureAvailable: boolean | ||
if (!preflight) { | ||
featureAvailable = false | ||
} else if (!guardOnCloud && preflight.cloud) { | ||
featureAvailable = true | ||
} else if (!guardOnSelfHosted && !preflight.cloud) { | ||
featureAvailable = true | ||
} else { | ||
featureAvailable = hasAvailableFeature(featureKey, currentUsage) | ||
} | ||
|
||
if (!featureAvailable) { | ||
actions.showUpgradeModal(featureKey, currentUsage, isGrandfathered) | ||
} else { | ||
featureAvailableCallback?.() | ||
} | ||
|
||
return featureAvailable | ||
} | ||
}, | ||
], | ||
})), | ||
listeners(() => ({ | ||
showUpgradeModal: ({ featureKey }) => { | ||
eventUsageLogic.actions.reportUpgradeModalShown(featureKey) | ||
}, | ||
})), | ||
]) |
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
Oops, something went wrong.