Skip to content

fix: Misc UX fixes#2157

Open
charlesvien wants to merge 5 commits into
mainfrom
05-17-misc_fixes
Open

fix: Misc UX fixes#2157
charlesvien wants to merge 5 commits into
mainfrom
05-17-misc_fixes

Conversation

@charlesvien
Copy link
Copy Markdown
Member

@charlesvien charlesvien commented May 17, 2026

Problem

Several small UX papercuts across settings, the file viewer, tool output and toasts.

Closes #2168

Changes

  1. Fix garbled initials in the settings avatar by extracting a shared unicode-aware getUserInitials util
  2. Always render markdown files (remove the source/rendered toggle and markdownViewerStore)
  3. Strip code fences from bash tool output in ExecuteToolView
  4. Use filled WarningCircle icon for error toasts instead of an X

How did you test this?

Manually

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Generated-By: PostHog Code
Task-Id: 5f514df8-a02d-42c8-bb24-e972875c458d
Generated-By: PostHog Code
Task-Id: 8b514353-44fc-4561-8075-bca46f95d645
@charlesvien charlesvien changed the title Misc fixes fix: Misc UX fixes May 18, 2026
@charlesvien charlesvien marked this pull request as ready for review May 18, 2026 05:53
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 18, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/features/auth/utils/userInitials.ts:13-22
When only `last_name` is set and `first_name` is absent, the function skips the last name entirely and falls through to email-based initials (or `"U"`). A user whose profile has `{first_name: null, last_name: "Smith"}` would get letters from their email address rather than `"S"` from their name.

```suggestion
export function getUserInitials(user: UserLike | null | undefined): string {
  const first = firstLetter(user?.first_name);
  const last = firstLetter(user?.last_name);
  if (first && last) {
    return `${first}${last}`.toUpperCase();
  }
  if (first) {
    return first.toUpperCase();
  }
  if (last) {
    return last.toUpperCase();
  }
  const emailLetters = user?.email?.match(/\p{L}/gu)?.slice(0, 2).join("");
```

Reviews (1): Last reviewed commit: "always render markdown files" | Re-trigger Greptile

Comment thread apps/code/src/renderer/features/auth/utils/userInitials.ts Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 18, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/features/auth/utils/userInitials.test.ts:4-89
The team prefers parameterised tests (`it.each`). The 14 individual `it()` calls here all drive the same function with different inputs and expected outputs — a textbook case for a table-driven test. The only case that warrants its own `it` is the astral-plane one, whose inline comment adds meaningful context. Collapsing the rest into `it.each` reduces repetition and makes it easier to add new edge cases.

```suggestion
describe("getUserInitials", () => {
  it.each([
    // first + last name
    [{ first_name: "Charles", last_name: "Vien" }, "CV"],
    [{ first_name: "alice", last_name: "smith" }, "AS"],
    // single name field
    [{ first_name: "Charles" }, "C"],
    [{ last_name: "Vien" }, "V"],
    // email fallback
    [{ email: "charles.v@posthog.com" }, "CH"],
    [{ email: "1234@example.com" }, "U"],
    [{ email: "1.2_charles@posthog.com" }, "CH"],
    // non-letter prefix in names
    [{ first_name: " 123Alice" }, "A"],
    // accented characters
    [{ first_name: "Émile", last_name: "Über" }, "ÉÜ"],
    // null / undefined / empty fallback to "U"
    [null, "U"],
    [undefined, "U"],
    [{ first_name: "", last_name: "", email: "" }, "U"],
    [{ first_name: "123" }, "U"],
    [{ first_name: "123", email: "456@example.com" }, "U"],
    [{ first_name: null, last_name: null, email: "charles.v@posthog.com" }, "CH"],
  ])("getUserInitials(%o) === %s", (input, expected) => {
    expect(getUserInitials(input as Parameters<typeof getUserInitials>[0])).toBe(expected);
  });

  it("handles astral-plane characters without producing lone surrogates", () => {
    // U+20BB7 ("𠮷") is encoded as a UTF-16 surrogate pair. The old
    // implementation used string[0], which returned only the high surrogate
    // and rendered as a garbled tofu char.
    expect(getUserInitials({ first_name: "𠮷田", last_name: "Smith" })).toBe(
      "𠮷S",
    );
  });
});
```

Reviews (2): Last reviewed commit: "address review feedback on initials and ..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default .md files to rendered preview and remember last view choice

1 participant