-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LWS-274: labels for Supersearch #1186
Conversation
I think this looks very promising! I will do a more formal review but first a quick reply regarding:
One way of achieving this is can be by modifying the $effect function which handles value changes inside SuperSearch.svelte. If we dispatch changes when the value differs from the current document state in the editor views, then changes to to URL should also be reflected in the editors. $effect(() => {
if (value) {
search.debouncedFetchData(value);
}
if (value !== collapsedEditorView?.state.doc.toString()) {
collapsedEditorView?.dispatch({
changes: {
from: 0,
to: collapsedEditorView.state.doc.length,
insert: value
}
});
expandedEditorView?.dispatch({
changes: {
from: 0,
to: expandedEditorView.state.doc.length,
insert: value
}
});
}
}); It's a little bit unfortunate that we need to dispatch the changes to both the expanded and collapsed editor in the example above, and it would also probably be preferable to use the reset function to ensure the editor state is resetted between navigations. We probably need to do some minor rewiring as |
I noticed now that the effect action in the example above ☝️ is triggered twice as the inequality check causes the effect to run again, it's therefore better to separate them by adding an additonal effect action: $effect(() => {
if (value) {
search.debouncedFetchData(value);
}
});
$effect(() => {
if (value !== collapsedEditorView?.state.doc.toString()) {
collapsedCodeMirror?.reset({
doc: value
});
expandedCodeMirror?.reset({
doc: value
});
}
}); EDIT: Another maybe more elegant solution would be just looking for changes in the URL (either using a URL prop or an effect action triggered by |
Searchparam sync without afterNavigate should in be fixed in 1276696 |
I've (hopfully) fixed this in e840722 By using an I've experimented with commenting out this line, i.e. only adding decorations (looking for labels etc) when new data is available, not on every keystroke. It should be great for performance. But to look good, instant styling of qualifiers must come from the Tag highlighter extension included in the language instead. Will work on it some more... Edit: yet another commit where I've implemented this 👆 . Let's see how it works out... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! 🙌
I think it looks really good (especially the changes where getQualifiers is now only triggered on new data)! It should help the performance quite alot 🌟
This allows the labels in #1186 to work as inteded. We need to sync what the Libris XL API needs first before we do something more.
Nice, however I'm beginning to think this does not cut it. There is a noticeable lag from the widgets when you type now. Removing a widget by backspace feels kind of buggy because of this. Maybe there's some middle ground here, updates should maybe be triggered by some input after all. Maybe this does not have to be 100% resolved at this point... |
8f8cb5a
to
c4eef3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚢
Description
Tickets involved
LWS-274
Solves
Add labels to qualifiers by passing in a callback function to the
lxlQualifierPlugin
. The function is called with any found qualifierkey
/value
pair, and should return their labels and an optional remove ('up') link. If found, a widget decoration (QualifierComponent
) will replace them and an atomic range will be created.In the lxlweb implementation (no implementation for the Supersearch demo route so far), the callback function iterates
search.mappings
of$page.data
and autosuggest fetches, suggest labels taking precedence. Page data is needed to have labels ready when page loads, suggest mappings are needed to get labels instantly when typing.As you'll notice, at this point this has quite a few limitations and bugs left to fix. I think cooperation and iteration will be the best way to proceed from here.
Summary of changes
lxlweb/Search
component/find
and/api/lang/supersearch
(needs improvement)getLabelsFromMapping
util functionlxlQualifier
plugin, now using one singleQualifierComponent
widget + additional mark decorations.Notes on the above
Syncing Codemirror with url searchParams is now done usingafterNavigate
which is a svelte/kit import and should be done differently. Suggestions are welcome. Dunno if it's even part of this PR, should be added soon anyhow...search.mapping
but rather matching a piece of the_q
string with a singleDisplayMapping
object may require further additions to the search api. I've not come up with a way to decisively match the two using today's response. Current implementation is hacky and resulting inrdf:type
not getting labels, for example.publicationYear:2001
,contributor:"Astrid"
), the value gets a special styling with no remove link and continues to be editable. One of many things we'll have to try out and discuss.bugs/limitations
Because of the nature of the current implementation + suggestion debounce, labels from suggest mapping will not magically appear when resolved, but rather when the function is called the next time. This usually means the labels appear only after typing the first letter of the value, which is not ideal.Labels can also disappear after appearing, usually because suggestion gets an empty response. Maybe we'll have to save the last successful response to avoid this.Todos
Write testsDocument Supersearch api/prop changes