-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Auto execute saved search note #7841
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
base: main
Are you sure you want to change the base?
Changes from all commits
cc468d9
9d0b532
921b56a
6dcc3a7
9c86145
6c1886c
2c447a4
1ac241a
625c0ed
a0e1cc4
b359b48
a79c8b4
d51a0d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,7 @@ import RenameNoteBulkAction from "../bulk_actions/note/rename_note"; | |||||
| import { getErrorMessage } from "../../services/utils"; | ||||||
| import "./SearchDefinitionTab.css"; | ||||||
|
|
||||||
| export default function SearchDefinitionTab({ note, ntxId, hidden }: TabContext) { | ||||||
| export default function SearchDefinitionTab({ note, ntxId, hidden, noteContext }: TabContext) { | ||||||
| const parentComponent = useContext(ParentComponent); | ||||||
| const [ searchOptions, setSearchOptions ] = useState<{ availableOptions: SearchOption[], activeOptions: SearchOption[] }>(); | ||||||
| const [ error, setError ] = useState<{ message: string }>(); | ||||||
|
|
@@ -73,6 +73,27 @@ export default function SearchDefinitionTab({ note, ntxId, hidden }: TabContext) | |||||
| } | ||||||
| }); | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| async function autoExecute() { | ||||||
| if (!note || note.type !== "search" || !note.hasLabel("autoExecuteSearch")) { | ||||||
| executionState.save(""); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| const lastExecutedNoteId = executionState.load(); | ||||||
| if (lastExecutedNoteId !== note.noteId) { | ||||||
| executionState.save(note.noteId); | ||||||
|
|
||||||
| await refreshResults(); | ||||||
|
|
||||||
| if (noteContext?.viewScope?.viewMode === "default" && note.children.length > 0) { | ||||||
| parentComponent?.triggerCommand("toggleRibbonTabBookProperties", {}); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| autoExecute(); | ||||||
| }, [note]); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gemini-code-assist only note being changed should be a trigger to execute search. No need to trigger it more often than that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand you want the React's "rules of hooks" require all values used inside an effect (that come from the component scope) to be listed in the dependency array to ensure the effect always operates with the latest values. If you truly want the effect to only re-run when
Until |
||||||
|
|
||||||
| return ( | ||||||
| <div className="search-definition-widget"> | ||||||
| <div className="search-settings"> | ||||||
|
|
@@ -160,6 +181,14 @@ export default function SearchDefinitionTab({ note, ntxId, hidden }: TabContext) | |||||
| ) | ||||||
| } | ||||||
|
|
||||||
| const executionState = function() { | ||||||
| let lastAutoExecutedSearchNoteId = ""; | ||||||
| return { | ||||||
| load: () => lastAutoExecutedSearchNoteId, | ||||||
| save: (noteId: string) => lastAutoExecutedSearchNoteId = noteId, | ||||||
| }; | ||||||
| }(); | ||||||
|
|
||||||
| function BulkActionsList({ note }: { note: FNote }) { | ||||||
| const [ bulkActions, setBulkActions ] = useState<RenameNoteBulkAction[]>(); | ||||||
|
|
||||||
|
|
||||||
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.
Using
toggleRibbonTabBookPropertiesmight lead to unexpected behavior. If the 'Collection Properties' tab is already active, this command will likely hide it, which seems contrary to the goal of ensuring it is visible. It would be safer to use a command that explicitly shows the tab, for example one with a name likeshowRibbonTabBookProperties, if one exists. If not, you might need to check if the tab is already active before triggering the toggle command to avoid accidentally hiding it.