Skip to content

Automate browser based workflows with AI

Render Google Sheets destination dropdown options as single A - Header lines (SKY-13180) (#7840)

Suchintan8496b9319d66
diff --git a/skyvern-frontend/src/routes/workflows/components/ColumnMappingEditor.test.tsx b/skyvern-frontend/src/routes/workflows/components/ColumnMappingEditor.test.tsx
new file mode 100644
index 000000000..e8d3a247e
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/components/ColumnMappingEditor.test.tsx
@@ -0,0 +1,51 @@
+// @vitest-environment jsdom
+
+import { fireEvent, render, screen } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+
+import { ColumnMappingEditor } from "./ColumnMappingEditor";
+
+describe("ColumnMappingEditor", () => {
+ it("renders combined labels as option values without text content", () => {
+ render(
+ <ColumnMappingEditor
+ idScope="test"
+ value='{"myfield":"Z"}'
+ onChange={vi.fn()}
+ headers={[
+ { letter: "A", name: "Name" },
+ { letter: "B", name: " " },
+ ]}
+ />,
+ );
+
+ const options = Array.from(document.querySelectorAll("option"));
+ expect(
+ options.map((option) => ({
+ value: option.value,
+ textContent: option.textContent,
+ })),
+ ).toEqual([
+ { value: "A - Name", textContent: "" },
+ { value: "B", textContent: "" },
+ ]);
+ });
+
+ it("serializes a selected combined label as its bare letter", () => {
+ const onChange = vi.fn();
+ render(
+ <ColumnMappingEditor
+ idScope="test"
+ value='{"myfield":"Z"}'
+ onChange={onChange}
+ headers={[{ letter: "A", name: "Name" }]}
+ />,
+ );
+
+ fireEvent.change(screen.getByPlaceholderText("A - Name"), {
+ target: { value: "A - Name" },
+ });
+
+ expect(onChange).toHaveBeenCalledWith('{"myfield":"A"}');
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/components/ColumnMappingEditor.tsx b/skyvern-frontend/src/routes/workflows/components/ColumnMappingEditor.tsx
index 1a244c4b2..6fefef190 100644
--- a/skyvern-frontend/src/routes/workflows/components/ColumnMappingEditor.tsx
+++ b/skyvern-frontend/src/routes/workflows/components/ColumnMappingEditor.tsx
@@ -1,10 +1,11 @@
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useState } from "react";
import { Cross2Icon, PlusIcon } from "@radix-ui/react-icons";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { cn } from "@/util/utils";
import {
+ formatDestinationLabel,
newEntryId,
parseColumnMapping,
resolveDestination,
@@ -54,15 +55,6 @@ function ColumnMappingEditor({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]);
- const headerOptions = useMemo(
- () =>
- headers.map((h) => ({
- value: h.letter,
- label: `${h.letter} - ${h.name}`,
- })),
- [headers],
- );
-
const commit = (next: ColumnMappingEntry[]) => {
setEntries(next);
onChange(serializeColumnMapping(next));
@@ -142,12 +134,10 @@ function ColumnMappingEditor({
disabled={disabled}
onChange={(e) => updateLetter(index, e.target.value)}
/>
- {headerOptions.length > 0 ? (
+ {headers.length > 0 ? (
<datalist id={`column-mapping-headers-${idScope}-${rowId}`}>
- {headerOptions.map((opt) => (
- <option key={opt.value} value={opt.value}>
- {opt.label}
- </option>
+ {headers.map((h) => (
+ <option key={h.letter} value={formatDestinationLabel(h)} />
))}
</datalist>
) : null}
diff --git a/skyvern-frontend/src/util/columnMappingSerialization.test.ts b/skyvern-frontend/src/util/columnMappingSerialization.test.ts
index 8709390e5..a38728d83 100644
--- a/skyvern-frontend/src/util/columnMappingSerialization.test.ts
+++ b/skyvern-frontend/src/util/columnMappingSerialization.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import {
+ formatDestinationLabel,
parseColumnMapping,
serializeColumnMapping,
resolveDestination,
@@ -88,6 +89,22 @@ describe("resolveDestination", () => {
expect(resolveDestination("email", headers)).toBe("B");
});
+ it("resolves a combined destination label (case-insensitive) to its letter", () => {
+ expect(resolveDestination("A - Name", headers)).toBe("A");
+ expect(resolveDestination("a - name", headers)).toBe("A");
+ });
+
+ it("resolves a combined label whose header name contains a separator", () => {
+ const headersWithSeparator = [{ letter: "D", name: "Score - Notes" }];
+ expect(resolveDestination("D - Score - Notes", headersWithSeparator)).toBe(
+ "D",
+ );
+ });
+
+ it("preserves an unmatched combined-looking string", () => {
+ expect(resolveDestination("ZZ - Unknown", headers)).toBe("ZZ - Unknown");
+ });
+
it("preserves user casing when no header matches and not a pure column letter", () => {
expect(resolveDestination(" Phone Number ", [])).toBe("Phone Number");
});
@@ -102,3 +119,15 @@ describe("resolveDestination", () => {
expect(resolveDestination(" ", headers)).toBe("");
});
});
+
+describe("formatDestinationLabel", () => {
+ it("formats named and unnamed headers", () => {
+ expect(formatDestinationLabel({ letter: "A", name: "Name" })).toBe(
+ "A - Name",
+ );
+ expect(formatDestinationLabel({ letter: "A", name: " " })).toBe("A");
+ expect(formatDestinationLabel({ letter: "A", name: " Padded " })).toBe(
+ "A - Padded",
+ );
+ });
+});
diff --git a/skyvern-frontend/src/util/columnMappingSerialization.ts b/skyvern-frontend/src/util/columnMappingSerialization.ts
index 4491fa274..e9f4494db 100644
--- a/skyvern-frontend/src/util/columnMappingSerialization.ts
+++ b/skyvern-frontend/src/util/columnMappingSerialization.ts
@@ -5,6 +5,14 @@ export type ColumnMappingEntry = {
_id?: string;
};
+export function formatDestinationLabel(header: {
+ letter: string;
+ name: string;
+}): string {
+ const name = header.name.trim();
+ return name ? `${header.letter} - ${name}` : header.letter;
+}
+
export function newEntryId(): string {
if (
typeof crypto !== "undefined" &&
@@ -53,9 +61,10 @@ export function resolveDestination(
): string {
const trimmed = input.trim();
if (!trimmed) return "";
- const match = headers.find(
- (h) => h.name.toLowerCase() === trimmed.toLowerCase(),
- );
+ const lowered = trimmed.toLowerCase();
+ const match =
+ headers.find((h) => formatDestinationLabel(h).toLowerCase() === lowered) ??
+ headers.find((h) => h.name.toLowerCase() === lowered);
if (match) return match.letter;
const upper = trimmed.toUpperCase();
if (LETTER_RE.test(upper)) return upper;