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.

fix(desktop): send flat source select fields as plain values (#122747)

Andrew Maguireb93dd84df559
diff --git a/products/desktop/packages/ui/src/features/inbox/components/DynamicSourceSetup.test.ts b/products/desktop/packages/ui/src/features/inbox/components/DynamicSourceSetup.test.ts
new file mode 100644
index 000000000000..803080e6c0aa
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/inbox/components/DynamicSourceSetup.test.ts
@@ -0,0 +1,73 @@
+import type { SourceConfig } from "@posthog/api-client/posthog-client";
+import { describe, expect, it } from "vitest";
+import { buildPayload } from "./DynamicSourceSetup";
+
+const flatSelectConfig = {
+ name: "Datadog",
+ fields: [
+ {
+ type: "select",
+ name: "site",
+ label: "Datadog site",
+ required: true,
+ defaultValue: "datadoghq.com",
+ options: [
+ { label: "US1", value: "datadoghq.com" },
+ { label: "EU1", value: "datadoghq.eu" },
+ ],
+ },
+ ],
+} as unknown as SourceConfig;
+
+const nestedSelectConfig = {
+ name: "Example",
+ fields: [
+ {
+ type: "select",
+ name: "auth_method",
+ label: "Auth method",
+ required: true,
+ defaultValue: "api_key",
+ options: [
+ {
+ label: "API key",
+ value: "api_key",
+ fields: [
+ { type: "text", name: "api_key", label: "API key", required: true },
+ ],
+ },
+ { label: "OAuth", value: "oauth" },
+ ],
+ },
+ ],
+} as unknown as SourceConfig;
+
+describe("buildPayload", () => {
+ it.each<{
+ name: string;
+ config: SourceConfig;
+ values: Parameters<typeof buildPayload>[1];
+ expected: Record<string, unknown>;
+ }>([
+ {
+ name: "flat select sends the chosen value",
+ config: flatSelectConfig,
+ values: { site: "datadoghq.eu" },
+ expected: { site: "datadoghq.eu" },
+ },
+ {
+ name: "flat select falls back to the default",
+ config: flatSelectConfig,
+ values: {},
+ expected: { site: "datadoghq.com" },
+ },
+ {
+ name: "select with option fields nests the selection",
+ config: nestedSelectConfig,
+ values: { auth_method: "api_key", api_key: " secret " },
+ expected: { auth_method: { selection: "api_key", api_key: "secret" } },
+ },
+ ])("$name", ({ config, values, expected }) => {
+ expect(buildPayload(config, values)).toEqual(expected);
+ });
+});
diff --git a/products/desktop/packages/ui/src/features/inbox/components/DynamicSourceSetup.tsx b/products/desktop/packages/ui/src/features/inbox/components/DynamicSourceSetup.tsx
index c5d57650c4a3..8e01eb5b6e56 100644
--- a/products/desktop/packages/ui/src/features/inbox/components/DynamicSourceSetup.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/components/DynamicSourceSetup.tsx
@@ -124,7 +124,7 @@ function missingRequiredFields(
* Build the `createExternalDataSource` payload from the collected field values,
* mirroring how PostHog Cloud nests switch-group and select fields.
*/
-function buildPayload(
+export function buildPayload(
config: SourceConfig,
values: FieldValues,
): Record<string, unknown> {
@@ -136,6 +136,15 @@ function buildPayload(
out[field.name] = { enabled, ...collect(field.fields) };
} else if (field.type === "select") {
const selected = (values[field.name] as string) ?? field.defaultValue;
+ // Cloud nests a select as `{ selection }` only when an option carries
+ // sub-fields; a flat select (e.g. Datadog `site`) is sent as a plain value.
+ const hasOptionFields = field.options.some(
+ (o) => (o.fields?.length ?? 0) > 0,
+ );
+ if (!hasOptionFields) {
+ out[field.name] = selected;
+ continue;
+ }
const option = field.options.find((o) => o.value === selected);
out[field.name] = {
selection: selected,