Skip to content

Commit

Permalink
Update setting UI
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Feb 4, 2022
1 parent d191c85 commit 8dcbca0
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 23 deletions.
5 changes: 4 additions & 1 deletion packages/completer-extension/package.json
Expand Up @@ -39,7 +39,10 @@
"dependencies": {
"@jupyterlab/application": "^4.0.0-alpha.4",
"@jupyterlab/completer": "^4.0.0-alpha.4",
"@jupyterlab/settingregistry": "^4.0.0-alpha.4"
"@jupyterlab/settingregistry": "^4.0.0-alpha.4",
"@jupyterlab/ui-components": "^4.0.0-alpha.19",
"@lumino/coreutils": "^1.12.0",
"react": "^17.0.1"
},
"devDependencies": {
"rimraf": "~3.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/completer-extension/schema/tracker.json
Expand Up @@ -26,14 +26,14 @@
"default": 1000
},
"showDocumentPanel": {
"title": "Show or hide the document panel.",
"description": "Flag to show or hide the document panel of completer widget, this configuration is applied to all providers. If a provider does not provide the documentation response, the panel will be hidden for this provider.",
"title": "Show the document panel.",
"description": "Show or hide the document panel of completer widget, this configuration is applied to all providers. If a provider does not provide the document content, the panel will be hidden for this provider.",
"type": "boolean",
"default": true
},
"continuousHinting": {
"title": "Continuous hinting.",
"description": "Flag to enable or disable continuous hinting.",
"title": "Enable continuous hinting.",
"description": "Continuous hinting setting.",
"type": "boolean",
"default": false
}
Expand Down
12 changes: 11 additions & 1 deletion packages/completer-extension/src/index.ts
Expand Up @@ -17,6 +17,8 @@ import {
KernelCompleterProvider
} from '@jupyterlab/completer';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { IFormComponentRegistry } from '@jupyterlab/ui-components';
import { renderAvailableProviders } from './renderer';

const COMPLETION_MANAGER_PLUGIN = '@jupyterlab/completer-extension:tracker';

Expand All @@ -36,11 +38,13 @@ const defaultProvider: JupyterFrontEndPlugin<void> = {
const manager: JupyterFrontEndPlugin<ICompletionProviderManager> = {
id: COMPLETION_MANAGER_PLUGIN,
requires: [ISettingRegistry],
optional: [IFormComponentRegistry],
provides: ICompletionProviderManager,
autoStart: true,
activate: (
app: JupyterFrontEnd,
settings: ISettingRegistry
settings: ISettingRegistry,
editorRegistry: IFormComponentRegistry | null
): ICompletionProviderManager => {
const AVAILABLE_PROVIDERS = 'availableProviders';
const PROVIDER_TIMEOUT = 'providerTimeout';
Expand Down Expand Up @@ -88,6 +92,12 @@ const manager: JupyterFrontEndPlugin<ICompletionProviderManager> = {
});
});

if (editorRegistry) {
editorRegistry.addRenderer('availableProviders', (props: any) => {
return renderAvailableProviders(props);
});
}

const addKeyBinding = (command: string, selector: string): void => {
app.commands.addKeyBinding({
command,
Expand Down
67 changes: 67 additions & 0 deletions packages/completer-extension/src/renderer.tsx
@@ -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>
);
};
1 change: 1 addition & 0 deletions packages/completer-extension/style/index.css
Expand Up @@ -4,5 +4,6 @@
|----------------------------------------------------------------------------*/

/* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
@import url('~@jupyterlab/ui-components/style/index.css');
@import url('~@jupyterlab/application/style/index.css');
@import url('~@jupyterlab/completer/style/index.css');
1 change: 1 addition & 0 deletions packages/completer-extension/style/index.js
Expand Up @@ -4,5 +4,6 @@
|----------------------------------------------------------------------------*/

/* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
import '@jupyterlab/ui-components/style/index.js';
import '@jupyterlab/application/style/index.js';
import '@jupyterlab/completer/style/index.js';
3 changes: 3 additions & 0 deletions packages/completer-extension/tsconfig.json
Expand Up @@ -14,6 +14,9 @@
},
{
"path": "../settingregistry"
},
{
"path": "../ui-components"
}
]
}
32 changes: 15 additions & 17 deletions yarn.lock
Expand Up @@ -4508,10 +4508,10 @@ colord@^2.9.2:
resolved "https://registry.yarnpkg.com/colord/-/colord-2.9.2.tgz#25e2bacbbaa65991422c07ea209e2089428effb1"
integrity sha512-Uqbg+J445nc1TKn4FoDPS6ZZqAvEDnwrH42yo8B40JSOgSLxMZ/gt3h4nmCtPLQeXhjJJkqBx7SCY35WnIixaQ==

colorette@^1.2.1, colorette@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.2.tgz#cbcc79d5e99caea2dbf10eb3a26fd8b3e6acfa94"
integrity sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==
colorette@^2.0.14, colorette@^2.0.16:
version "2.0.16"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da"
integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==

colors@1.4.0:
version "1.4.0"
Expand Down Expand Up @@ -5190,8 +5190,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
dependencies:
ms "2.0.0"


debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3:
debug@4, debug@4.3.3, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.1, debug@^4.3.3:
version "4.3.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
Expand Down Expand Up @@ -6814,8 +6813,7 @@ globby@10.0.0:
merge2 "^1.2.3"
slash "^3.0.0"


globby@^11.0.1, globby@^11.0.2, globby@^11.1.0:
globby@^11.0.1, globby@^11.0.2, globby@^11.0.3, globby@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
Expand Down Expand Up @@ -7280,13 +7278,11 @@ ignore@^4.0.6:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==


ignore@^5.1.1, ignore@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==


image-ssim@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/image-ssim/-/image-ssim-0.2.0.tgz#83b42c7a2e6e4b85505477fe6917f5dbc56420e5"
Expand Down Expand Up @@ -7356,8 +7352,7 @@ inherits@2.0.3:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=


ini@1.3.7, ini@^1.3.2, ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
ini@1.3.7, ini@^1.3.5:
version "1.3.7"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.7.tgz#a09363e1911972ea16d7a8851005d84cf09a9a84"
integrity sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==
Expand Down Expand Up @@ -9719,7 +9714,7 @@ nan@^2.15.0:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.15.0.tgz#3f34a473ff18e15c1b5626b62903b5ad6e665fee"
integrity sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==

nanoid@^3.1.23, nanoid@^3.2.0:
nanoid@^3.1.23, nanoid@^3.1.30:
version "3.2.0"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.2.0.tgz#62667522da6673971cca916a6d3eff3f415ff80c"
integrity sha512-fmsZYa9lpn69Ad5eDn7FMcnnSR+8R34W9qJEijxYhTbfOWzr22n1QxCMzXLK+ODyW2973V3Fux959iQoUxzUIA==
Expand Down Expand Up @@ -10786,7 +10781,6 @@ postcss-selector-parser@^6.0.2, postcss-selector-parser@^6.0.4, postcss-selector
cssesc "^3.0.0"
util-deprecate "^1.0.2"


postcss-value-parser@^4.1.0, postcss-value-parser@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
Expand All @@ -10797,7 +10791,7 @@ postcss@^8.2.15, postcss@^8.3.11, postcss@^8.4.5:
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.5.tgz#bae665764dfd4c6fcc24dc0fdf7e7aa00cc77f95"
integrity sha512-jBDboWM8qpaqwkMwItqTQTiFikhs/67OYVvblFFTM7MrZjt6yMKd6r2kgXizEbTTljacm4NldIlZnhbjr84QYg==
dependencies:
nanoid "^3.2.0"
nanoid "^3.1.30"
picocolors "^1.0.0"
source-map-js "^1.0.1"

Expand Down Expand Up @@ -12334,7 +12328,6 @@ string-width@^1.0.1:
is-fullwidth-code-point "^1.0.0"
strip-ansi "^3.0.0"


"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
Expand Down Expand Up @@ -12585,6 +12578,11 @@ supports-hyperlinks@^2.0.0, supports-hyperlinks@^2.2.0:
has-flag "^4.0.0"
supports-color "^7.0.0"

supports-preserve-symlinks-flag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

svg-tags@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/svg-tags/-/svg-tags-1.0.0.tgz#58f71cee3bd519b59d4b2a843b6c7de64ac04764"
Expand Down Expand Up @@ -13381,7 +13379,7 @@ uuid@^8.3.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

v8-compile-cache@^2.0.3, v8-compile-cache@^2.2.0, v8-compile-cache@^2.3.0:
v8-compile-cache@^2.0.3, v8-compile-cache@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==
Expand Down

0 comments on commit 8dcbca0

Please sign in to comment.