Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Replace more indexOf with includes #43694

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/pigment-css-vite-app/src/Slider/ZeroSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ const Slider = React.forwardRef<HTMLSpanElement, SliderProps>(function Slider(pr

let markActive;
if (track === false) {
markActive = values.indexOf(mark.value) !== -1;
markActive = values.includes(mark.value);
} else {
markActive =
(track === 'normal' &&
Expand Down
2 changes: 1 addition & 1 deletion apps/pigment-css-vite-app/src/pages/fixtures/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Layout() {
);

const demosRoutes = (materialUIRoute?.route.children ?? []).filter(
(item) => !!item.path && item.path.indexOf('react-pagination') < 0,
(item) => !!item.path && !item.path.includes('react-pagination'),
);

return (
Expand Down
4 changes: 2 additions & 2 deletions docs/data/joy/components/autocomplete/FixedTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function FixedTags() {
onChange={(event, newValue) => {
setValue([
...fixedOptions,
...newValue.filter((option) => fixedOptions.indexOf(option) === -1),
...newValue.filter((option) => !fixedOptions.includes(option)),
]);
}}
options={top100Films}
Expand All @@ -30,7 +30,7 @@ export default function FixedTags() {
color="neutral"
sx={{ minWidth: 0 }}
{...getTagProps({ index })}
disabled={fixedOptions.indexOf(option) !== -1}
disabled={fixedOptions.includes(option)}
>
{option.title}
</Chip>
Expand Down
4 changes: 2 additions & 2 deletions docs/data/joy/components/autocomplete/FixedTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function FixedTags() {
onChange={(event, newValue) => {
setValue([
...fixedOptions,
...newValue.filter((option) => fixedOptions.indexOf(option) === -1),
...newValue.filter((option) => !fixedOptions.includes(option)),
]);
}}
options={top100Films}
Expand All @@ -30,7 +30,7 @@ export default function FixedTags() {
color="neutral"
sx={{ minWidth: 0 }}
{...getTagProps({ index })}
disabled={fixedOptions.indexOf(option) !== -1}
disabled={fixedOptions.includes(option)}
>
{option.title}
</Chip>
Expand Down
3 changes: 1 addition & 2 deletions docs/data/joy/components/table/TableSortAndSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ export default function TableSortAndSelection() {
? rows.length
: Math.min(rows.length, (page + 1) * rowsPerPage);
};
const isSelected = (name) => selected.indexOf(name) !== -1;
// Avoid a layout jump when reaching the last page with empty rows.
const emptyRows =
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
Expand Down Expand Up @@ -329,7 +328,7 @@ export default function TableSortAndSelection() {
.sort(getComparator(order, orderBy))
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row, index) => {
const isItemSelected = isSelected(row.name);
const isItemSelected = selected.includes(row.name);
const labelId = `enhanced-table-checkbox-${index}`;

return (
Expand Down
3 changes: 1 addition & 2 deletions docs/data/joy/components/table/TableSortAndSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ export default function TableSortAndSelection() {
? rows.length
: Math.min(rows.length, (page + 1) * rowsPerPage);
};
const isSelected = (name: string) => selected.indexOf(name) !== -1;
// Avoid a layout jump when reaching the last page with empty rows.
const emptyRows =
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
Expand Down Expand Up @@ -370,7 +369,7 @@ export default function TableSortAndSelection() {
.sort(getComparator(order, orderBy))
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row, index) => {
const isItemSelected = isSelected(row.name);
const isItemSelected = selected.includes(row.name);
const labelId = `enhanced-table-checkbox-${index}`;

return (
Expand Down
4 changes: 2 additions & 2 deletions docs/data/material/components/autocomplete/FixedTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function FixedTags() {
onChange={(event, newValue) => {
setValue([
...fixedOptions,
...newValue.filter((option) => fixedOptions.indexOf(option) === -1),
...newValue.filter((option) => !fixedOptions.includes(option)),
]);
}}
options={top100Films}
Expand All @@ -28,7 +28,7 @@ export default function FixedTags() {
key={key}
label={option.title}
{...tagProps}
disabled={fixedOptions.indexOf(option) !== -1}
disabled={fixedOptions.includes(option)}
/>
);
})
Expand Down
4 changes: 2 additions & 2 deletions docs/data/material/components/autocomplete/FixedTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function FixedTags() {
onChange={(event, newValue) => {
setValue([
...fixedOptions,
...newValue.filter((option) => fixedOptions.indexOf(option) === -1),
...newValue.filter((option) => !fixedOptions.includes(option)),
]);
}}
options={top100Films}
Expand All @@ -28,7 +28,7 @@ export default function FixedTags() {
key={key}
label={option.title}
{...tagProps}
disabled={fixedOptions.indexOf(option) !== -1}
disabled={fixedOptions.includes(option)}
/>
);
})
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/lists/CheckboxList.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function CheckboxList() {
<ListItemIcon>
<Checkbox
edge="start"
checked={checked.indexOf(value) !== -1}
checked={checked.includes(value)}
tabIndex={-1}
disableRipple
inputProps={{ 'aria-labelledby': labelId }}
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/lists/CheckboxList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function CheckboxList() {
<ListItemIcon>
<Checkbox
edge="start"
checked={checked.indexOf(value) !== -1}
checked={checked.includes(value)}
tabIndex={-1}
disableRipple
inputProps={{ 'aria-labelledby': labelId }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function CheckboxListSecondary() {
<Checkbox
edge="end"
onChange={handleToggle(value)}
checked={checked.indexOf(value) !== -1}
checked={checked.includes(value)}
inputProps={{ 'aria-labelledby': labelId }}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function CheckboxListSecondary() {
<Checkbox
edge="end"
onChange={handleToggle(value)}
checked={checked.indexOf(value) !== -1}
checked={checked.includes(value)}
inputProps={{ 'aria-labelledby': labelId }}
/>
}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/material/components/lists/SwitchListSecondary.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function SwitchListSecondary() {
<Switch
edge="end"
onChange={handleToggle('wifi')}
checked={checked.indexOf('wifi') !== -1}
checked={checked.includes('wifi')}
inputProps={{
'aria-labelledby': 'switch-list-label-wifi',
}}
Expand All @@ -51,7 +51,7 @@ export default function SwitchListSecondary() {
<Switch
edge="end"
onChange={handleToggle('bluetooth')}
checked={checked.indexOf('bluetooth') !== -1}
checked={checked.includes('bluetooth')}
inputProps={{
'aria-labelledby': 'switch-list-label-bluetooth',
}}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/material/components/lists/SwitchListSecondary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function SwitchListSecondary() {
<Switch
edge="end"
onChange={handleToggle('wifi')}
checked={checked.indexOf('wifi') !== -1}
checked={checked.includes('wifi')}
inputProps={{
'aria-labelledby': 'switch-list-label-wifi',
}}
Expand All @@ -51,7 +51,7 @@ export default function SwitchListSecondary() {
<Switch
edge="end"
onChange={handleToggle('bluetooth')}
checked={checked.indexOf('bluetooth') !== -1}
checked={checked.includes('bluetooth')}
inputProps={{
'aria-labelledby': 'switch-list-label-bluetooth',
}}
Expand Down
8 changes: 4 additions & 4 deletions docs/data/material/components/material-icons/SearchIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ const allIcons = Object.keys(mui)
.sort()
.map((importName) => {
let theme;
if (importName.indexOf('Outlined') !== -1) {
if (importName.includes('Outlined')) {
theme = 'Outlined';
} else if (importName.indexOf('TwoTone') !== -1) {
} else if (importName.includes('TwoTone')) {
theme = 'Two tone';
} else if (importName.indexOf('Rounded') !== -1) {
} else if (importName.includes('Rounded')) {
theme = 'Rounded';
} else if (importName.indexOf('Sharp') !== -1) {
} else if (importName.includes('Sharp')) {
theme = 'Sharp';
} else {
theme = 'Filled';
Expand Down
7 changes: 3 additions & 4 deletions docs/data/material/components/selects/MultipleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ const names = [

function getStyles(name, personName, theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
fontWeight: personName.includes(name)
? theme.typography.fontWeightMedium
: theme.typography.fontWeightRegular,
};
}

Expand Down
7 changes: 3 additions & 4 deletions docs/data/material/components/selects/MultipleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ const names = [

function getStyles(name: string, personName: string[], theme: Theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
fontWeight: personName.includes(name)
? theme.typography.fontWeightMedium
: theme.typography.fontWeightRegular,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function MultipleSelectCheckmarks() {
>
{names.map((name) => (
<MenuItem key={name} value={name}>
<Checkbox checked={personName.indexOf(name) > -1} />
<Checkbox checked={personName.includes(name)} />
<ListItemText primary={name} />
</MenuItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function MultipleSelectCheckmarks() {
>
{names.map((name) => (
<MenuItem key={name} value={name}>
<Checkbox checked={personName.indexOf(name) > -1} />
<Checkbox checked={personName.includes(name)} />
<ListItemText primary={name} />
</MenuItem>
))}
Expand Down
7 changes: 3 additions & 4 deletions docs/data/material/components/selects/MultipleSelectChip.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ const names = [

function getStyles(name, personName, theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
fontWeight: personName.includes(name)
? theme.typography.fontWeightMedium
: theme.typography.fontWeightRegular,
};
}

Expand Down
7 changes: 3 additions & 4 deletions docs/data/material/components/selects/MultipleSelectChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ const names = [

function getStyles(name: string, personName: readonly string[], theme: Theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
fontWeight: personName.includes(name)
? theme.typography.fontWeightMedium
: theme.typography.fontWeightRegular,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ const names = [

function getStyles(name, personName, theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
fontWeight: personName.includes(name)
? theme.typography.fontWeightMedium
: theme.typography.fontWeightRegular,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ const names = [

function getStyles(name: string, personName: readonly string[], theme: Theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
fontWeight: personName.includes(name)
? theme.typography.fontWeightMedium
: theme.typography.fontWeightRegular,
};
}

Expand Down
4 changes: 1 addition & 3 deletions docs/data/material/components/table/EnhancedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ export default function EnhancedTable() {
setDense(event.target.checked);
};

const isSelected = (id) => selected.indexOf(id) !== -1;

// Avoid a layout jump when reaching the last page with empty rows.
const emptyRows =
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
Expand Down Expand Up @@ -298,7 +296,7 @@ export default function EnhancedTable() {
/>
<TableBody>
{visibleRows.map((row, index) => {
const isItemSelected = isSelected(row.id);
const isItemSelected = selected.includes(row.id);
const labelId = `enhanced-table-checkbox-${index}`;

return (
Expand Down
4 changes: 1 addition & 3 deletions docs/data/material/components/table/EnhancedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ export default function EnhancedTable() {
setDense(event.target.checked);
};

const isSelected = (id: number) => selected.indexOf(id) !== -1;

// Avoid a layout jump when reaching the last page with empty rows.
const emptyRows =
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
Expand Down Expand Up @@ -329,7 +327,7 @@ export default function EnhancedTable() {
/>
<TableBody>
{visibleRows.map((row, index) => {
const isItemSelected = isSelected(row.id);
const isItemSelected = selected.includes(row.id);
const labelId = `enhanced-table-checkbox-${index}`;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import Button from '@mui/material/Button';
import Divider from '@mui/material/Divider';

function not(a, b) {
return a.filter((value) => b.indexOf(value) === -1);
return a.filter((value) => !b.includes(value));
}

function intersection(a, b) {
return a.filter((value) => b.indexOf(value) !== -1);
return a.filter((value) => b.includes(value));
}

function union(a, b) {
Expand Down Expand Up @@ -108,7 +108,7 @@ export default function SelectAllTransferList() {
>
<ListItemIcon>
<Checkbox
checked={checked.indexOf(value) !== -1}
checked={checked.includes(value)}
tabIndex={-1}
disableRipple
inputProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import Button from '@mui/material/Button';
import Divider from '@mui/material/Divider';

function not(a: readonly number[], b: readonly number[]) {
return a.filter((value) => b.indexOf(value) === -1);
return a.filter((value) => !b.includes(value));
}

function intersection(a: readonly number[], b: readonly number[]) {
return a.filter((value) => b.indexOf(value) !== -1);
return a.filter((value) => b.includes(value));
}

function union(a: readonly number[], b: readonly number[]) {
Expand Down Expand Up @@ -109,7 +109,7 @@ export default function SelectAllTransferList() {
>
<ListItemIcon>
<Checkbox
checked={checked.indexOf(value) !== -1}
checked={checked.includes(value)}
tabIndex={-1}
disableRipple
inputProps={{
Expand Down
Loading