Skip to content

Fix/shared components data loading - #331

Closed
IamKirbki wants to merge 9 commits into
mainfrom
fix/shared-components-data-loading
Closed

IamKirbki wants to merge 9 commits into
mainfrom
fix/shared-components-data-loading

Conversation

@IamKirbki

Copy link
Copy Markdown
Contributor

Why

Components used across the console hid failures:

  • False successes:
    • creating a scheduled item could show success when the server refused it
    • deleting a sender address, and uploading or deleting media, failed silently
  • Failed loads showed an endless skeleton or "nothing here".
  • The sender picker showed "no sender" while still loading or after a failure, even though the form had one selected.
  • The sidebar's project and workspace lists never refreshed after a rename.

Changes

Infrastructure (backwards compatible; no caller has to change):

  • useResolver (hooks.ts):
    • Ignores responses from superseded calls, so a slow older request can no longer overwrite a newer one.
    • Sets nothing after unmount.
    • Returns the error as a new fifth tuple element.
  • InlineEdit and DateTimeEdit: a failing onSave is caught, and the editor stays open with the user's value instead of throwing an unhandled rejection.
  • SearchTable:
    • New optional isLoading, isError and onRetry props, with an error row and Retry.
    • A new search resets the page cursor.
    • Note: nothing in the console currently renders SearchTable.

Components moved to TanStack Query, with an error and Retry instead of an endless skeleton:

  • Scheduled detail table:
    • Create, delete, pause, resume and reschedule are mutations.
    • A rejected create keeps the dialog and the user's input, with no success toast.
    • A failed load of schedule names is shown instead of raw ids.
  • Inbox detail table:
    • The list is a query keyed by page, search and status.
    • A refused reschedule keeps the date editor open.
  • Sender identities (list and picker):
    • Shared queries under ["projects", id, "sender-identities", …].
    • A failed delete keeps the confirmation open.
    • The picker shows "Loading…" or a load error for the selected sender instead of the placeholder.
  • Providers list: loads every page (shared key ["projects", id, "providers", "list"], also used by the settings PR), so whichever page loads first can't cap the cached list at 20.
  • Media manager: upload and delete failures are reported, and a failed load is shown instead of "no images".
  • Action preview: keyed by action type, so a quick switch can't show the wrong preview.
  • Sidebar: project and workspace lists use ["projects", "list"] and ["organizations", "list"], so other pages can refresh them after a rename.
  • Message rows: the sender identity comes from the cache instead of being refetched on every expand.
  • User import dialog: shows a failed import inline and stays open.

Cleanup:

  • provider/select.tsx deleted (unused).
  • The inbox table (1,116 → 327 lines), scheduled table (937 → 453) and sender picker (638 → 321) are split into components/inbox/, components/scheduled/ and components/sender-identity/.

Testing

New tests, each failing against the old code unless marked:

File What it checks
hooks.test.ts stale responses are ignored; the error is exposed and cleared on a successful reload
search-table.test.tsx a new search starts from the first page; an error row with Retry
scheduled-detail-table.test.tsx a rejected create keeps the dialog; failed list and schedule-name loads
ui/inline-edit.test.tsx a failed save no longer causes an unhandled rejection
sender-identity/sender-identity.test.tsx 4 of its 5 tests
media-manager/MediaManager.test.tsx all three tests
inbox-detail-table.test.tsx —
ui/user-import-dialog.test.tsx —
action-preview-iframe.test.tsx —

All 113 console tests pass. vite build succeeds, with no new type errors.

Manual check:

  1. Open a campaign's sender picker, then Settings → Integrations. It should list every provider, not just 20.
  2. Rename the project. The sidebar's project switcher should show the new name.

Notes

  • search-table.tsx (426 lines) and scheduled-detail-table.tsx (453) are slightly over the 400-line target.
  • No test for the sidebar switchers.

Depends-On: #329

Shared setup for moving console pages from fetch-in-effect to TanStack
Query, so each area can migrate on its own branch:

- one QueryClient for the app, provided in App.tsx; failed mutations
  are shown in a toast by the mutation cache, so no save fails silently
- unwrap() turns an openapi-fetch { error } into a thrown ApiError,
  since openapi-fetch never throws on HTTP errors; problemDetail reads it
- useProjectLocales / projectLocalesQuery: the project's locales as one
  cached query with the API's maximum page size
…s error

useResolver committed whichever request settled last and only logged
failures, so a slow response for old params could overwrite newer data
and callers could not tell a failed load from a pending one. Only the
latest call now commits, and the error is a new last tuple element.

SearchTable gains optional isLoading/isError/onRetry props so a failed
load can show an error row with Retry instead of an endless skeleton,
and a new search drops the cursor so it starts from the first page.
openapi-fetch returns a rejected PUT instead of throwing, so creating a
scheduled item the server refused showed the success toast, closed the
dialog and reset the form. The create is now a mutation over unwrap that
keeps the dialog and input on failure.

The list and schedule schemas load through queries keyed by page and
search, so a stale response can't win, and a failed load shows an error
with Retry instead of an endless skeleton or raw ids. The file is split
into queries, the create dialog, the action dialogs and the expanded row.
InlineEdit and DateTimeEdit awaited onSave without a catch, so a failed
save became an unhandled rejection. They now keep the editor open with
the user's value; callers still report the error themselves.
Removing a sender address ignored the openapi-fetch error, so a refused
DELETE closed the confirmation and left the row without a word; it is
now a mutation that reports the failure and keeps the confirmation.

The integration list, the sender picker and the inbox rows share
queries under ["projects", id, "sender-identities"], so a change in one
place shows everywhere and expanding a row no longer refetches the
sender. Failed loads show an error with Retry instead of an endless
skeleton or "no addresses", and the picker says the selected sender is
loading or failed to load instead of showing the placeholder.
The media manager swallowed upload and delete errors and showed "no
images" when the list failed to load. Uploads and deletes are now
mutations whose failures are reported, the list is a query that shows
an error with Retry, and both refresh the list on success.
A failed inbox load left the table on its skeleton forever, and the
debounced search and status/page changes had no guard against a slower,
older response. The list is now a query keyed by page, search and
status, with an error row and Retry.

Creating and updating messages are mutations, so refused requests are
reported with the server's detail. A refused reschedule now keeps the
date editor open instead of closing it as if it saved. The file is split
into queries, the row and the create dialog.
…ion preview

- The sidebar loads the project and organization lists through queries
  keyed ["projects", "list"] and ["organizations", "list"], so pages
  that create or rename one can invalidate them and the switcher shows
  the change. A failed load offers a retry in the switcher instead of
  silently listing nothing.
- The user import dialog shows a failed import instead of leaving an
  unhandled rejection, unless the mutation cache already reported it.
- The action preview loads through a query keyed by action type, so a
  quick switch can't show the wrong preview, and a failed load says so
  with Retry instead of the preview silently disappearing.
- Remove provider/select.tsx, which nothing imports.
The sender picker's providers query shares its key with the settings
pages' providers list. It fetched only the API's default first page, so
whichever page loaded first decided how many providers the other saw:
after opening the picker, Integrations could show at most 20. Page
through all providers, as the settings query does.
@IamKirbki IamKirbki closed this Oct 30, 2026
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