Skip to content

Commit 275bd19

Browse files
committed
fix(web): preserve normalized label limits
1 parent 1a2af3b commit 275bd19

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

‎apps/web/src/routes/_chat.pull-requests.tsx‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,24 @@ const EMPTY_PREVIEW_SESSIONS = {};
204204
const EMPTY_PREVIEW_DESKTOP_STATE = {};
205205
const EMPTY_TERMINAL_LABELS = new Map<string, string>();
206206
const EMPTY_PENDING_SURFACES = new Set<string>();
207+
const MAX_SEARCH_LABEL_CANDIDATES = 100;
207208

208209
function pullRequestSearchLabels(raw: unknown): Partial<Pick<PullRequestsSearch, "labels">> {
209-
const values = (Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : []).slice(0, 10);
210-
const labels = values
211-
.filter((value): value is string => typeof value === "string")
212-
.map((value) => value.trim().slice(0, 200))
213-
.filter(
214-
(value, index, all) =>
215-
value.length > 0 &&
216-
all.findIndex((candidate) => candidate.toLowerCase() === value.toLowerCase()) === index,
217-
);
210+
const values = (Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : []).slice(
211+
0,
212+
MAX_SEARCH_LABEL_CANDIDATES,
213+
);
214+
const labels: Array<string> = [];
215+
const seen = new Set<string>();
216+
for (const rawValue of values) {
217+
if (typeof rawValue !== "string") continue;
218+
const value = rawValue.trim().slice(0, 200);
219+
const key = value.toLowerCase();
220+
if (value.length === 0 || seen.has(key)) continue;
221+
labels.push(value);
222+
seen.add(key);
223+
if (labels.length === 10) break;
224+
}
218225
return labels.length === 0 ? {} : { labels };
219226
}
220227

0 commit comments

Comments
 (0)