Skip to content

Commit ac52c44

Browse files
authored
reducer: refactor complexity to On (#103672)
Refactor reducer spread or concat operations in a couple places where this might be sensitive
1 parent 0dd1f62 commit ac52c44

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

static/app/components/core/compactSelect/utils.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function getSelectedOptions<Value extends SelectKey>(
6666
// If this is an option
6767
if (selection === 'all' || selection.has(cur.key)) {
6868
const {key: _key, ...opt} = cur;
69-
return acc.concat(opt);
69+
acc.push(opt);
7070
}
7171
return acc;
7272
}, []);
@@ -81,19 +81,24 @@ export function getDisabledOptions<Value extends SelectKey>(
8181
items: Array<SelectOptionOrSectionWithKey<Value>>,
8282
isOptionDisabled?: (opt: SelectOptionWithKey<Value>) => boolean
8383
): SelectKey[] {
84-
return items.reduce((acc: SelectKey[], cur) => {
84+
return items.reduce<SelectKey[]>((acc, cur) => {
8585
// If this is a section
8686
if ('options' in cur) {
8787
if (cur.disabled) {
8888
// If the entire section is disabled, then mark all of its children as disabled
89-
return acc.concat(cur.options.map(opt => opt.key));
89+
for (const opt of cur.options) {
90+
acc.push(opt.key);
91+
}
92+
return acc;
9093
}
94+
9195
return acc.concat(getDisabledOptions(cur.options, isOptionDisabled));
9296
}
9397

9498
// If this is an option
9599
if (isOptionDisabled?.(cur) ?? cur.disabled) {
96-
return acc.concat(cur.key);
100+
acc.push(cur.key);
101+
return acc;
97102
}
98103
return acc;
99104
}, []);

static/app/components/dropdownMenu/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ function removeHiddenItemsAndSetHref(source: MenuItemProps[]): MenuItemProps[] {
3535
* Recursively finds and returns disabled items
3636
*/
3737
function getDisabledKeys(source: MenuItemProps[]): Array<MenuItemProps['key']> {
38-
return source.reduce<string[]>((acc, cur) => {
38+
return source.reduce<Array<MenuItemProps['key']>>((acc, cur) => {
3939
if (cur.disabled) {
4040
// If an item is disabled, then its children will be inaccessible, so we
4141
// can skip them and just return the parent item
42-
return acc.concat([cur.key]);
42+
acc.push(cur.key);
43+
return acc;
4344
}
4445

4546
if (cur.children) {

static/app/components/events/eventTags/util.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ export const TagFilterData = {
147147
* Combines all of the above into a single set to determine if a tag is custom
148148
*/
149149
export function getSentryDefaultTags() {
150-
return Object.values(TagFilterData).reduce(
151-
// TODO: result.union(s) when Set.prototype.union is Baseline
152-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union
153-
(result, s) => new Set([...result, ...s]),
154-
new Set([])
155-
);
150+
return Object.values(TagFilterData).reduce<Set<string>>((acc, set) => {
151+
for (const tag of set) {
152+
acc.add(tag);
153+
}
154+
return acc;
155+
}, new Set());
156156
}
157157

158158
const ISSUE_DETAILS_COLUMN_BREAKPOINTS = [

static/app/components/searchQueryBuilder/utils.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ export function collapseTextTokens(tokens: ParseResult | null) {
166166
return acc;
167167
}
168168

169-
return [...acc, token];
169+
acc.push(token);
170+
return acc;
170171
}, []);
171172
}
172173

static/app/views/explore/logs/tables/logsTableRow.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ import {
4545
useLogsAutoRefreshEnabled,
4646
useSetLogsAutoRefresh,
4747
} from 'sentry/views/explore/contexts/logs/logsAutoRefreshContext';
48-
import type {TraceItemDetailsResponse} from 'sentry/views/explore/hooks/useTraceItemDetails';
48+
import type {
49+
TraceItemDetailsResponse,
50+
TraceItemResponseAttribute,
51+
} from 'sentry/views/explore/hooks/useTraceItemDetails';
4952
import {useFetchTraceItemDetailsOnHover} from 'sentry/views/explore/hooks/useTraceItemDetails';
5053
import {
5154
DEFAULT_TRACE_ITEM_HOVER_TIMEOUT,
@@ -502,11 +505,23 @@ function LogRowDetails({
502505
const theme = useTheme();
503506
const logColors = getLogColors(level, theme);
504507
const attributes =
505-
data?.attributes?.reduce((it, {name, value}) => ({...it, [name]: value}), {
506-
[OurLogKnownFieldKey.TIMESTAMP]: dataRow[OurLogKnownFieldKey.TIMESTAMP],
507-
}) ?? {};
508+
data?.attributes?.reduce<Record<string, TraceItemResponseAttribute['value']>>(
509+
(it, attr) => {
510+
it[attr.name] = attr.value;
511+
return it;
512+
},
513+
{
514+
[OurLogKnownFieldKey.TIMESTAMP]: dataRow[OurLogKnownFieldKey.TIMESTAMP],
515+
}
516+
) ?? {};
508517
const attributeTypes =
509-
data?.attributes?.reduce((it, {name, type}) => ({...it, [name]: type}), {}) ?? {};
518+
data?.attributes?.reduce<Record<string, TraceItemResponseAttribute['type']>>(
519+
(it, attr) => {
520+
it[attr.name] = attr.type;
521+
return it;
522+
},
523+
{}
524+
) ?? {};
510525

511526
if (missingLogId || isError) {
512527
return (

0 commit comments

Comments
 (0)