Skip to content

Commit

Permalink
Merge branch 'feat/cdp-internal-events' into feat/cdp-error-events
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Dec 19, 2024
2 parents d424ac7 + 518fd97 commit e2990b1
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 114 deletions.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function SidePanelActivitySubscriptions(): JSX.Element {

<LinkedHogFunctions
type="internal_destination"
subTemplateId="activity_log"
subTemplateId="activity-log"
filters={{
events: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function EarlyAccessFeature({ id }: { id?: string } = {}): JSX.Element {
</div>
)}
</div>
<div className="flex flex-wrap gap-4 items-start">
<div className="flex flex-wrap items-start gap-4">
<div className="flex-1 min-w-[20rem]">
{isEditingFeature || isNewEarlyAccessFeature ? (
<LemonField name="description" label="Description" showOptional>
Expand Down Expand Up @@ -333,14 +333,14 @@ export function EarlyAccessFeature({ id }: { id?: string } = {}): JSX.Element {
<LinkedHogFunctions
type="destination"
filters={destinationFilters}
subTemplateId="early_access_feature_enrollment"
subTemplateId="early-access-feature-enrollment"
/>
</>
)}
{!isEditingFeature && !isNewEarlyAccessFeature && 'id' in earlyAccessFeature && (
<>
<LemonDivider className="my-8" />
<div className="flex items-start justify-between gap-4">
<div className="flex items-start justify-between gap-4">
<div>
<h3>Users</h3>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ export function HogFunctionConfiguration({
personsCountLoading,
personsListQuery,
template,
subTemplate,
templateHasChanged,
forcedSubTemplateId,
type,
} = useValues(logic)
const {
Expand All @@ -94,7 +92,6 @@ export function HogFunctionConfiguration({
duplicateFromTemplate,
setConfigurationValue,
deleteHogFunction,
setSubTemplateId,
} = useActions(logic)

if (loading && !loaded) {
Expand Down Expand Up @@ -384,41 +381,6 @@ export function HogFunctionConfiguration({
</div>

<div className="space-y-4 flex-2 min-w-100">
{!forcedSubTemplateId && template?.sub_templates && (
<>
<div className="p-3 space-y-2 border rounded bg-bg-light">
<div className="flex items-center gap-2">
<LemonLabel className="flex-1">Choose template</LemonLabel>
<LemonSelect
size="small"
options={[
{
value: null,
label: 'Default',
},
...template.sub_templates.map((subTemplate) => ({
value: subTemplate.id,
label: subTemplate.name,
labelInMenu: (
<div className="my-1 space-y-1 max-w-120">
<div className="font-semibold">{subTemplate.name}</div>
<div className="font-sans text-xs text-muted">
{subTemplate.description}
</div>
</div>
),
})),
]}
value={subTemplate?.id}
onChange={(value) => {
setSubTemplateId(value)
}}
/>
</div>
</div>
</>
)}

<div className="p-3 space-y-2 border rounded bg-bg-light">
<div className="space-y-2">
<HogFunctionInputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const HOG_TEMPLATE: HogFunctionTemplateType = {
inputs: null,
},
{
id: 'survey_response',
id: 'survey-response',
name: 'HTTP Webhook on survey response',
description: null,
filters: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import {
HogFunctionInputType,
HogFunctionInvocationGlobals,
HogFunctionMappingType,
HogFunctionSubTemplateIdType,
HogFunctionSubTemplateType,
HogFunctionTemplateType,
HogFunctionType,
HogFunctionTypeType,
Expand All @@ -49,7 +47,6 @@ import type { hogFunctionConfigurationLogicType } from './hogFunctionConfigurati

export interface HogFunctionConfigurationLogicProps {
templateId?: string | null
subTemplateId?: string | null
id?: string | null
}

Expand Down Expand Up @@ -116,19 +113,11 @@ export function sanitizeConfiguration(data: HogFunctionConfigurationType): HogFu
return payload
}

const templateToConfiguration = (
template: HogFunctionTemplateType,
subTemplate?: HogFunctionSubTemplateType | null
): HogFunctionConfigurationType => {
function getInputs(
inputs_schema?: HogFunctionInputSchemaType[] | null,
subTemplate?: HogFunctionSubTemplateType | null
): Record<string, HogFunctionInputType> {
const templateToConfiguration = (template: HogFunctionTemplateType): HogFunctionConfigurationType => {
function getInputs(inputs_schema?: HogFunctionInputSchemaType[] | null): Record<string, HogFunctionInputType> {
const inputs: Record<string, HogFunctionInputType> = {}
inputs_schema?.forEach((schema) => {
if (typeof subTemplate?.inputs?.[schema.key] !== 'undefined') {
inputs[schema.key] = { value: subTemplate.inputs[schema.key] }
} else if (schema.default !== undefined) {
if (schema.default !== undefined) {
inputs[schema.key] = { value: schema.default }
}
})
Expand All @@ -149,19 +138,19 @@ const templateToConfiguration = (

return {
type: template.type ?? 'destination',
name: subTemplate?.name ?? template.name,
description: subTemplate?.name ?? template.description,
name: template.name,
description: template.description,
inputs_schema: template.inputs_schema,
filters: subTemplate?.filters ?? template.filters,
mappings: (subTemplate?.mappings ?? template.mappings)?.map(
filters: template.filters,
mappings: template.mappings?.map(
(mapping): HogFunctionMappingType => ({
...mapping,
inputs: getMappingInputs(mapping.inputs_schema),
})
),
hog: template.hog,
icon_url: template.icon_url,
inputs: getInputs(template.inputs_schema, subTemplate),
inputs: getInputs(template.inputs_schema),
enabled: template.type !== 'broadcast',
}
}
Expand Down Expand Up @@ -226,7 +215,6 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
sparklineQueryChanged: (sparklineQuery: TrendsQuery) => ({ sparklineQuery } as { sparklineQuery: TrendsQuery }),
personsCountQueryChanged: (personsCountQuery: ActorsQuery) =>
({ personsCountQuery } as { personsCountQuery: ActorsQuery }),
setSubTemplateId: (subTemplateId: HogFunctionSubTemplateIdType | null) => ({ subTemplateId }),
loadSampleGlobals: true,
setUnsavedConfiguration: (configuration: HogFunctionConfigurationType | null) => ({ configuration }),
persistForUnload: true,
Expand All @@ -247,12 +235,6 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
upsertHogFunctionFailure: () => true,
},
],
subTemplateId: [
null as HogFunctionSubTemplateIdType | null,
{
setSubTemplateId: (_, { subTemplateId }) => subTemplateId,
},
],

unsavedConfiguration: [
null as { timestamp: number; configuration: HogFunctionConfigurationType } | null,
Expand Down Expand Up @@ -503,10 +485,10 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
(hogFunction, template) => (hogFunction ?? template)?.type === 'site_destination',
],
defaultFormState: [
(s) => [s.template, s.hogFunction, s.subTemplate],
(template, hogFunction, subTemplate): HogFunctionConfigurationType | null => {
(s) => [s.template, s.hogFunction],
(template, hogFunction): HogFunctionConfigurationType | null => {
if (template) {
return templateToConfiguration(template, subTemplate)
return templateToConfiguration(template)
}
return hogFunction ?? null
},
Expand Down Expand Up @@ -838,18 +820,6 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
return hogFunction?.template?.hog && hogFunction.template.hog !== configuration.hog
},
],
subTemplate: [
(s) => [s.template, s.subTemplateId],
(template, subTemplateId) => {
if (!template || !subTemplateId) {
return null
}

const subTemplate = template.sub_templates?.find((st) => st.id === subTemplateId)
return subTemplate
},
],
forcedSubTemplateId: [() => [router.selectors.searchParams], ({ sub_template }) => !!sub_template],
mappingTemplates: [
(s) => [s.hogFunction, s.template],
(hogFunction, template) => template?.mapping_templates ?? hogFunction?.template?.mapping_templates ?? [],
Expand Down Expand Up @@ -961,7 +931,7 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
resetToTemplate: async () => {
const template = values.hogFunction?.template ?? values.template
if (template) {
const config = templateToConfiguration(template, values.subTemplate)
const config = templateToConfiguration(template)

const inputs = config.inputs ?? {}

Expand Down Expand Up @@ -1009,10 +979,6 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
router.actions.replace(hogFunctionUrl(type))
},

setSubTemplateId: () => {
actions.resetToTemplate()
},

persistForUnload: () => {
actions.setUnsavedConfiguration(values.configuration)
},
Expand All @@ -1025,9 +991,6 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy

if (props.templateId) {
cache.configFromUrl = router.values.hashParams.configuration
if (router.values.searchParams.sub_template) {
actions.setSubTemplateId(router.values.searchParams.sub_template)
}
actions.loadTemplate() // comes with plugin info
} else if (props.id && props.id !== 'new') {
actions.loadHogFunction()
Expand Down
Loading

0 comments on commit e2990b1

Please sign in to comment.