-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend bar, debouncer, task cancellation (#30)
* frontend bar, debouncer, task cancellation * adhere to lint * add updated yarn.lock * adhere to eslint * Change import order Co-authored-by: Frédéric Collonval <[email protected]> * add docs for task tracking and cancellation Co-authored-by: Frédéric Collonval <[email protected]> * check if task is done before cancellation Co-authored-by: Frédéric Collonval <[email protected]> * re-order import for handler Co-authored-by: Frédéric Collonval <[email protected]> * access task underneath Co-authored-by: Frédéric Collonval <[email protected]>
- Loading branch information
1 parent
36d28b4
commit aabc6ef
Showing
7 changed files
with
248 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import { Debouncer } from '@lumino/polling'; | ||
import { requestAPI } from './handler'; | ||
import { VDomModel, VDomRenderer } from '@jupyterlab/apputils'; | ||
import { Search } from '@jupyter-notebook/react-components'; | ||
|
||
export class SearchReplaceModel extends VDomModel { | ||
constructor() { | ||
super(); | ||
this._searchString = ''; | ||
this._debouncedStartSearch = new Debouncer(() => { | ||
this.getSearchString(this._searchString); | ||
}); | ||
} | ||
|
||
get searchString(): string { | ||
return this._searchString; | ||
} | ||
|
||
set searchString(v: string) { | ||
if (v !== this._searchString) { | ||
this._searchString = v; | ||
this.stateChanged.emit(); | ||
this._debouncedStartSearch | ||
.invoke() | ||
.catch(reason => | ||
console.error(`failed query for ${v} due to ${reason}`) | ||
); | ||
} | ||
} | ||
|
||
get queryResults(): string { | ||
return this._queryResults; | ||
} | ||
|
||
async getSearchString(search: string): Promise<void> { | ||
try { | ||
const data = await requestAPI<any>( | ||
'?' + new URLSearchParams([['query', search]]).toString(), | ||
{ | ||
method: 'GET' | ||
} | ||
); | ||
this._queryResults = data; | ||
this.stateChanged.emit(); | ||
console.log(data); | ||
} catch (reason) { | ||
console.error( | ||
`The jupyterlab_search_replace server extension appears to be missing.\n${reason}` | ||
); | ||
} | ||
} | ||
|
||
private _searchString: string; | ||
private _queryResults: any; | ||
private _debouncedStartSearch: Debouncer; | ||
} | ||
|
||
//TODO: fix css issue with buttons | ||
export class SearchReplaceView extends VDomRenderer<SearchReplaceModel> { | ||
constructor(searchModel: SearchReplaceModel) { | ||
super(searchModel); | ||
this.addClass('jp-search-replace-tab'); | ||
} | ||
|
||
render(): JSX.Element | null { | ||
return ( | ||
<> | ||
<Search | ||
appearance="outline" | ||
placeholder="<pre>{matches}</pre>" | ||
label="Search" | ||
onInput={(event: any) => | ||
(this.model.searchString = event.target.value) | ||
} | ||
/> | ||
<pre>{JSON.stringify(this.model.queryResults, undefined, 4)}</pre> | ||
</> | ||
); | ||
} | ||
} |
Oops, something went wrong.