Skip to content

Remember most-recently-used value in foreign key autocomplete#2816

Open
youdie006 wants to merge 1 commit into
simonw:mainfrom
youdie006:feat/fk-autocomplete-remember
Open

Remember most-recently-used value in foreign key autocomplete#2816
youdie006 wants to merge 1 commit into
simonw:mainfrom
youdie006:feat/fk-autocomplete-remember

Conversation

@youdie006

Copy link
Copy Markdown

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 localStorage scoped 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.

  • Opt-in via a new remember-key attribute on the datasette-autocomplete element; behavior is unchanged when the attribute is absent.
  • Reads/writes are wrapped in try/catch, so the element degrades silently when localStorage is unavailable (private mode, full, etc.).
  • Wired up in edit-tools.js for the FK row insert/edit field, keyed per source-table + column so two FKs never collide.

Test plan

  • Added 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).
  • Existing tests/test_autocomplete.py + tests/test_debug_autocomplete.py pass (10); node --check clean on both JS files.

Fixes #2801

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

In foreign key complete always show single most recently used (remembered by localStorage) at top

1 participant