Skip to content

Commit

Permalink
chore: remove unused props
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed Feb 7, 2024
1 parent f2e4662 commit 2c1471c
Showing 1 changed file with 11 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,19 @@ interface SwitcherProps {
}

export interface TableColumnSetupProps {
// for Button
disabled?: boolean;
/**
* @deprecated Use renderSwitcher instead
*/
switcher?: React.ReactElement | undefined;
renderSwitcher?: (props: SwitcherProps) => React.ReactElement | undefined;

// for List
items: Item[];
itemsHeight?: number | ((items: Item[]) => number);
sortable?: boolean;
filterable?: boolean;

onUpdate: (updated: Item[]) => void;
popupWidth?: number | string;
popupPlacement?: PopperPlacement;
getItemTitle?: (item: Item) => TableColumnSetupItem['title'];
showStatus?: boolean;
className?: string;
}

export const TableColumnSetup = (props: TableColumnSetupProps) => {
const {
switcher,
renderSwitcher,
disabled,
popupWidth,
popupPlacement,
className,
items: propsItems,
itemsHeight,
getItemTitle = (item: Item) => item.title,
sortable = true,
filterable = false,
showStatus,
} = props;
const {renderSwitcher, popupWidth, popupPlacement, items: propsItems, sortable = true} = props;

const [focused, setFocused] = React.useState(false);
const [items, setItems] = React.useState<Item[]>([]);
Expand Down Expand Up @@ -97,27 +73,13 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {
};

const getListHeight = (list: Item[]) => {
if (typeof itemsHeight === 'function') {
return itemsHeight(list);
} else if (typeof itemsHeight === 'number') {
return itemsHeight;
} else {
return Math.min(5, list.length) * LIST_ITEM_HEIGHT + LIST_ITEM_HEIGHT / 2;
}
return Math.min(5, list.length) * LIST_ITEM_HEIGHT + LIST_ITEM_HEIGHT / 2;
};

const getRequiredListHeight = (list: Item[]) => {
if (typeof itemsHeight === 'function') {
return itemsHeight(list);
} else if (typeof itemsHeight === 'number') {
return itemsHeight;
} else {
return list.length * LIST_ITEM_HEIGHT;
}
return list.length * LIST_ITEM_HEIGHT;
};

const getCountSelected = () => items.reduce((acc, cur) => (cur.selected ? acc + 1 : acc), 0);

const makeOnSortEnd =
(list: Item[]) =>
({oldIndex, newIndex}: {oldIndex: number; newIndex: number}) => {
Expand All @@ -129,12 +91,10 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {
const handleClosePopup = () => setInitialState();

const handleControlClick = React.useCallback(() => {
if (!disabled) {
setFocused(!focused);
setRequiredItems(getRequiredItems(items));
setCurrentItems(getConfigurableItems(items));
}
}, [disabled, focused, items]);
setFocused(!focused);
setRequiredItems(getRequiredItems(items));
setCurrentItems(getConfigurableItems(items));
}, [focused, items]);

const handleApplyClick = () => {
setInitialState();
Expand Down Expand Up @@ -165,23 +125,11 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {
<Icon data={Check} className={b('tick')} width={10} height={10} />
</div>
)}
<div className={b('title')}>{getItemTitle(item)}</div>
<div className={b('title')}>{item.title}</div>
</div>
);
};

const renderStatus = () => {
if (!showStatus) {
return null;
}

const selected = getCountSelected();
const all = propsItems.length;
const status = `${selected}/${all}`;

return <span className={b('status')}>{status}</span>;
};

const renderRequiredColumns = () => {
const hasRequiredColumns = requiredItems.length;

Expand All @@ -194,7 +142,6 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {
items={requiredItems}
itemHeight={LIST_ITEM_HEIGHT}
itemsHeight={getRequiredListHeight}
filterable={filterable}
renderItem={renderItem}
itemsClassName={b('items')}
itemClassName={b('item')}
Expand All @@ -210,7 +157,6 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {
itemHeight={LIST_ITEM_HEIGHT}
itemsHeight={getListHeight}
sortable={sortable}
filterable={filterable}
sortHandleAlign={'right'}
onSortEnd={makeOnSortEnd(currentItems)}
onItemClick={handleItemClick}
Expand All @@ -233,19 +179,18 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {
);

return (
<div className={b(null, className)}>
<div className={b(null)}>
{/* FIXME remove switcher prop and this wrapper */}
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div
className={b('control')}
ref={refControl}
{...(renderSwitcher ? {} : switcherProps)}
>
{renderSwitcher?.(switcherProps) || switcher || (
<Button disabled={disabled}>
{renderSwitcher?.(switcherProps) || (
<Button>
<Icon data={Gear} />
{i18n('button_switcher')}
{renderStatus()}
</Button>
)}
</div>
Expand Down

0 comments on commit 2c1471c

Please sign in to comment.