2023-05-20 19:21:23 -07:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { ICellRendererParams } from '@ag-grid-community/core';
|
|
|
|
|
import { Group } from '@mantine/core';
|
|
|
|
|
import { RiCheckboxBlankLine, RiCheckboxLine } from 'react-icons/ri';
|
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
import { Button } from '/@/renderer/components/button';
|
|
|
|
|
import { Paper } from '/@/renderer/components/paper';
|
|
|
|
|
import { getNodesByDiscNumber, setNodeSelection } from '../utils';
|
|
|
|
|
|
|
|
|
|
const Container = styled(Paper)`
|
2023-07-01 19:10:05 -07:00
|
|
|
padding: 0.5rem 1rem;
|
|
|
|
|
border: 1px solid transparent;
|
2023-05-20 19:21:23 -07:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const FullWidthDiscCell = ({ node, data, api }: 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;
|
|
|
|
|
const discNumber = Number(node.data.id.split('-')[1]);
|
|
|
|
|
const nodes = getNodesByDiscNumber({ api, discNumber });
|
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 (
|
|
|
|
|
<Container>
|
|
|
|
|
<Group
|
|
|
|
|
position="apart"
|
|
|
|
|
w="100%"
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
compact
|
|
|
|
|
leftIcon={isSelected ? <RiCheckboxLine /> : <RiCheckboxBlankLine />}
|
|
|
|
|
size="md"
|
|
|
|
|
variant="subtle"
|
|
|
|
|
onClick={handleToggleDiscNodes}
|
|
|
|
|
>
|
|
|
|
|
{data.name}
|
|
|
|
|
</Button>
|
|
|
|
|
</Group>
|
|
|
|
|
</Container>
|
|
|
|
|
);
|
2023-05-20 19:21:23 -07:00
|
|
|
};
|