Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cyclops-ui): Filter Modules by TargetNamespace #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cyclops-ctrl/internal/mapper/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ func ModuleListToDTO(modules []cyclopsv1alpha1.Module) []dto.Module {
for _, module := range modules {
values := make(map[string]interface{})
out = append(out, dto.Module{
Name: module.Name,
Namespace: module.Namespace,
Version: module.Spec.TemplateRef.Version,
Template: k8sTemplateRefToDTO(module.Spec.TemplateRef, module.Status.TemplateResolvedVersion),
Values: values,
IconURL: module.Status.IconURL,
Name: module.Name,
Namespace: module.Namespace,
TargetNamespace: mapTargetNamespace(module.Spec.TargetNamespace),
Version: module.Spec.TemplateRef.Version,
Template: k8sTemplateRefToDTO(module.Spec.TemplateRef, module.Status.TemplateResolvedVersion),
Values: values,
IconURL: module.Status.IconURL,
})
}

Expand Down
93 changes: 75 additions & 18 deletions cyclops-ui/src/components/pages/Modules/Modules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,40 @@ import { mapResponseError } from "../../../utils/api/errors";

const { Title } = Typography;

interface ModuleInterface {
name: string;
namespace: string;
targetNamespace: string;
template: {
repo: string;
path: string;
version: string;
resolvedVersion: string;
sourceType: string;
};
version: string;
values: { [key: string]: any };
status: string;
iconURL: string;
reconciliationStatus: { [key: string]: any };
}

const Modules = () => {
const [allData, setAllData] = useState([]);
const [filteredData, setFilteredData] = useState([]);
const [allData, setAllData] = useState<ModuleInterface[]>([]);
const [filteredData, setFilteredData] = useState<ModuleInterface[]>([]);
const [loadingModules, setLoadingModules] = useState(false);
const [moduleHealthFilter, setModuleHealthFilter] = useState<string[]>([
"Healthy",
"Unhealthy",
"Progressing",
"Unknown",
]);
const [moduleNamespaceFilter, setModuleNamespaceFilter] = useState<string[]>(
[],
);
const [searchInputFilter, setsearchInputFilter] = useState("");
const resourceFilter = ["Healthy", "Unhealthy", "Progressing", "Unknown"];
const [namespaceFilterData, setNamespaceFilterData] = useState<string[]>([]);
const [error, setError] = useState({
message: "",
description: "",
Expand All @@ -49,6 +71,7 @@ const Modules = () => {
.get(`/api/modules/list`)
.then((res) => {
setAllData(res.data);
populateNamespaceData(res.data);
setLoadingModules(false);
})
.catch((error) => {
Expand All @@ -64,6 +87,16 @@ const Modules = () => {
};
}, []);

const populateNamespaceData = (allData: ModuleInterface[]) => {
const namespaceData = allData
.map((module) => module.targetNamespace)
.filter((targetNamespace, index, self) => {
return self.indexOf(targetNamespace) === index;
});
setNamespaceFilterData(namespaceData);
setModuleNamespaceFilter(namespaceData);
};

useEffect(() => {
var updatedList = [...allData];
updatedList = updatedList.filter((module: any) => {
Expand All @@ -72,34 +105,58 @@ const Modules = () => {
-1
);
});
const newfilteredData = updatedList.filter((module: any) =>
moduleHealthFilter
.map((status) => status.toLowerCase())
.includes(module.status.toLowerCase()),
const newfilteredData = updatedList.filter(
(module: any) =>
moduleHealthFilter
.map((status) => status.toLowerCase())
.includes(module.status.toLowerCase()) &&
moduleNamespaceFilter
.map((targetNamespace) => targetNamespace.toLowerCase())
.includes(module.targetNamespace.toLowerCase()),
);
setFilteredData(newfilteredData);
}, [moduleHealthFilter, allData, searchInputFilter]);
}, [moduleNamespaceFilter, moduleHealthFilter, allData, searchInputFilter]);

const handleClick = () => {
window.location.href = "/modules/new";
};
const handleSelectItem = (selectedItems: any[]) => {
setModuleHealthFilter(selectedItems);
};
const handleNamespaceSelectItem = (selectedItems: any[]) => {
setModuleNamespaceFilter(selectedItems);
};

const resourceFilterPopover = () => {
return (
<Checkbox.Group
style={{ display: "block" }}
onChange={handleSelectItem}
value={moduleHealthFilter}
>
{resourceFilter.map((item, index) => (
<Checkbox key={index} value={item}>
{item}
</Checkbox>
))}
</Checkbox.Group>
<>
<Checkbox.Group
style={{ display: "block", margin: "5px 0px" }}
onChange={handleSelectItem}
value={moduleHealthFilter}
>
<b>Health</b>
<br />
{resourceFilter.map((item, index) => (
<Checkbox key={index} value={item}>
{item}
</Checkbox>
))}
</Checkbox.Group>
<Checkbox.Group
style={{ display: "block", margin: "5px 0px" }}
onChange={handleNamespaceSelectItem}
value={moduleNamespaceFilter}
>
<b>Namespace</b>
<br />
{namespaceFilterData.map((item, index) => (
<Checkbox key={index} value={item}>
{item}
</Checkbox>
))}
</Checkbox.Group>
</>
);
};
const handleSearch = (event: any) => {
Expand Down
Loading