mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Clean up type validation
This commit is contained in:
parent
912f257a68
commit
018815cf9d
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -40,6 +40,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bootstrap": "5.2.10",
|
"@types/bootstrap": "5.2.10",
|
||||||
"@types/cookie": "^0.5.1",
|
"@types/cookie": "^0.5.1",
|
||||||
|
"@types/node": "^20.11.16",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.39.0",
|
"@typescript-eslint/eslint-plugin": "^5.39.0",
|
||||||
"@typescript-eslint/parser": "^5.39.0",
|
"@typescript-eslint/parser": "^5.39.0",
|
||||||
"esbuild": "^0.13.15",
|
"esbuild": "^0.13.15",
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
|
import { TomOption } from 'tom-select/src/types';
|
||||||
|
import { escape_html } from 'tom-select/src/utils';
|
||||||
|
import { DynamicTomSelect } from './classes/dynamicTomSelect';
|
||||||
import { getElements } from '../util';
|
import { getElements } from '../util';
|
||||||
import { DynamicTomSelect } from './classes/dynamicTomSelect'
|
|
||||||
|
|
||||||
const VALUE_FIELD = 'id';
|
const VALUE_FIELD = 'id';
|
||||||
const LABEL_FIELD = 'display';
|
const LABEL_FIELD = 'display';
|
||||||
const MAX_OPTIONS = 100;
|
const MAX_OPTIONS = 100;
|
||||||
|
|
||||||
|
|
||||||
// Render the HTML for a dropdown option
|
// Render the HTML for a dropdown option
|
||||||
function renderOption(data: any, escape: Function) {
|
function renderOption(data: TomOption, escape: typeof escape_html) {
|
||||||
|
|
||||||
// If the option has a `_depth` property, indent its label
|
// If the option has a `_depth` property, indent its label
|
||||||
if (typeof data._depth === 'number' && data._depth > 0) {
|
if (typeof data._depth === 'number' && data._depth > 0) {
|
||||||
return `<div>${'─'.repeat(data._depth)} ${escape(data[LABEL_FIELD])}</div>`;
|
return `<div>${'─'.repeat(data._depth)} ${escape(data[LABEL_FIELD])}</div>`;
|
||||||
@ -17,10 +17,8 @@ function renderOption(data: any, escape: Function) {
|
|||||||
return `<div>${escape(data[LABEL_FIELD])}</div>`;
|
return `<div>${escape(data[LABEL_FIELD])}</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize <select> elements which are populated via a REST API call
|
// Initialize <select> elements which are populated via a REST API call
|
||||||
export function initDynamicSelects(): void {
|
export function initDynamicSelects(): void {
|
||||||
|
|
||||||
for (const select of getElements<HTMLSelectElement>('select.api-select')) {
|
for (const select of getElements<HTMLSelectElement>('select.api-select')) {
|
||||||
new DynamicTomSelect(select, {
|
new DynamicTomSelect(select, {
|
||||||
valueField: VALUE_FIELD,
|
valueField: VALUE_FIELD,
|
||||||
@ -42,12 +40,13 @@ export function initDynamicSelects(): void {
|
|||||||
|
|
||||||
// Define custom rendering functions
|
// Define custom rendering functions
|
||||||
render: {
|
render: {
|
||||||
option: renderOption
|
option: renderOption,
|
||||||
},
|
},
|
||||||
|
|
||||||
// By default, load() will be called only if query.length > 0
|
// By default, load() will be called only if query.length > 0
|
||||||
shouldLoad: function(): boolean { return true; }
|
shouldLoad: function (): boolean {
|
||||||
});
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { initColorSelects, initStaticSelects } from './static';
|
import { initColorSelects, initStaticSelects } from './static';
|
||||||
import { initDynamicSelects } from './dynamic';
|
import { initDynamicSelects } from './dynamic';
|
||||||
|
|
||||||
|
|
||||||
export function initSelects(): void {
|
export function initSelects(): void {
|
||||||
initStaticSelects();
|
initStaticSelects();
|
||||||
initDynamicSelects();
|
initDynamicSelects();
|
||||||
|
@ -1,30 +1,28 @@
|
|||||||
import { getElements } from '../util';
|
|
||||||
import { TomOption } from 'tom-select/src/types';
|
import { TomOption } from 'tom-select/src/types';
|
||||||
import TomSelect from 'tom-select';
|
import TomSelect from 'tom-select';
|
||||||
|
import { escape_html } from 'tom-select/src/utils';
|
||||||
|
import { getElements } from '../util';
|
||||||
|
|
||||||
// Initialize <select> elements with statically-defined options
|
// Initialize <select> elements with statically-defined options
|
||||||
export function initStaticSelects(): void {
|
export function initStaticSelects(): void {
|
||||||
|
for (const select of getElements<HTMLSelectElement>(
|
||||||
for (const select of getElements<HTMLSelectElement>('select:not(.api-select):not(.color-select)')) {
|
'select:not(.api-select):not(.color-select)',
|
||||||
|
)) {
|
||||||
new TomSelect(select, {
|
new TomSelect(select, {
|
||||||
plugins: ['clear_button']
|
plugins: ['clear_button'],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize color selection fields
|
// Initialize color selection fields
|
||||||
export function initColorSelects(): void {
|
export function initColorSelects(): void {
|
||||||
|
|
||||||
for (const select of getElements<HTMLSelectElement>('select.color-select')) {
|
for (const select of getElements<HTMLSelectElement>('select.color-select')) {
|
||||||
new TomSelect(select, {
|
new TomSelect(select, {
|
||||||
render: {
|
render: {
|
||||||
option: function(item: TomOption, escape: Function) {
|
option: function (item: TomOption, escape: typeof escape_html) {
|
||||||
return `<div style="background-color: #${escape(item.value)}">${escape(item.text)}</div>`;
|
return `<div style="background-color: #${escape(item.value)}">${escape(item.text)}</div>`;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": false,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
|
@ -150,6 +150,13 @@
|
|||||||
resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz"
|
resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz"
|
||||||
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
|
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
|
||||||
|
|
||||||
|
"@types/node@^20.11.16":
|
||||||
|
version "20.11.16"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.16.tgz#4411f79411514eb8e2926f036c86c9f0e4ec6708"
|
||||||
|
integrity sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==
|
||||||
|
dependencies:
|
||||||
|
undici-types "~5.26.4"
|
||||||
|
|
||||||
"@typescript-eslint/eslint-plugin@^5.39.0":
|
"@typescript-eslint/eslint-plugin@^5.39.0":
|
||||||
version "5.39.0"
|
version "5.39.0"
|
||||||
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.39.0.tgz"
|
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.39.0.tgz"
|
||||||
@ -2233,6 +2240,11 @@ unbox-primitive@^1.0.2:
|
|||||||
has-symbols "^1.0.3"
|
has-symbols "^1.0.3"
|
||||||
which-boxed-primitive "^1.0.2"
|
which-boxed-primitive "^1.0.2"
|
||||||
|
|
||||||
|
undici-types@~5.26.4:
|
||||||
|
version "5.26.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
|
||||||
|
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
|
||||||
|
|
||||||
uri-js@^4.2.2:
|
uri-js@^4.2.2:
|
||||||
version "4.4.1"
|
version "4.4.1"
|
||||||
resolved "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz"
|
resolved "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz"
|
||||||
|
Loading…
Reference in New Issue
Block a user