Skip to content

packages/ui-components/src/lib/utils is a junk drawer — split into named directories #2823

Description

@thedavidmeister

packages/ui-components/src/lib/utils is a junk drawer sitting among siblings that are all named for what they contain.

The odd one out

packages/ui-components/src/lib is otherwise well organised:

components/  errors/  hooks/  models/  providers/  queries/
services/    storesGeneric/  types/   assets/  test/
app.css      consts.ts       index.ts
utils/                                  <- names nothing

Every other directory answers "what is in here?". utils/ answers "things". A reader looking for the network-name helper has no reason to look there rather than in services/ or models/, and a contributor adding a new helper has no signal about where it belongs — so it lands in utils/, which is how the drawer grows.

What is actually in it

12 files that cluster cleanly into real homes:

file belongs with
codeMirrorThemes.ts, lightweightChartsThemes.ts themes — two files that are the same kind of thing and should sit together
number.ts, hex.ts, stripTrailingWhitespace.ts formatting
tokens.ts, getNetworkName.ts, vaultBalanceChangeLabels.ts, localDbStatus.ts domain — these know about raindex concepts, not general utility
breadcrumbs.ts, constructHashLink.ts navigation
configHelpers.ts config

The domain row is the strongest signal that this isn't a naming quibble: vaultBalanceChangeLabels.ts and localDbStatus.ts encode product concepts, and filing them under "utils" hides them from anyone reading the tree for domain logic.

Proposed fix

Replace utils/ with directories named for their contents — themes/, format/, navigation/, and domain files moved next to the concepts they describe (models/ or services/ as fits each). Keep index.ts re-exporting the same public surface so consumers outside the package do not have to change in the same PR.

Deleting the utils/ directory outright is the check that the job is finished; leaving a two-file remainder recreates the problem at a smaller size.

Migration cost

Modest. Indicative importer counts from GitHub code search — getNetworkName 9, lightweightChartsThemes 4, breadcrumbs 3, hex 3, number 3, stripTrailingWhitespace 3, codeMirrorThemes 2, localDbStatus 2, constructHashLink 1. Treat these as a floor rather than a census: the search hit a rate limit before covering tokens, vaultBalanceChangeLabels and configHelpers, so those three are unmeasured. Re-run the counts locally before planning the move.

Explicitly out of scope

crates/common/src/utils and crates/subgraph/src/utils are also named utils, but they each have a mod.rs and cohesive, well-named members (float.rs, serde.rs, timestamp.rs, timing.rs, amount_formatter.rs, order_id.rs, slice_list.rs). They are not the same problem and are not part of this.

Separate observation, not part of this either: float.rs exists in both those crates' utils directories. Whether that is genuine duplication or two unrelated things sharing a name is worth its own look.

History

This is the live successor to #958 ("don't have utils folder in tauri-app/src/lib/utils", 2024-10-23). That path went away with the tauri app, but the folder moved rather than being cleaned up — tauri-app/src/lib/utilspackages/ui-components/src/lib/utils is the same <package>/src/lib/utils shape at the same depth. #958 is closed in favour of this, which names the files that actually exist.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions