enable active search through dropped targets (#10668)

Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
This commit is contained in:
Augustin Husson 2022-05-04 20:27:56 +02:00 committed by GitHub
parent 2381d7be57
commit 0a30ac3f9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,11 +22,16 @@ export interface TargetLabels {
isDropped: boolean;
}
const kvSearch = new KVSearch<Target>({
const activeTargetKVSearch = new KVSearch<Target>({
shouldSort: true,
indexedKeys: ['labels', 'discoveredLabels', ['discoveredLabels', /.*/], ['labels', /.*/]],
});
const droppedTargetKVSearch = new KVSearch<DroppedTarget>({
shouldSort: true,
indexedKeys: ['discoveredLabels', ['discoveredLabels', /.*/]],
});
export const processSummary = (
activeTargets: Target[],
droppedTargets: DroppedTarget[]
@ -91,6 +96,7 @@ export const processTargets = (activeTargets: Target[], droppedTargets: DroppedT
export const ServiceDiscoveryContent: FC<ServiceMap> = ({ activeTargets, droppedTargets }) => {
const [activeTargetList, setActiveTargetList] = useState(activeTargets);
const [droppedTargetList, setDroppedTargetList] = useState(droppedTargets);
const [targetList, setTargetList] = useState(processSummary(activeTargets, droppedTargets));
const [labelList, setLabelList] = useState(processTargets(activeTargets, droppedTargets));
@ -98,21 +104,23 @@ export const ServiceDiscoveryContent: FC<ServiceMap> = ({ activeTargets, dropped
(value: string) => {
setQuerySearchFilter(value);
if (value !== '') {
const result = kvSearch.filter(value.trim(), activeTargets);
setActiveTargetList(result.map((value) => value.original));
const activeTargetResult = activeTargetKVSearch.filter(value.trim(), activeTargets);
const droppedTargetResult = droppedTargetKVSearch.filter(value.trim(), droppedTargets);
setActiveTargetList(activeTargetResult.map((value) => value.original));
setDroppedTargetList(droppedTargetResult.map((value) => value.original));
} else {
setActiveTargetList(activeTargets);
}
},
[activeTargets]
[activeTargets, droppedTargets]
);
const defaultValue = useMemo(getQuerySearchFilter, []);
useEffect(() => {
setTargetList(processSummary(activeTargetList, droppedTargets));
setLabelList(processTargets(activeTargetList, droppedTargets));
}, [activeTargetList, droppedTargets]);
setTargetList(processSummary(activeTargetList, droppedTargetList));
setLabelList(processTargets(activeTargetList, droppedTargetList));
}, [activeTargetList, droppedTargetList]);
return (
<>