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

[NoQA] Fix type errors in SelectionList.stories.tsx #38139

Merged
merged 1 commit into from
Mar 12, 2024
Merged
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
29 changes: 22 additions & 7 deletions src/stories/SelectionList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function WithTextInput(props: BaseSelectionListProps<ListItem>) {

const sections = props.sections.map((section) => {
const data = section.data.reduce<ListItem[]>((memo, item, index) => {
if (!item.text.toLowerCase().includes(searchText.trim().toLowerCase())) {
if (!item.text?.toLowerCase().includes(searchText.trim().toLowerCase())) {
return memo;
}

Expand Down Expand Up @@ -221,8 +221,10 @@ function MultipleSelection(props: BaseSelectionListProps<ListItem>) {

const sections = props.sections.map((section) => {
const data = section.data.map((item, index) => {
allIds.push(item.keyForList);
const isSelected = selectedIds.includes(item.keyForList);
if (item.keyForList) {
allIds.push(item.keyForList);
}
const isSelected = item.keyForList ? selectedIds.includes(item.keyForList) : false;
const isAdmin = index + (section?.indexOffset ?? 0) === 0;

return {
Expand All @@ -248,6 +250,9 @@ function MultipleSelection(props: BaseSelectionListProps<ListItem>) {
}, [props.sections, selectedIds]);

const onSelectRow = (item: ListItem) => {
if (!item.keyForList) {
return;
}
const newSelectedIds = selectedIds.includes(item.keyForList) ? selectedIds.filter((id) => id !== item.keyForList) : [...selectedIds, item.keyForList];
setSelectedIds(newSelectedIds);
};
Expand Down Expand Up @@ -286,8 +291,10 @@ function WithSectionHeader(props: BaseSelectionListProps<ListItem>) {

const sections = props.sections.map((section, sectionIndex) => {
const data = section.data.map((item, itemIndex) => {
allIds.push(item.keyForList);
const isSelected = selectedIds.includes(item.keyForList);
if (item.keyForList) {
allIds.push(item.keyForList);
}
const isSelected = item.keyForList ? selectedIds.includes(item.keyForList) : false;
const isAdmin = itemIndex + (section?.indexOffset ?? 0) === 0;

return {
Expand All @@ -313,6 +320,9 @@ function WithSectionHeader(props: BaseSelectionListProps<ListItem>) {
}, [props.sections, selectedIds]);

const onSelectRow = (item: ListItem) => {
if (!item.keyForList) {
return;
}
const newSelectedIds = selectedIds.includes(item.keyForList) ? selectedIds.filter((id) => id !== item.keyForList) : [...selectedIds, item.keyForList];
setSelectedIds(newSelectedIds);
};
Expand Down Expand Up @@ -349,8 +359,10 @@ function WithConfirmButton(props: BaseSelectionListProps<ListItem>) {

const sections = props.sections.map((section, sectionIndex) => {
const data = section.data.map((item, itemIndex) => {
allIds.push(item.keyForList);
const isSelected = selectedIds.includes(item.keyForList);
if (item.keyForList) {
allIds.push(item.keyForList);
}
const isSelected = item.keyForList ? selectedIds.includes(item.keyForList) : false;
const isAdmin = itemIndex + (section.indexOffset ?? 0) === 0;

return {
Expand All @@ -376,6 +388,9 @@ function WithConfirmButton(props: BaseSelectionListProps<ListItem>) {
}, [props.sections, selectedIds]);

const onSelectRow = (item: ListItem) => {
if (!item.keyForList) {
return;
}
const newSelectedIds = selectedIds.includes(item.keyForList) ? selectedIds.filter((id) => id !== item.keyForList) : [...selectedIds, item.keyForList];
setSelectedIds(newSelectedIds);
};
Expand Down
Loading