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 #666

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
78 changes: 61 additions & 17 deletions cyclops-ui/src/components/pages/Modules/Modules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import styles from "./styles.module.css";
import { PlusCircleOutlined, FilterOutlined } from "@ant-design/icons";
import { mapResponseError } from "../../../utils/api/errors";

const { Title } = Typography;
const { Title, Text } = Typography;

const Modules = () => {
const [allData, setAllData] = useState([]);
Expand All @@ -34,8 +34,12 @@ const Modules = () => {
"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 @@ -44,6 +48,22 @@ const Modules = () => {
useEffect(() => {
setLoadingModules(true);

function populateNamespaceData() {
s-vamshi marked this conversation as resolved.
Show resolved Hide resolved
axios
.get(`/api/namespaces`)
.then((res) => {
setNamespaceFilterData(res.data);
setModuleNamespaceFilter(res.data);
setLoadingModules(false);
s-vamshi marked this conversation as resolved.
Show resolved Hide resolved
})
.catch((error) => {
setError(mapResponseError(error));
setLoadingModules(false);
s-vamshi marked this conversation as resolved.
Show resolved Hide resolved
});
}

populateNamespaceData();

function fetchModules() {
axios
.get(`/api/modules/list`)
Expand Down Expand Up @@ -72,34 +92,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}
>
<Text strong>Health</Text>
<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}
>
<Text strong>Namespace</Text>
<br />
{namespaceFilterData.map((item, index) => (
<Checkbox key={index} value={item}>
{item}
</Checkbox>
))}
</Checkbox.Group>
</>
);
};
const handleSearch = (event: any) => {
Expand Down
Loading