Skip to content

Commit

Permalink
fix type errors in SelectionList.stories.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
JKobrynski committed Mar 12, 2024
1 parent 4ac2dd7 commit 6c34c11
Showing 1 changed file with 22 additions and 7 deletions.
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

0 comments on commit 6c34c11

Please sign in to comment.