MCPcopy Create free account
hub / github.com/bytebase/bytebase / getLabelFilter

Function getLabelFilter

frontend/src/react/stores/app/utils.ts:68–96  ·  view source on GitHub ↗
(labels: string[])

Source from the content-addressed store, hash-verified

66// (`labels.{key} == "v"` or `labels.{key} in [...]`). Ported verbatim from
67// the legacy Pinia database store.
68export function getLabelFilter(labels: string[]): string[] {
69 const labelMap = new Map<string, string[]>();
70 for (const label of labels) {
71 const sections = label.split(":");
72 if (sections.length !== 2) {
73 continue;
74 }
75 const [key, rawValue] = sections;
76 const values = rawValue.split(",");
77 if (!labelMap.has(key)) {
78 labelMap.set(key, []);
79 }
80 labelMap.get(key)?.push(...values);
81 }
82 return [...labelMap.entries()].reduce((result, [key, values]) => {
83 switch (values.length) {
84 case 0:
85 return result;
86 case 1:
87 result.push(`labels.${key} == "${values[0]}"`);
88 return result;
89 default:
90 result.push(
91 `labels.${key} in [${values.map((v) => `"${v}"`).join(", ")}]`
92 );
93 return result;
94 }
95 }, [] as string[]);
96}
97
98// Builds the CEL filter string for `listDatabases` from a structured
99// `DatabaseFilter`. Mirrors the legacy Pinia `getListDatabaseFilter` so the

Callers 3

getListProjectFilterFunction · 0.90
getListInstanceFilterFunction · 0.90
buildDatabaseFilterFunction · 0.85

Calls 2

setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected