Skip to content

refactor(web): drop custom utils in favor of Radashi usage.#2412

Merged
dgdavid merged 26 commits intomasterfrom
radashi
Jun 6, 2025
Merged

refactor(web): drop custom utils in favor of Radashi usage.#2412
dgdavid merged 26 commits intomasterfrom
radashi

Conversation

@dgdavid
Copy link
Copy Markdown
Contributor

@dgdavid dgdavid commented May 28, 2025

Problem

Over time, we’ve created a number of utility functions, such as isEmpty, that are already well-implemented in mature, widely-used libraries like Lodash, Ramda, or Radashi. These libraries are not only well-tested and maintained, but they also provide battle-hardened solutions to common problems, allowing us to avoid reinventing the wheel.

Some time ago, adopting Radashi was proposed and discussed in #1601, but the idea was eventually postponed.

This week, while updating and expanding our utils/isEmpty function, I noticed it was evolving into something more complex, more along the lines of isVariableConsideredEmpty, which, apart from being debatable in behavior, also strays from its original simplicity. Writing tests for this change made it even more apparent that our time and energy might be better spent focusing on Agama-specific business logic, rather than on maintaining our own versions of common utility functions.

Solution

This PR introduces Radashi as a dependency and removes our custom utility functions that are already covered by it.

Radashi offers modern, type-safe, and well-tested utility functions that align with our needs, and adopting it allows us to:

  • Reduce technical debt by eliminating redundant code
  • Rely on a maintained and community-backed solution
  • Focus our efforts on Agama-specific features and business logic

This change builds on the earlier discussion in #1601 and serves as a practical step forward in simplifying our codebase while improving long-term maintainability.

Summary of changes

As part of this PR, utils without a Radashi counterpart have been either documented, tested, and refactored (if needed), or deleted if they were no longer in use. Find below a brief summary of changes, but refer to commits to know more.

Method / utility Change Type Details
isEmpty Deleted Replaced by Radashi.isEmpty. Additionally, some previous usages of isEmpty were further refined by being replaced with Radashi.isNullish
partition Deleted Replaced by Radashi.fork
isObject Deleted Replaced with Radashi.isObject
isObjectEmpty Deleted Replaced by Radashi.isEmpty
noop Deleted Replaced with Radashi.noop
identity Deleted No longer in use
uniq Deleted Replaced by Radashi.unique
classNames Deleted Not in use from long ago
slugify Deleted Not in use
toValidationError Deleted Not in use
hex Refactored, documented, and tested -
mask Refactored, documented, and tested -
localConnection Added missing tests -
timezoneTime Added missing tests -
agamaWidthBreakpoints, getBreakpoint Extracted Moved to components/layout/Layout.tsx, the only component using them
useLocalStorage Extracted Custom React hook extracted from the general utilities section to its own file placed at hooks/
useCancellablePromise Extracted Custom React hook extracted from the general utilities section to its own file placed at hooks/
useDebounce Deleted Custom React hook replaced with the Radashi.debounce
useNodeSiblings Deleted Custom React hook not in use from long ago

Testing

  • Tested manually in development mode. Everything works as expected.

Notes for reviewers

Do not merge until #2402 is merged and later rebased. It was there where utils/isEmpty was first extended and then fixed and tested.

Related resources

https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore

dgdavid added 10 commits May 28, 2025 08:13
With the idea to write and maintain less code, documentation, and tests
for the utils it already provides.
And drop the custom utils/partition
And drop the custom utils/isObject
And use radashi/isEmpty instead, which also checks "object with no
enumerable keys"
And drop the custom utils/noop
And drop the custom utils/uniq
Since it has not been used for a while and is no longer necessary.
@coveralls
Copy link
Copy Markdown

coveralls commented May 28, 2025

Coverage Status

coverage: 62.745%. remained the same
when pulling 631515e on radashi
into c5d08e1 on master.

dgdavid added 2 commits May 31, 2025 17:46
- Return 0 when sanitized input contains non-numeric characters
- Improve documentation for clarity and completeness
- Add comprehensive unit tests covering edge cases

Note: This util has a specialized behavior and might better belong in
the storage/DASD namespace rather than as a general-purpose utility.
Replaced the RegExp-based masking (which involved pattern matching) with
a simpler implementation using native string methods wich helps reducing
complexity and improving performance.

Added comprehensive unit tests covering edge cases including negative,
zero, and NaN values for the visible parameter to ensure robustness.
Moved useCancellablePromise from utils to its own file under the hooks/
directory for better code organization.

No tests added, as this hook is likely to be removed once storage ZFCP
components are updated, similar to how it was removed from other parts
of Agama after adopting TanStack Query (see commits 688397a,
5043e96, or 78b50f2 for reference).
dgdavid added 3 commits June 2, 2025 13:37
Moved useLocalStorage from utils to its own file under the hooks/
directory for better code organization.

No tests were added, as the hook is currently used by only one
component, and its future in the codebase is uncertain. The component
may be refactored and stop relying on this hook for data persistence.
Moved useDebounce from utils to its own file under the hooks/
directory for better code organization.

No tests were added, as the hook is currently used by only one
component and it could be replaced by the "debounce" Radashi util
function.
Replaces the custom useDebounce React hook with Radashi debounce
function. This simplifies the code by removing the need for a hook while
preserving the same behavior. The radashi implementation is also
well-tested and offers additional configuration options and methods,
which might be useful in the future.
dgdavid added 5 commits June 2, 2025 15:12
The Layout component is currently the only consumer of the custom
breakpoints, so it makes little sense to keep them in a shared utils
file where they unnecessarily pollute the global namespace.

As part of the move, the breakpoints and related logic have been
properly documented for maintainability.
The `toValidationError` function is no longer in use. It was originally
introduced in the storage area implementation (#540, commit 1fc1f6f)
but its usage was gradually phased out across later changes (e.g., #1112),
until it became fully unused in commit 9cfc9c7 (part of #1972).

Removing it to reduce dead code and simplify the utils namespace.
joseivanlopez

This comment was marked as resolved.

@dgdavid

This comment was marked as outdated.

The hook has not been used since commit 726c632.
dgdavid added 3 commits June 6, 2025 09:19
This makes the Connection type work as expected by supporting boolean
values for connection options. This is related to the fact that the
removed `isEmpty` utility incorrectly supported boolean values as well.
@dgdavid dgdavid marked this pull request as ready for review June 6, 2025 13:36
Copy link
Copy Markdown
Contributor

@joseivanlopez joseivanlopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dgdavid dgdavid merged commit 28ac79a into master Jun 6, 2025
7 checks passed
@dgdavid dgdavid deleted the radashi branch June 6, 2025 14:58
@imobachgs imobachgs mentioned this pull request Jun 30, 2025
imobachgs added a commit that referenced this pull request Jun 30, 2025
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.

3 participants