0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-21 13:39:22 +01:00
This commit is contained in:
Marius Andra 2024-11-20 16:11:50 +01:00
parent edb290cf48
commit d8023c4382
2 changed files with 19 additions and 11 deletions

View File

@ -460,12 +460,14 @@ export function HogFunctionConfiguration({ templateId, id }: HogFunctionConfigur
<LemonField name="hog">
{({ value, onChange }) => (
<>
<span className="text-xs text-muted-alt">
This is the underlying Hog code that will run whenever the
filters match.{' '}
<Link to="https://posthog.com/docs/hog">See the docs</Link> for
more info
</span>
{type !== 'web' ? (
<span className="text-xs text-muted-alt">
This is the underlying Hog code that will run whenever the
filters match.{' '}
<Link to="https://posthog.com/docs/hog">See the docs</Link>{' '}
for more info
</span>
) : null}
<CodeEditorResizeable
language={type === 'web' ? 'typescript' : 'hog'}
value={value ?? ''}

View File

@ -187,10 +187,10 @@ class HogFunctionSerializer(HogFunctionMinimalSerializer):
if "hog" in attrs:
if attrs["type"] == "web":
# TODO: do we always have instance.id available?
attrs["transpiled"] = get_transpiled_function(
str(instance.id), attrs["hog"], attrs["filters"], attrs["inputs"], team
)
# Upon creation, this code will be run before the model has an "id".
# If that's the case, the code just makes sure transpilation doesn't throw. We'll re-transpile after creation.
id = str(instance.id) if instance else "__"
attrs["transpiled"] = get_transpiled_function(id, attrs["hog"], attrs["filters"], attrs["inputs"], team)
attrs["bytecode"] = None
else:
attrs["bytecode"] = compile_hog(attrs["hog"])
@ -223,7 +223,13 @@ class HogFunctionSerializer(HogFunctionMinimalSerializer):
def create(self, validated_data: dict, *args, **kwargs) -> HogFunction:
request = self.context["request"]
validated_data["created_by"] = request.user
return super().create(validated_data=validated_data)
hog_function = super().create(validated_data=validated_data)
if validated_data.get("type") == "web":
# Re-run the transpilation now that we have an ID
hog_function.transpiled = get_transpiled_function(
str(hog_function.id), hog_function.hog, hog_function.filters, hog_function.inputs, hog_function.team
)
return hog_function
def update(self, instance: HogFunction, validated_data: dict, *args, **kwargs) -> HogFunction:
res: HogFunction = super().update(instance, validated_data)