2022-12-19 15:59:14 -08:00
|
|
|
import type { ICellRendererParams } from '@ag-grid-community/core';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2022-12-19 15:59:14 -08:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
import styled from 'styled-components';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2022-12-20 04:25:51 -08:00
|
|
|
import { Skeleton } from '/@/renderer/components/skeleton';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { Text } from '/@/renderer/components/text';
|
|
|
|
|
|
2025-05-18 14:03:18 -07:00
|
|
|
export const CellContainer = styled.div<{ $position?: 'center' | 'left' | 'right' }>`
|
2023-07-01 19:10:05 -07:00
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: ${(props) =>
|
2023-09-22 02:34:57 -07:00
|
|
|
props.$position === 'right'
|
2023-07-01 19:10:05 -07:00
|
|
|
? 'flex-end'
|
2023-09-22 02:34:57 -07:00
|
|
|
: props.$position === 'center'
|
2024-08-23 08:19:27 -07:00
|
|
|
? 'center'
|
|
|
|
|
: 'flex-start'};
|
2023-07-01 19:10:05 -07:00
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
letter-spacing: 0.5px;
|
2022-12-19 15:59:14 -08:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
type Options = {
|
2023-07-01 19:10:05 -07:00
|
|
|
array?: boolean;
|
|
|
|
|
isArray?: boolean;
|
|
|
|
|
isLink?: boolean;
|
2025-05-18 14:03:18 -07:00
|
|
|
position?: 'center' | 'left' | 'right';
|
2023-07-01 19:10:05 -07:00
|
|
|
primary?: boolean;
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const GenericCell = (
|
2023-07-01 19:10:05 -07:00
|
|
|
{ value, valueFormatted }: ICellRendererParams,
|
2025-05-18 14:03:18 -07:00
|
|
|
{ isLink, position, primary }: Options,
|
2022-12-19 15:59:14 -08:00
|
|
|
) => {
|
2023-07-01 19:10:05 -07:00
|
|
|
const displayedValue = valueFormatted || value;
|
|
|
|
|
|
|
|
|
|
if (value === undefined) {
|
|
|
|
|
return (
|
2023-09-22 02:34:57 -07:00
|
|
|
<CellContainer $position={position || 'left'}>
|
2023-07-01 19:10:05 -07:00
|
|
|
<Skeleton
|
|
|
|
|
height="1rem"
|
|
|
|
|
width="80%"
|
|
|
|
|
/>
|
|
|
|
|
</CellContainer>
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2022-12-20 04:25:51 -08:00
|
|
|
return (
|
2023-09-22 02:34:57 -07:00
|
|
|
<CellContainer $position={position || 'left'}>
|
2023-07-01 19:10:05 -07:00
|
|
|
{isLink ? (
|
|
|
|
|
<Text
|
|
|
|
|
$link={isLink}
|
|
|
|
|
$secondary={!primary}
|
|
|
|
|
component={Link}
|
|
|
|
|
overflow="hidden"
|
|
|
|
|
size="md"
|
|
|
|
|
to={displayedValue.link}
|
|
|
|
|
>
|
|
|
|
|
{isLink ? displayedValue.value : displayedValue}
|
|
|
|
|
</Text>
|
|
|
|
|
) : (
|
|
|
|
|
<Text
|
2023-09-22 02:34:57 -07:00
|
|
|
$noSelect={false}
|
2023-07-01 19:10:05 -07:00
|
|
|
$secondary={!primary}
|
|
|
|
|
overflow="hidden"
|
|
|
|
|
size="md"
|
|
|
|
|
>
|
|
|
|
|
{displayedValue}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</CellContainer>
|
2022-12-20 04:25:51 -08:00
|
|
|
);
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GenericCell.defaultProps = {
|
2023-07-01 19:10:05 -07:00
|
|
|
position: undefined,
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|