buster/web/src/components/features/layout/AppVerticalCodeSplitter/DataContainer.tsx

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-02-06 02:27:53 +08:00
import type { IDataResult } from '@/api/asset_interfaces';
2025-01-10 03:04:57 +08:00
import { createStyles } from 'antd-style';
import React from 'react';
import isEmpty from 'lodash/isEmpty';
import { AppDataGrid } from '@/components/ui/table/AppDataGrid';
import { IndeterminateLinearLoader } from '@/components/ui/loaders/IndeterminateLinearLoader';
2025-01-10 03:04:57 +08:00
export const DataContainer: React.FC<{
2025-02-06 02:27:53 +08:00
data: IDataResult;
2025-01-10 05:00:40 +08:00
fetchingData: boolean;
2025-01-10 03:04:57 +08:00
className?: string;
2025-01-10 05:00:40 +08:00
}> = React.memo(({ data, fetchingData, className }) => {
2025-01-10 03:04:57 +08:00
const { styles, cx } = useStyles();
2025-02-06 02:27:53 +08:00
const hasData = data && !isEmpty(data);
2025-01-10 03:04:57 +08:00
return (
<div className={cx(styles.container, 'relative h-full w-full overflow-hidden', className)}>
<IndeterminateLinearLoader
className={cx(
'absolute top-0 left-0 z-10 w-full',
2025-02-19 04:23:44 +08:00
fetchingData && hasData ? 'block' : 'hidden!'
)}
/>
2025-01-10 03:04:57 +08:00
{hasData ? (
2025-02-06 04:06:25 +08:00
<AppDataGrid rows={data} resizable={true} draggable={false} animate={false} />
2025-01-10 03:04:57 +08:00
) : (
2025-01-10 05:00:40 +08:00
<div className="flex h-full items-center justify-center">
{fetchingData ? 'Loading data...' : 'No data returned'}
</div>
2025-01-10 03:04:57 +08:00
)}
</div>
);
});
DataContainer.displayName = 'DataContainer';
const useStyles = createStyles(({ css, token }) => ({
container: css`
background: ${token.colorBgBase};
border-radius: ${token.borderRadius}px;
border: 0.5px solid ${token.colorBorder};
`
}));