forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update completer part 2 (jupyterlab#11969)
* Refactor `completer` and `completer-extension` package * Apply suggestions * Update completer - part 2 * Update setting UI * Apply reviewer's suggestions * Improve wording.
- Loading branch information
1 parent
8a5eb9d
commit 6cda4ff
Showing
46 changed files
with
1,169 additions
and
433 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 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,75 @@ | ||
import { ISettingRegistry } from '@jupyterlab/settingregistry'; | ||
import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; | ||
import { FieldProps } from '@rjsf/core'; | ||
import React, { useState } from 'react'; | ||
|
||
const AVAILABLE_PROVIDERS = 'availableProviders'; | ||
|
||
/** | ||
* Custom setting renderer for provider rank. | ||
*/ | ||
export function renderAvailableProviders(props: FieldProps): JSX.Element { | ||
const { schema } = props; | ||
const title = schema.title; | ||
const desc = schema.description; | ||
const settings: ISettingRegistry.ISettings = props.formContext.settings; | ||
const userData = settings.get(AVAILABLE_PROVIDERS).user as | ||
| ReadonlyPartialJSONObject | ||
| undefined; | ||
|
||
const items = { | ||
...(schema.default as { [key: string]: number }) | ||
}; | ||
if (userData) { | ||
for (const key of Object.keys(items)) { | ||
if (key in userData) { | ||
items[key] = userData[key] as number; | ||
} else { | ||
items[key] = -1; | ||
} | ||
} | ||
} | ||
|
||
const [settingValue, setValue] = useState(items); | ||
const onSettingChange = ( | ||
key: string, | ||
e: React.ChangeEvent<HTMLInputElement> | ||
) => { | ||
const newValue = { | ||
...settingValue, | ||
[key]: parseInt(e.target.value) | ||
}; | ||
|
||
settings.set(AVAILABLE_PROVIDERS, newValue); | ||
|
||
setValue(newValue); | ||
}; | ||
return ( | ||
//TODO Remove hard coded class names | ||
<div> | ||
<fieldset> | ||
<legend>{title}</legend> | ||
<p className="field-description">{desc}</p> | ||
{Object.keys(items).map(key => { | ||
return ( | ||
<div key={key} className="form-group small-field"> | ||
<div> | ||
<h3> {key}</h3> | ||
<div className="inputFieldWrapper"> | ||
<input | ||
className="form-control" | ||
type="number" | ||
value={settingValue[key]} | ||
onChange={e => { | ||
onSettingChange(key, e); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</fieldset> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.