β¬ οΈ Back to Table of Contents
π ConfigEditor¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 4 |
| π¦ Imports | 9 |
| π JSX Elements | 14 |
| π Interfaces | 4 |
| π Type Aliases | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/website/src/components/config/ConfigEditor.tsx
π¦ Imports¶
| Name | Source |
|---|---|
clsx |
clsx |
useCallback |
react |
useMemo |
react |
useState |
react |
React |
react |
Checkbox |
../inputs/Checkbox |
Dropdown |
../inputs/Dropdown |
Text |
../inputs/Text |
styles |
./ConfigEditor.module.css |
JSX Elements¶
| Component | Type | Props | Children |
|---|---|---|---|
label |
element | className={styles.searchResult} | , {item.type === 'boolean' ? ( <Checkbox checked={Boolean(value)} indet... |
span |
element | className={styles.searchResultDescription} | , {item.label && }, {item.label && {item.label}} |
span |
element | className={styles.searchResultName} | {item.key} |
br |
element | none | none |
span |
element | none | {item.label} |
Checkbox |
component | checked={Boolean(value)}, indeterminate={Boolean(value) && !isDefault(value, ... | none |
Dropdown |
component | name={config_${item.key}}, onChange={(value): void => onChange(item.key, va... |
none |
div |
element | className={clsx( 'thin-scrollbar', styles.searchResultContainer, className, )} | , {filteredOptions.map(group => ( <h3 classNam... |
div |
element | className={styles.searchBar} | |
Text |
component | name="config-filter", onChange={setFilter}, type="search", value={filter} | none |
div |
element | key={group.heading} | , |
h3 |
element | className={styles.searchResultGroup} | {group.heading} |
div |
element | none | {group.fields.map(item => ( <ConfigEditorField item={item} key={item.key} onC... |
ConfigEditorField |
component | item={item}, key={item.key}, onChange={onChange}, value={values[item.key]} | none |
Functions¶
filterConfig(options: ConfigOptionsType[], filter: string): ConfigOptionsType[]¶
Parameters:
optionsConfigOptionsType[]filterstring
Returns: ConfigOptionsType[]
Calls:
options .map(group => ({ fields: group.fields.filter(item => item.key.toLowerCase().includes(filter.toLowerCase()), ), heading: group.heading, })) .filter
Code
isDefault(value: unknown, defaults: unknown[]): boolean¶
Parameters:
valueunknowndefaultsunknown[]
Returns: boolean
Calls:
defaults.includes
Code
ConfigEditorField({ item, onChange, value, }: ConfigEditorFieldProps): React.JSX.Element¶
Parameters:
{ item, onChange, value, }ConfigEditorFieldProps
Returns: React.JSX.Element
Calls:
BooleanisDefaultonChangeString
Code
function ConfigEditorField({
item,
onChange,
value,
}: ConfigEditorFieldProps): React.JSX.Element {
return (
<label className={styles.searchResult}>
<span className={styles.searchResultDescription}>
<span className={styles.searchResultName}>{item.key}</span>
{item.label && <br />}
{item.label && <span> {item.label}</span>}
</span>
{item.type === 'boolean' ? (
<Checkbox
checked={Boolean(value)}
indeterminate={Boolean(value) && !isDefault(value, item.defaults)}
name={`config_${item.key}`}
onChange={(checked): void =>
onChange(
item.key,
checked ? (item.defaults?.[0] ?? true) : undefined,
)
}
value={item.key}
/>
) : (
item.enum && (
<Dropdown
name={`config_${item.key}`}
onChange={(value): void => onChange(item.key, value)}
options={item.enum}
value={String(value)}
/>
)
)}
</label>
);
}
ConfigEditor({ className, onChange: onChangeβ¦: ConfigEditorProps): React.JSX.Element¶
Parameters:
{ className, onChange: onChangeProp, options, values, }ConfigEditorProps
Returns: React.JSX.Element
Calls:
useState (from react)useMemo (from react)filterConfiguseCallback (from react)onChangePropclsx (from clsx)filteredOptions.mapgroup.fields.map
Internal Comments:
// Filter out falsy values from the new config (x2)
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete (x2)
Code
function ConfigEditor({
className,
onChange: onChangeProp,
options,
values,
}: ConfigEditorProps): React.JSX.Element {
const [filter, setFilter] = useState('');
const filteredOptions = useMemo(() => {
return filterConfig(options, filter);
}, [options, filter]);
const onChange = useCallback(
(name: string, value: unknown): void => {
const newConfig = { ...values };
if (value === '' || value == null) {
// Filter out falsy values from the new config
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete newConfig[name];
} else {
newConfig[name] = value;
}
onChangeProp(newConfig);
},
[values, onChangeProp],
);
return (
<div
className={clsx(
'thin-scrollbar',
styles.searchResultContainer,
className,
)}
>
<div className={styles.searchBar}>
<Text
name="config-filter"
onChange={setFilter}
type="search"
value={filter}
/>
</div>
{filteredOptions.map(group => (
<div key={group.heading}>
<h3 className={styles.searchResultGroup}>{group.heading}</h3>
<div>
{group.fields.map(item => (
<ConfigEditorField
item={item}
key={item.key}
onChange={onChange}
value={values[item.key]}
/>
))}
</div>
</div>
))}
</div>
);
}
Interfaces¶
ConfigOptionsField¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
defaults |
unknown[] |
β | not shown |
enum |
string[] |
β | not shown |
key |
string |
β | not shown |
label |
string |
β | not shown |
type |
'boolean' \| 'string' |
β | not shown |
ConfigOptionsType¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
fields |
ConfigOptionsField[] |
β | not shown |
heading |
string |
β | not shown |
ConfigEditorProps¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
className |
string |
β | not shown |
onChange |
(config: ConfigEditorValues) => void |
β | not shown |
options |
ConfigOptionsType[] |
β | not shown |
values |
ConfigEditorValues |
β | not shown |
ConfigEditorFieldProps¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
item |
ConfigOptionsField |
β | not shown |
onChange |
(name: string, value: unknown) => void |
β | not shown |
value |
unknown |
β | not shown |
Type Aliases¶
ConfigEditorValues¶
Generated by Syntax Scribe