Modules/api: export constraints, filter by inventory
This commit is contained in:
@@ -139,6 +139,7 @@ class ModuleInfo:
|
||||
categories: list[str]
|
||||
roles: list[str] | None
|
||||
features: list[str] = field(default_factory=list)
|
||||
constraints: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
|
||||
def get_modules(base_path: str) -> dict[str, str]:
|
||||
@@ -208,6 +209,7 @@ def get_module_info(
|
||||
roles=get_roles(module_path),
|
||||
readme=readme_content,
|
||||
features=["inventory"] if has_inventory_feature(module_path) else [],
|
||||
constraints=frontmatter.constraints,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,13 @@ import { createQuery } from "@tanstack/solid-query";
|
||||
import { callApi } from "../api";
|
||||
import toast from "solid-toast";
|
||||
|
||||
export const createModulesQuery = (uri: string | null) =>
|
||||
export interface ModulesFilter {
|
||||
features: string[];
|
||||
}
|
||||
export const createModulesQuery = (
|
||||
uri: string | null,
|
||||
filter?: ModulesFilter,
|
||||
) =>
|
||||
createQuery(() => ({
|
||||
queryKey: [uri, "list_modules"],
|
||||
placeholderData: [],
|
||||
@@ -17,8 +23,13 @@ export const createModulesQuery = (uri: string | null) =>
|
||||
if (response.status === "error") {
|
||||
toast.error("Failed to fetch data");
|
||||
} else {
|
||||
if (!filter) {
|
||||
return Object.entries(response.data);
|
||||
}
|
||||
return Object.entries(response.data).filter(([key, value]) =>
|
||||
filter.features.every((f) => (value.features || []).includes(f)),
|
||||
);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
},
|
||||
|
||||
@@ -28,7 +28,9 @@ const ModuleListItem = (props: { name: string; info: ModuleInfo }) => {
|
||||
};
|
||||
|
||||
export const ModuleList = () => {
|
||||
const modulesQuery = createModulesQuery(activeURI());
|
||||
const modulesQuery = createModulesQuery(activeURI(), {
|
||||
features: ["inventory"],
|
||||
});
|
||||
return (
|
||||
<Switch fallback="Shit">
|
||||
<Match when={modulesQuery.isLoading}>Loading....</Match>
|
||||
|
||||
Reference in New Issue
Block a user