Skip to content

Commit

Permalink
Tables route styling
Browse files Browse the repository at this point in the history
  • Loading branch information
joncombe committed Jan 26, 2024
1 parent 2b4c3dd commit a96fd54
Show file tree
Hide file tree
Showing 8 changed files with 479 additions and 319 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Added responsive styling to the tables page

## 2024-01-25 - 0.2.0

- Added a cluster overview page with overall cluster stats.
Expand Down
4 changes: 2 additions & 2 deletions src/components/StatusBar/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function StatusBar() {
return (
<>
<div
className="gap-3 flex leading-tight text-white md:hidden"
className="gap-3 flex leading-tight select-none text-white md:hidden"
onClick={() => setMobileVisible(true)}
>
<div>
Expand All @@ -127,7 +127,7 @@ function StatusBar() {
<DownOutlined className="opacity-50 text-xs" />
</div>
</div>
<div className="hidden gap-8 leading-snug text-white md:flex">
<div className="hidden gap-8 leading-snug select-none text-white md:flex">
<div>
<div className="opacity-50 text-xs uppercase">Cluster</div>
<div>{spin(cluster?.name)}</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/StatusBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import StatusBar from './StatusBar';

export default StatusBar;
2 changes: 2 additions & 0 deletions src/constants/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
// -------------------------------------
export const SHORT_MESSAGE_NOTIFICATION_DURATION = 7;
export const LONG_MESSAGE_NOTIFICATION_DURATION = 15;

export const TAILWIND_BREAKPOINT_MD = 768;
8 changes: 2 additions & 6 deletions src/constants/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SQLConsole from '../routes/SQLConsole/SQLConsole';
import Users from '../routes/Users/Users';
import EnterpriseScreen from '../components/EnterpriseScreen/EnterpriseScreen';
import Tables from '../routes/Tables/Tables';
import Tables from '../routes/Tables';
import { Route } from '../types';
import ScheduledJobs from '../routes/JobScheduler';
import Overview from '../routes/Overview/Overview.tsx';
Expand Down Expand Up @@ -29,11 +29,7 @@ const routes: Route[] = [
},
{
path: '/tables',
element: (
<div className="p-4">
<Tables />
</div>
),
element: <Tables />,
label: 'Tables',
key: 'tables',
},
Expand Down
139 changes: 139 additions & 0 deletions src/routes/Tables/TableDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { LeftOutlined } from '@ant-design/icons';
import { Button, Heading } from '@crate.io/crate-ui-components';
import { Table, Tabs, Tag } from 'antd';
import { useGCContext } from '../../contexts';
import routes from '../../constants/routes';
import { format as formatSQL } from 'sql-formatter';
import {
getTableInformation,
showCreateTable,
TableInfo,
TableListEntry,
} from '../../utils/queries';

function TableDetail({
activeTable,
setActiveTable,
systemSchemas,
}: {
activeTable: TableListEntry | undefined;
setActiveTable: (table: TableListEntry | undefined) => void;
systemSchemas: string[];
}) {
const { sqlUrl } = useGCContext();
const [activeTableInfo, setActiveTableInfo] = useState<TableInfo[] | undefined>();
const [createTableSQL, setCreateTableSQL] = useState<string | undefined>();

useEffect(() => {
if (!activeTable) {
setActiveTableInfo(undefined);
return;
}

getTableInformation(
sqlUrl,
activeTable.table_schema,
activeTable.table_name,
).then(setActiveTableInfo);

setCreateTableSQL(undefined);
if (!systemSchemas.includes(activeTable.table_schema)) {
showCreateTable(sqlUrl, activeTable.table_schema, activeTable.table_name).then(
res => setCreateTableSQL(res ? formatSQL(res) : undefined),
);
}
}, [activeTable]);

const columns = [
{
title: '#',
key: 'ordinal_position',
dataIndex: 'ordinal_position',
width: '5%',
},
{
title: 'Name',
key: 'column_name',
dataIndex: 'column_name',
width: '25%',
render: (_: string, record: TableInfo) => {
return (
<span>
{record.column_name}{' '}
{record.constraint_type ? <Tag>{record.constraint_type}</Tag> : null}
</span>
);
},
},
{
title: 'Type',
key: 'data_type',
dataIndex: 'data_type',
width: '70%',
render: (dataType: string) => {
return <span>{dataType.toUpperCase()}</span>;
},
},
];

const tabs = [
{
key: 'columns',
label: 'Columns',
children: (
<Table
columns={columns}
dataSource={activeTableInfo}
rowKey="ordinal_position"
pagination={false}
/>
),
},
];

if (createTableSQL) {
tabs.push({
key: 'SQL',
label: 'SQL',
children: (
<div className="">
<pre>{createTableSQL}</pre>
</div>
),
});
}

return (
<div>
{activeTable && (
<>
<div
className="block text-crate-blue md:hidden"
onClick={() => setActiveTable(undefined)}
>
<LeftOutlined className="text-xs" /> Back to list
</div>
<Heading level="h2">
{activeTable.table_schema}.{activeTable.table_name}
</Heading>
<Tabs defaultActiveKey="columns" items={tabs} />
<div className="mt-4">
<Link
to={{
pathname: routes.find(r => r.key == 'sql')?.path,
search: `?q=SELECT * FROM "${activeTable.table_schema}"."${activeTable.table_name}" LIMIT 100;`,
}}
>
<Button kind="primary">Query</Button>
</Link>
</div>
</>
)}
{!activeTable && <div>No table selected</div>}
</div>
);
}

export default TableDetail;
Loading

0 comments on commit a96fd54

Please sign in to comment.