44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
import * as React from "react";
|
|
import { SidebarCategory } from "./components.js";
|
|
import Option from "./options.js";
|
|
|
|
// Copied from `/src/cli/utils.js`
|
|
function groupBy(array, iteratee) {
|
|
const result = Object.create(null);
|
|
|
|
for (const value of array) {
|
|
const key = iteratee(value);
|
|
|
|
if (Array.isArray(result[key])) {
|
|
result[key].push(value);
|
|
} else {
|
|
result[key] = [value];
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
export default function SidebarOptions({
|
|
categories,
|
|
availableOptions,
|
|
optionValues,
|
|
onOptionValueChange,
|
|
}) {
|
|
const options = groupBy(availableOptions, (option) => option.category);
|
|
return categories.map((category) =>
|
|
options[category] ? (
|
|
<SidebarCategory key={category} title={category}>
|
|
{options[category].map((option) => (
|
|
<Option
|
|
key={option.name}
|
|
option={option}
|
|
value={optionValues[option.name]}
|
|
onChange={onOptionValueChange}
|
|
/>
|
|
))}
|
|
</SidebarCategory>
|
|
) : null
|
|
);
|
|
}
|