-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d191c85
commit 8dcbca0
Showing
8 changed files
with
106 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { ISettingRegistry } from '@jupyterlab/settingregistry'; | ||
import React, { useState } from 'react'; | ||
import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; | ||
|
||
const AVAILABLE_PROVIDERS = 'availableProviders'; | ||
|
||
export const renderAvailableProviders = (props: any): 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: { [key: string]: number } = { ...schema.default }; | ||
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 ( | ||
<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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ | |
}, | ||
{ | ||
"path": "../settingregistry" | ||
}, | ||
{ | ||
"path": "../ui-components" | ||
} | ||
] | ||
} |
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