import { makeStyles, Theme, Typography, Chip, Tooltip, } from '@material-ui/core'; import { useContext } from 'react'; import { useParams } from 'react-router-dom'; import AttuGrid from '@/components/grid/Grid'; import { ColDefinitionsType } from '@/components/grid/Types'; import { useTranslation } from 'react-i18next'; import icons from '@/components/icons/Icons'; import { formatFieldType } from '@/utils'; import { rootContext, dataContext } from '@/context'; import IndexTypeElement from './IndexTypeElement'; import { getLabelDisplayedRows } from '../../../search/Utils'; import { LOADING_STATE } from '@/consts'; import LoadCollectionDialog from '@/pages/dialogs/LoadCollectionDialog'; import ReleaseCollectionDialog from '@/pages/dialogs/ReleaseCollectionDialog'; import StatusAction from '@/pages/databases/collections/StatusAction'; import CustomButton from '@/components/customButton/CustomButton'; const useStyles = makeStyles((theme: Theme) => ({ wrapper: { display: 'flex', flexDirection: 'column', flexGrow: 1, height: `100%`, overflow: 'auto', '& h5': { color: theme.palette.attuGrey.dark, marginBottom: theme.spacing(0.5), fontSize: '14px', fontWeight: 400, }, }, infoWrapper: { marginBottom: theme.spacing(2), paddingTop: theme.spacing(0.5), }, block: { '& *': { fontSize: '14px', lineHeight: 1.5, }, paddingBottom: theme.spacing(2), }, icon: { fontSize: '20px', marginLeft: theme.spacing(0.5), }, primaryKeyChip: { fontSize: '8px', position: 'relative', top: '3px', color: 'grey', }, chip: { marginLeft: theme.spacing(0.5), marginRight: theme.spacing(0.5), fontSize: '12px', background: 'rgba(0, 0, 0, 0.04)', border: 'none', }, featureChip: { marginLeft: 0, border: 'none', }, nameWrapper: { display: 'flex', alignItems: 'center', '& .key': { width: '16px', height: '16px', marginLeft: theme.spacing(0.5), }, }, refreshBtn: { color: theme.palette.attuGrey.main, cursor: 'pointer', minWidth: 0, minHeight: 0, padding: theme.spacing(0.5), alignSelf: 'center', '& svg': { width: 15, }, }, paramWrapper: { // set min width to prevent other table cell stretching minWidth: 180, '& .param': { marginRight: theme.spacing(2), '& .key': { color: theme.palette.attuGrey.dark, display: 'inline-block', marginRight: theme.spacing(0.5), }, '& .value': { color: theme.palette.attuDark.main, }, }, }, gridWrapper: { paddingBottom: theme.spacing(2), }, })); const Overview = () => { const { setDialog } = useContext(rootContext); const { fetchCollection, collections, loading } = useContext(dataContext); const { collectionName = '' } = useParams<{ collectionName: string }>(); const classes = useStyles(); const { t: collectionTrans } = useTranslation('collection'); const { t: indexTrans } = useTranslation('index'); const { t: commonTrans } = useTranslation(); const gridTrans = commonTrans('grid'); const consistencyTooltipsMap: Record = { Strong: collectionTrans('consistencyStrongTooltip'), Bounded: collectionTrans('consistencyBoundedTooltip'), Session: collectionTrans('consistencySessionTooltip'), Eventually: collectionTrans('consistencyEventuallyTooltip'), }; // get collection const collection = collections.find( c => c.collection_name === collectionName ); // get fields const fields = collection?.schema?.fields || []; const KeyIcon = icons.key; const EnabledIcon = icons.check; const RefreshIcon = icons.refresh; // refresh collection const refreshCollection = async () => { await fetchCollection(collectionName); }; const colDefinitions: ColDefinitionsType[] = [ { id: 'name', align: 'left', disablePadding: true, formatter(f) { return (
{f.name} {f.is_primary_key ? (
) : null} {f.is_partition_key ? ( ) : null} {f.autoID ? ( ) : null}
); }, label: collectionTrans('fieldName'), sortBy: 'name', }, { id: 'data_type', align: 'left', disablePadding: false, formatter(f) { return formatFieldType(f); }, label: collectionTrans('fieldType'), }, { id: 'name', align: 'left', disablePadding: true, label: indexTrans('indexName'), formatter(f) { return f.index?.index_name; }, }, { id: 'name', align: 'left', disablePadding: true, label: indexTrans('type'), notSort: true, formatter(f) { return ( { await fetchCollection(collectionName); }} /> ); }, }, { id: 'name', align: 'left', disablePadding: false, label: indexTrans('param'), notSort: true, formatter(f) { return f.index ? (
{f.index.indexParameterPairs.length > 0 ? ( f.index.indexParameterPairs.map((p: any) => p.value ? ( {`${p.key}:`} {p.value} ) : ( '' ) ) ) : ( <>-- )}
) : ( <>-- ); }, }, { id: 'description', align: 'left', disablePadding: false, label: indexTrans('desc'), }, ]; // get loading state label return (
{collection && (
{collectionTrans('status')} { setDialog({ open: true, type: 'custom', params: { component: collection.status === LOADING_STATE.UNLOADED ? ( ) : ( ), }, }); }} />
{collectionTrans('rowCount')} {collection?.rowCount || '--'}
{collectionTrans('description')} {collection?.description || '--'}
{collectionTrans('consistency')}
{collectionTrans('createdTime')} {new Date(collection.createdTime).toLocaleString()}
)}
{collectionTrans('schema')} {collection && collection.schema && collection.schema.enable_dynamic_field ? ( } /> ) : null} 1 ? 'fields' : 'field'] )} />
); }; export default Overview;