Remember most-recently-used value in foreign key autocomplete#2816
Remember most-recently-used value in foreign key autocomplete#2816youdie006 wants to merge 1 commit into
Conversation
Persist the selected FK value to localStorage scoped per db/table/column, and show it as the single de-duped top suggestion on the next focus. Opt-in via a remember-key attribute; degrades silently without localStorage.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5806a9f676
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }); | ||
| var rememberedRow = { | ||
| pks: { value: remembered.value }, | ||
| label: remembered.label, |
There was a problem hiding this comment.
Prefer fetched rows for remembered matches
When the remembered PK is also present in the current _initial response, the filter above removes the fresh server row and this cached remembered.label is rendered instead. If the referenced row's label changed since it was last selected, the autocomplete will now show the stale localStorage label and hide the up-to-date result; promote the fetched row when it exists, and only fall back to the cached row when it was not returned.
Useful? React with 👍 / 👎.
Summary
Implements #2801 — the foreign-key autocomplete now remembers the most-recently-used value and surfaces it as the single top suggestion.
When a value is chosen in a FK autocomplete, it is persisted to
localStoragescoped per database/table/column (datasette-autocomplete:<db>/<table>/<column>). On the next focus with an empty query, that remembered value is shown as the top option and de-duped from the fetched rows so it is not listed twice.remember-keyattribute on thedatasette-autocompleteelement; behavior is unchanged when the attribute is absent.edit-tools.jsfor the FK row insert/edit field, keyed per source-table + column so two FKs never collide.Test plan
tests/test_playwright.py::test_autocomplete_remembers_most_recently_used_value(mocks/-/autocomplete, asserts the remembered value is written on select and shown as the de-duped top option on re-focus).tests/test_autocomplete.py+tests/test_debug_autocomplete.pypass (10);node --checkclean on both JS files.Fixes #2801