-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add include and exclude by cells in table cells
Fixes #1774
- Loading branch information
1 parent
c93180e
commit b6e8f8b
Showing
9 changed files
with
442 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 70 additions & 7 deletions
77
src/components/Configs/Changes/ConfigChangesFilters/ConfigChangesFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,89 @@ | ||
import ClosableBadge from "@flanksource-ui/ui/Badge/ClosableBadge"; | ||
import clsx from "clsx"; | ||
import { useCallback } from "react"; | ||
import { FaBan } from "react-icons/fa"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import { paramsToReset } from "../ConfigChangeHistory"; | ||
import { ChangesTypesDropdown } from "./ChangeTypesDropdown"; | ||
import { ConfigChangeSeverity } from "./ConfigChangeSeverity"; | ||
import ConfigChangesDateRangeFilter from "./ConfigChangesDateRangeFIlter"; | ||
import ConfigTypesTristateDropdown from "./ConfigTypesTristateDropdown"; | ||
|
||
type FilterBadgeProps = { | ||
filters: string; | ||
paramKey: string; | ||
}; | ||
|
||
function FilterBadge({ filters, paramKey }: FilterBadgeProps) { | ||
const [params, setParams] = useSearchParams(); | ||
|
||
const onRemove = useCallback( | ||
(key: string, value: string) => { | ||
const currentValue = params.get(key); | ||
const arrayValue = currentValue?.split(",") || []; | ||
const newValues = arrayValue.filter( | ||
(v) => decodeURIComponent(v) !== decodeURIComponent(value) | ||
); | ||
if (newValues.length === 0) { | ||
params.delete(key); | ||
} else { | ||
const updateValue = newValues.join(","); | ||
params.set(key, updateValue); | ||
} | ||
paramsToReset.configChanges.forEach((param) => params.delete(param)); | ||
setParams(params); | ||
}, | ||
[params, setParams] | ||
); | ||
|
||
const filtersArray = filters.split(","); | ||
|
||
return ( | ||
<> | ||
{filtersArray.map((filter) => ( | ||
<ClosableBadge | ||
color="gray" | ||
key={filter} | ||
className="flex flex-row gap-1 px-2 text-xs" | ||
onRemove={() => onRemove(paramKey, filter)} | ||
> | ||
<span className="text-gray-500 font-semibold">{paramKey}:</span> | ||
<span className="text-gray-500"> | ||
{decodeURIComponent(filter.split(":")[0])} | ||
</span> | ||
<span>{filter.split(":")[1] === "-1" && <FaBan />}</span> | ||
</ClosableBadge> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
type ConfigChangeFiltersProps = React.HTMLProps<HTMLDivElement> & { | ||
paramsToReset?: string[]; | ||
arbitraryFilters?: Record<string, string>; | ||
}; | ||
|
||
export function ConfigChangeFilters({ | ||
className, | ||
paramsToReset = [], | ||
arbitraryFilters, | ||
...props | ||
}: ConfigChangeFiltersProps) { | ||
return ( | ||
<div className={clsx("flex flex-row gap-2", className)} {...props}> | ||
<ConfigTypesTristateDropdown | ||
paramsToReset={[...paramsToReset, "configType"]} | ||
/> | ||
<ChangesTypesDropdown paramsToReset={paramsToReset} /> | ||
<ConfigChangeSeverity paramsToReset={paramsToReset} /> | ||
<ConfigChangesDateRangeFilter paramsToReset={paramsToReset} /> | ||
<div className="flex flex-col gap-2"> | ||
<div className={clsx("flex flex-row gap-1", className)} {...props}> | ||
<ConfigTypesTristateDropdown | ||
paramsToReset={[...paramsToReset, "configType"]} | ||
/> | ||
<ChangesTypesDropdown paramsToReset={paramsToReset} /> | ||
<ConfigChangeSeverity paramsToReset={paramsToReset} /> | ||
<ConfigChangesDateRangeFilter paramsToReset={paramsToReset} /> | ||
</div> | ||
<div className="flex flex-wrap gap-2"> | ||
{Object.entries(arbitraryFilters ?? {}).map(([key, value]) => ( | ||
<FilterBadge filters={value} key={value} paramKey={key} /> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from "react"; | ||
import { IoMdClose } from "react-icons/io"; | ||
import { Button } from "../Buttons/Button"; | ||
|
||
type BadgeProps = { | ||
size?: "xs" | "sm" | "md"; | ||
color?: "blue" | "gray"; | ||
dot?: string; | ||
title?: string; | ||
className?: string; | ||
colorClass?: string; | ||
roundedClass?: string; | ||
children: React.ReactNode; | ||
onRemove?: () => void; | ||
}; | ||
|
||
export default function ClosableBadge({ | ||
children, | ||
size = "sm", | ||
dot, | ||
title, | ||
color = "blue", | ||
className, | ||
roundedClass = "rounded", | ||
onRemove = () => {} | ||
}: BadgeProps) { | ||
if (children == null || children === "") { | ||
return null; | ||
} | ||
|
||
const colorClass = | ||
color === "blue" | ||
? "bg-blue-100 text-blue-800" | ||
: "bg-gray-200 text-gray-700"; | ||
const spanClassName = | ||
size === "sm" ? "text-sm px-1 py-0.5" : "text-xs px-1 py-0.5"; | ||
const svgClassName = | ||
size === "sm" ? "mr-1.5 h-2 w-2" : "-ml-0.5 mr-1.5 h-2 w-2"; | ||
|
||
return ( | ||
<div | ||
className={`${className} ${spanClassName} inline items-center ${roundedClass} font-medium ${colorClass}`} | ||
title={title} | ||
> | ||
{dot != null && ( | ||
<svg | ||
className={`${svgClassName} text-blue-400" fill="${dot}" viewBox="0 0 8 8"`} | ||
> | ||
<circle cx={4} cy={4} r={3} /> | ||
</svg> | ||
)} | ||
{children} | ||
<Button | ||
icon={<IoMdClose size={12} />} | ||
className="hover:text-gray-700 text-gray-500 border-l border-gray-50 pl-1.5 py-1.5 text-xs rounded" | ||
size="none" | ||
onClick={onRemove} | ||
title="Remove filter" | ||
/> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.