Skip to content

refactor: dedup TranslateFn helpers and controllable-open into @multica/core - #4

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783494964-dedup-translate-utils
Open

refactor: dedup TranslateFn helpers and controllable-open into @multica/core#4
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783494964-dedup-translate-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

jscpd flagged two patterns duplicated across the views package. Both are extracted into @multica/core and adopted at every call site — no behavior change.

1. The t translate-prop pattern (~27 files). Each view component redeclared the same type and fallback logic:

type TranslateFn = (key: string, fallback: string) => string;   // declared in 25+ files
const defaultT = (_key, fallback) => fallback;                  // in 12+ files
const translate = t || defaultT;                                // in 12+ files

Now provided once in packages/core/hooks/useTranslation.ts:

export type TranslateFn = (key: string, fallback: string) => string;
export const fallbackT: TranslateFn = (_key, fallback) => fallback;
export function withT(t?: TranslateFn): TranslateFn { return t ?? fallbackT; }

Call sites collapse to import { withT, fallbackT, type TranslateFn } from "@multica/core" and either const translate = withT(t) or a t = fallbackT default param.

2. Controlled/uncontrolled open state (3 pickers). assignee/priority/status pickers each had:

const [internalOpen, setInternalOpen] = useState(false);
const open = controlledOpen ?? internalOpen;
const setOpen = controlledOnOpenChange ?? setInternalOpen;

Replaced by a new useControllableOpen(controlledOpen, controlledOnOpenChange) hook in packages/core/hooks/use-controllable-open.ts returning [open, setOpen].

Notes

  • useControllableOpen, withT, fallbackT and the TranslateFn type are re-exported from the @multica/core barrel.
  • issues-page.test.tsx's @multica/core mock gains the new exports (withT, fallbackT, useControllableOpen) since the components under test now consume them.
  • Verified: pnpm typecheck clean on changed files, pnpm test for core passes, views test suite unchanged vs. base (the 7 issue-detail.test failures — api.getIssueWorkdirFiles is not a function — and the captcha typecheck/lint errors are pre-existing on main).

Link to Devin session: https://app.devin.ai/sessions/036672cd408042b191cb2beeb5405f75
Requested by: @killerleon94

…into @multica/core

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@killerleon94 killerleon94 self-assigned this Jul 8, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

1 participant