Service filters
This commit is contained in:
@ -25,7 +25,6 @@ export default function Dashboard() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadEnv = (envTab: EnvTab) => {
|
const loadEnv = (envTab: EnvTab) => {
|
||||||
console.log("loading env:", envTab);
|
|
||||||
setLoadingErr(null);
|
setLoadingErr(null);
|
||||||
setLoadingEnv(true);
|
setLoadingEnv(true);
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,41 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Environment } from "types";
|
import { Environment } from "types";
|
||||||
import TenantList from "components/dashboard/TenantList";
|
import TenantList, { tenantHasServices } from "components/dashboard/TenantList";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Container from "@mui/material/Container";
|
import Container from "@mui/material/Container";
|
||||||
import { useGlobalState } from "GlobalStateProvider";
|
import { useGlobalState } from "GlobalStateProvider";
|
||||||
|
|
||||||
|
function environmentHasTenants(env: Environment): boolean {
|
||||||
|
return env.tenants.filter((tenant) => tenantHasServices(tenant)).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
interface EnvironmentListProps {
|
interface EnvironmentListProps {
|
||||||
environments: Environment[];
|
environments: Environment[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function EnvironmentList({ environments }: EnvironmentListProps) {
|
export default function EnvironmentList({ environments }: EnvironmentListProps) {
|
||||||
const envItems = environments.map((env) => {
|
let filteredEnvironments: Environment[] = [];
|
||||||
|
const { state } = useGlobalState();
|
||||||
|
|
||||||
|
// deep clone array
|
||||||
|
filteredEnvironments = JSON.parse(JSON.stringify(environments));
|
||||||
|
|
||||||
|
// filter services
|
||||||
|
filteredEnvironments.forEach((env) => {
|
||||||
|
env.tenants.forEach((tenant) => {
|
||||||
|
tenant.services = tenant.services.filter(
|
||||||
|
(service) =>
|
||||||
|
!state.searchFilter ||
|
||||||
|
service.name.toLocaleLowerCase().includes(state.searchFilter.toLocaleLowerCase())
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove empty environments
|
||||||
|
filteredEnvironments = filteredEnvironments.filter((env) => environmentHasTenants(env));
|
||||||
|
|
||||||
|
const envItems = filteredEnvironments.map((env) => {
|
||||||
return (
|
return (
|
||||||
<Box className="environment" key={env.name} sx={{ marginBottom: "2rem" }}>
|
<Box className="environment" key={env.name} sx={{ marginBottom: "2rem" }}>
|
||||||
<Container maxWidth={false} className="main-container">
|
<Container maxWidth={false} className="main-container">
|
||||||
|
|||||||
@ -2,27 +2,19 @@ import React from "react";
|
|||||||
import { Service } from "types";
|
import { Service } from "types";
|
||||||
import Grid from "@mui/material/Unstable_Grid2";
|
import Grid from "@mui/material/Unstable_Grid2";
|
||||||
import ServiceCard from "./ServiceCard";
|
import ServiceCard from "./ServiceCard";
|
||||||
import { useGlobalState } from "GlobalStateProvider";
|
|
||||||
|
|
||||||
interface ServiceListProps {
|
interface ServiceListProps {
|
||||||
services: Service[];
|
services: Service[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ServiceList({ services }: ServiceListProps) {
|
export default function ServiceList({ services }: ServiceListProps) {
|
||||||
const { state } = useGlobalState();
|
const serviceItems = services.map((service) => {
|
||||||
|
return (
|
||||||
const serviceItems = services
|
<Grid key={service.name} sx={{ display: "flex" }}>
|
||||||
.filter(
|
<ServiceCard service={service} />
|
||||||
(service) =>
|
</Grid>
|
||||||
!state.searchFilter || service.name.toLocaleLowerCase().includes(state.searchFilter.toLocaleLowerCase())
|
);
|
||||||
)
|
});
|
||||||
.map((service) => {
|
|
||||||
return (
|
|
||||||
<Grid key={service.name} sx={{ display: "flex" }}>
|
|
||||||
<ServiceCard service={service} />
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container rowSpacing={2} columnSpacing={2} className="service-list">
|
<Grid container rowSpacing={2} columnSpacing={2} className="service-list">
|
||||||
|
|||||||
@ -8,8 +8,14 @@ interface TenantListProps {
|
|||||||
tenants: Tenant[];
|
tenants: Tenant[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function tenantHasServices(tenant: Tenant): boolean {
|
||||||
|
return tenant.services.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
export default function TenantList({ tenants }: TenantListProps) {
|
export default function TenantList({ tenants }: TenantListProps) {
|
||||||
const tenantItems = tenants.map((tenant) => {
|
const tenantItems = tenants.map((tenant) => {
|
||||||
|
if (!tenantHasServices(tenant)) return null;
|
||||||
|
|
||||||
const tenantName = tenant.name !== "default" ? `Tenant: ${tenant.name}` : "Multitenant";
|
const tenantName = tenant.name !== "default" ? `Tenant: ${tenant.name}` : "Multitenant";
|
||||||
return (
|
return (
|
||||||
<Box key={tenant.name} className="tenant">
|
<Box key={tenant.name} className="tenant">
|
||||||
|
|||||||
Reference in New Issue
Block a user