Skip to content

Commit

Permalink
fix(explore): Do not use iterator.map (#81312)
Browse files Browse the repository at this point in the history
`Iterator.prototype.map()` is not widely available so don't use it.

See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/map

Resolves JAVASCRIPT-2WW0
  • Loading branch information
Zylphrex authored Nov 26, 2024
1 parent 93ce77b commit f2b839f
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions static/app/views/explore/toolbar/toolbarSortBy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,45 +38,50 @@ export function ToolbarSortBy({fields, setSorts, sorts}: ToolbarSortByProps) {
const stringTags = useSpanTags('string');

const fieldOptions: SelectOption<Field>[] = useMemo(() => {
const options = [
...new Set(fields).keys().map(field => {
const tag = stringTags[field] ?? numberTags[field] ?? null;
if (tag) {
return {
label: tag.name,
value: field,
textValue: tag.name,
trailingItems: <TypeBadge kind={tag?.kind} />,
};
}

const func = parseFunction(field);
if (func) {
const formatted = prettifyParsedFunction(func);
return {
label: formatted,
value: field,
textValue: formatted,
trailingItems: <TypeBadge func={func} />,
};
}

const result = field.match(TYPED_TAG_KEY_RE);
const kind =
result?.[2] === 'string'
? FieldKind.TAG
: result?.[2] === 'number'
? FieldKind.MEASUREMENT
: undefined;
const uniqFields: Field[] = [];
for (const field of fields) {
if (!uniqFields.includes(field)) {
uniqFields.push(field);
}
}

const options = uniqFields.map(field => {
const tag = stringTags[field] ?? numberTags[field] ?? null;
if (tag) {
return {
label: prettifyTagKey(field),
label: tag.name,
value: field,
textValue: field,
trailingItems: <TypeBadge kind={kind} />,
textValue: tag.name,
trailingItems: <TypeBadge kind={tag?.kind} />,
};
}),
];
}

const func = parseFunction(field);
if (func) {
const formatted = prettifyParsedFunction(func);
return {
label: formatted,
value: field,
textValue: formatted,
trailingItems: <TypeBadge func={func} />,
};
}

const result = field.match(TYPED_TAG_KEY_RE);
const kind =
result?.[2] === 'string'
? FieldKind.TAG
: result?.[2] === 'number'
? FieldKind.MEASUREMENT
: undefined;

return {
label: prettifyTagKey(field),
value: field,
textValue: field,
trailingItems: <TypeBadge kind={kind} />,
};
});

options.sort((a, b) => {
if (a.label < b.label) {
Expand Down

0 comments on commit f2b839f

Please sign in to comment.