Skip to content
Snippets Groups Projects
index.tsx 1.15 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jacopo Gasparetto's avatar
    Jacopo Gasparetto committed
    import { Page } from '../../components/Page';
    
    import { Table } from '../../components/Table';
    
    import { useContext } from 'react';
    
    import { BucketInfo } from '../../models/bucket';
    import { getHumanSize, parseReadWriteAccess } from '../../commons/utils';
    
    import { BucketsListContext } from '../../services/BucketListContext';
    import './index.css';
    
    Jacopo Gasparetto's avatar
    Jacopo Gasparetto committed
    
    export const Home = () => {
    
      const onClick = (element: React.MouseEvent<HTMLTableRowElement>, index: number) => {
        const bucketName = element.currentTarget.firstChild?.textContent;
        console.log(bucketName);
      }
    
    
      const columns = ["Bucket", "Objects", "Size", "Access"];
    
    
      const bucketList = useContext(BucketsListContext).map((bucket: BucketInfo) => {
        return [
          bucket.name,
          bucket.objects,
          getHumanSize(bucket.size),
          parseReadWriteAccess(bucket.rw_access)
        ]
      });
    
    Jacopo Gasparetto's avatar
    Jacopo Gasparetto committed
      return (
    
        <Page title="Home">
    
          <div className="Home">
    
            <div className="flex place-content-center">
    
              <Table
                className="table-auto w-2/3"
                columns={columns}
                data={bucketList}
                onClick={onClick}
              />
    
    Jacopo Gasparetto's avatar
    Jacopo Gasparetto committed
        </Page>
      );
    }