Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding sortable tables #6338

Open
wants to merge 15 commits into
base: current
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions website/snippets/_enterprise-permissions-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@
Account roles enable you to manage the dbt Cloud account and manage the account settings (for example, generating service tokens, inviting users, and configuring SSO). They also provide project-level permissions. The **Account Admin** role is the highest level of access you can assign.

#### Account permissions for account roles
| Account-level permission| Account Admin | Billing admin | Manage <br></br> marketplace <br></br> apps | Project creator | Security admin | Viewer |
|:-------------------------|:-------------:|:------------:|:-------------------------:|:---------------:|:--------------:|:------:|
| Account settings | W | | | R | R | R |
| Audit logs | R | | | | R | R |
| Auth provider | W | | | | W | R |
| Billing | W | W | | | | R |
| Connections | W | | | W | | |
| Groups | W | | | R | W | R |
| Invitations | W | | | W | W | R |
| IP restrictions | W | | | | W | R |
| Licenses | W | | | W | W | R |
| Marketplace app | | | W | | | |
| Members | W | | | W | W | R |
| Project (create) | W | | | W | | |
| Public models | R | R | | R | R | R |
| Service tokens | W | | | | R | R |
| Webhooks | W | | | | | |

<SortableTable columnAlignments={['center', 'center', 'center','center', 'center', 'center','center']} >
{`
| Account-level permission| Account Admin | Billing admin | Manage marketplace apps | Project creator | Security admin | Viewer |
| Account settings | W | - | - | R | R | R |

Check warning on line 20 in website/snippets/_enterprise-permissions-table.md

View workflow job for this annotation

GitHub Actions / vale

[vale] website/snippets/_enterprise-permissions-table.md#L20

[custom.UIElements] UI elements like 'Account settings' should be bold.
Raw output
{"message": "[custom.UIElements] UI elements like 'Account settings' should be bold.", "location": {"path": "website/snippets/_enterprise-permissions-table.md", "range": {"start": {"line": 20, "column": 3}}}, "severity": "WARNING"}
| Audit logs | R | - | - | - | R | R |
| Auth provider | W | - | - | - | W | R |
| Billing | W | W | - | - | - | R |
| Connections | W | - | - | W | - | - |
| Groups | W | - | - | R | W | R |
| Invitations | W | - | - | W | W | R |
| IP restrictions | W | - | - | - | W | R |
| Licenses | W | - | - | W | W | R |
| Marketplace app | - | - | W | - | - | - |
| Members | W | - | - | W | W | R |
| Project (create) | W | - | - | W | - | - |
| Public models | R | R | - | R | R | R |
| Service tokens | W | - | - | - | R | R |
| Webhooks | W | - | - | - | - | - |
`}
</SortableTable>

#### Project permissions for account roles

Expand Down
73 changes: 73 additions & 0 deletions website/src/components/sortableTable/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { useState } from 'react';

const parseMarkdownTable = (markdown) => {
const rows = markdown.trim().split('\n');
const headers = rows[0].split('|').map((header) => header.trim()).filter(Boolean);
const data = rows.slice(1).map(row => row.split('|').map(cell => cell.trim()).filter(Boolean));
return { headers, data };
};

const SortableTable = ({ children, columnAlignments }) => {
const { headers, data: initialData } = parseMarkdownTable(children);

const [data, setData] = useState(initialData);
const [sortConfig, setSortConfig] = useState({ key: '', direction: 'asc' });

const sortTable = (keyIndex) => {
const newDirection = (sortConfig.key === keyIndex && sortConfig.direction === 'asc') ? 'desc' : 'asc';
setSortConfig({ key: keyIndex, direction: newDirection });

const sortedData = [...data].sort((a, b) => {
const aVal = a[keyIndex];
const bVal = b[keyIndex];
if (aVal < bVal) return newDirection === 'asc' ? -1 : 1;
if (aVal > bVal) return newDirection === 'asc' ? 1 : -1;
return 0;
});

setData(sortedData);
};

return (
<table>
<thead>
<tr>
{headers.map((header, index) => (
<th
key={index}
onClick={() => sortTable(index)}
style={{ cursor: 'pointer', position: 'relative', textAlign: columnAlignments[index] || 'left', padding: '10px' }} // Apply alignment
>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: columnAlignments[index] === 'center' ? 'center' : columnAlignments[index] }}>
<span style={{ marginRight: '5px' }}>{header}</span>
{/* Always show both carets */}
<span style={{
opacity: sortConfig.key === index && sortConfig.direction === 'asc' ? 1 : (sortConfig.key === index ? 0.5 : 0.5)
}}>
</span>
<span style={{
marginLeft: '5px',
opacity: sortConfig.key === index && sortConfig.direction === 'desc' ? 1 : (sortConfig.key === index ? 0.5 : 0.5)
}}>
</span>
</div>
</th>
))}
</tr>
</thead>
<tbody>
{data.map((row, rowIndex) => (
<tr key={rowIndex}>
{row.map((cell, cellIndex) => (
<td key={cellIndex} style={{ textAlign: columnAlignments[cellIndex] || 'left', padding: '8px' }}>{cell || '\u00A0'}</td> // Apply alignment to cells
))}
</tr>
))}
</tbody>
</table>
);
};

export default SortableTable;
2 changes: 2 additions & 0 deletions website/src/theme/MDXComponents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Mermaid from '@theme/Mermaid';
/* dbt Customizations:
* Imports the following components below for export
*/
import SortableTable from '@site/src/components/SortableTable';
matthewshaver marked this conversation as resolved.
Show resolved Hide resolved
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem'
import Changelog from '@site/src/components/changelog';
Expand Down Expand Up @@ -95,5 +96,6 @@ const MDXComponents = {
DetailsToggle: DetailsToggle,
Expandable: Expandable,
ConfettiTrigger: ConfettiTrigger,
SortableTable: SortableTable,
};
export default MDXComponents;
Loading