-
Notifications
You must be signed in to change notification settings - Fork 772
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
28436f7
3bdde7b
14fa7f8
cb4cf57
df2a318
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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[]>([]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert to empty array |
||
const [filteredData, setFilteredData] = useState<ModuleInterface[]>([]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert to empty array |
||
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: "", | ||
|
@@ -49,6 +71,7 @@ const Modules = () => { | |
.get(`/api/modules/list`) | ||
.then((res) => { | ||
setAllData(res.data); | ||
populateNamespaceData(res.data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the call of this function outside the In this useEffect, before the |
||
setLoadingModules(false); | ||
}) | ||
.catch((error) => { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true didnt check this my bad, will update |
||
}; | ||
|
||
useEffect(() => { | ||
var updatedList = [...allData]; | ||
updatedList = updatedList.filter((module: any) => { | ||
|
@@ -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) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove this for now, we'd have to implement it in more places. Let's keep the scope of the PR to just what was defined in the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure will remove it!