feishin/src/renderer/components/virtual-table/cells/full-width-disc-cell.tsx

44 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-05-20 19:21:23 -07:00
import { ICellRendererParams } from '@ag-grid-community/core';
import { useState } from 'react';
import styles from './full-width-disc-cell.module.css';
2023-05-20 19:21:23 -07:00
import { getNodesByDiscNumber, setNodeSelection } from '/@/renderer/components/virtual-table/utils';
import { Button } from '/@/shared/components/button/button';
import { Group } from '/@/shared/components/group/group';
import { Icon } from '/@/shared/components/icon/icon';
2023-05-20 19:21:23 -07:00
export const FullWidthDiscCell = ({ api, data, node }: ICellRendererParams) => {
2023-07-01 19:10:05 -07:00
const [isSelected, setIsSelected] = useState(false);
2023-05-20 19:21:23 -07:00
2023-07-01 19:10:05 -07:00
const handleToggleDiscNodes = () => {
if (!data) return;
2024-08-25 21:34:43 -07:00
const split: string[] = node.data.id.split('-');
const discNumber = Number(split[1]);
// the subtitle could have '-' in it; make sure to have all remaining items
const subtitle = split.length === 3 ? split.slice(2).join('-') : null;
const nodes = getNodesByDiscNumber({ api, discNumber, subtitle });
2023-05-20 19:21:23 -07:00
2023-07-01 19:10:05 -07:00
setNodeSelection({ isSelected: !isSelected, nodes });
setIsSelected((prev) => !prev);
};
2023-05-20 19:21:23 -07:00
2023-07-01 19:10:05 -07:00
return (
<div className={styles.container}>
2023-07-01 19:10:05 -07:00
<Group
justify="space-between"
2023-07-01 19:10:05 -07:00
w="100%"
>
<Button
leftSection={isSelected ? <Icon icon="squareCheck" /> : <Icon icon="square" />}
onClick={handleToggleDiscNodes}
size="compact-md"
2023-07-01 19:10:05 -07:00
variant="subtle"
>
{data.name}
</Button>
</Group>
</div>
2023-07-01 19:10:05 -07:00
);
2023-05-20 19:21:23 -07:00
};