-
Notifications
You must be signed in to change notification settings - Fork 221
feat(DataTableToolbar): add reusable toolbar component for Meshery UI migration #1664
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
Open
Uday9909
wants to merge
2
commits into
layer5io:master
Choose a base branch
from
Uday9909:feat/datatable-toolbar
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+154
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import React from 'react'; | ||
|
|
||
| import { DataTableToolbar } from '../custom/DataTableToolbar'; | ||
| import { SistentThemeProvider } from '../theme'; | ||
|
|
||
| const renderWithTheme = (ui: React.ReactElement) => | ||
| render(<SistentThemeProvider>{ui}</SistentThemeProvider>); | ||
|
|
||
| describe('DataTableToolbar', () => { | ||
| it('renders primaryActions content', () => { | ||
| renderWithTheme(<DataTableToolbar primaryActions={<button>Add</button>} />); | ||
| expect(screen.getByRole('button', { name: 'Add' })).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders secondaryActions content', () => { | ||
| renderWithTheme(<DataTableToolbar secondaryActions={<button>Export</button>} />); | ||
| expect(screen.getByRole('button', { name: 'Export' })).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders search slot', () => { | ||
| renderWithTheme(<DataTableToolbar search={<input placeholder="Search" />} />); | ||
| expect(screen.getByPlaceholderText('Search')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders filter slot', () => { | ||
| renderWithTheme(<DataTableToolbar filter={<div>Filter</div>} />); | ||
| expect(screen.getByText('Filter')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders columnVisibility slot', () => { | ||
| renderWithTheme(<DataTableToolbar columnVisibility={<div>Columns</div>} />); | ||
| expect(screen.getByText('Columns')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders viewSwitch slot', () => { | ||
| renderWithTheme(<DataTableToolbar viewSwitch={<div>Grid/Table</div>} />); | ||
| expect(screen.getByText('Grid/Table')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders all slots simultaneously', () => { | ||
| renderWithTheme( | ||
| <DataTableToolbar | ||
| primaryActions={<button>Add</button>} | ||
| search={<input placeholder="Search" />} | ||
| filter={<div>Filter</div>} | ||
| /> | ||
| ); | ||
| expect(screen.getByRole('button', { name: 'Add' })).toBeTruthy(); | ||
| expect(screen.getByPlaceholderText('Search')).toBeTruthy(); | ||
| expect(screen.getByText('Filter')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders without any props (empty state)', () => { | ||
| const { container } = renderWithTheme(<DataTableToolbar />); | ||
| expect(container.firstChild).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('applies custom sx styles', () => { | ||
| const { container } = renderWithTheme(<DataTableToolbar sx={{ marginTop: '32px' }} />); | ||
| const root = container.firstChild as HTMLElement; | ||
| expect(root).toHaveStyle('margin-top: 32px'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { Box } from '../../base'; | ||
| import { styled } from '../../theme'; | ||
| import type { DataTableToolbarProps } from './DataTableToolbar.types'; | ||
|
|
||
| const ToolbarRoot = styled(Box)(({ theme }) => ({ | ||
| display: 'flex', | ||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| marginBottom: theme.spacing(4), | ||
| minHeight: theme.spacing(8), | ||
| padding: theme.spacing(1.5), | ||
| backgroundColor: theme.palette.background.card, | ||
| borderRadius: theme.spacing(1), | ||
| boxShadow: theme.shadows[2], | ||
|
|
||
| [theme.breakpoints.down('sm')]: { | ||
| height: 'auto', | ||
| flexWrap: 'wrap', | ||
| padding: theme.spacing(1), | ||
| gap: theme.spacing(1) | ||
| } | ||
| })); | ||
|
|
||
| const Section = styled(Box)(({ theme }) => ({ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: theme.spacing(1) | ||
| })); | ||
|
Uday9909 marked this conversation as resolved.
|
||
|
|
||
| export function DataTableToolbar({ | ||
| primaryActions, | ||
| secondaryActions, | ||
| search, | ||
| filter, | ||
| columnVisibility, | ||
| viewSwitch, | ||
| sx | ||
| }: DataTableToolbarProps): JSX.Element { | ||
| const hasLeftContent = Boolean(primaryActions) || Boolean(secondaryActions); | ||
| const hasRightContent = | ||
| Boolean(filter) || Boolean(search) || Boolean(columnVisibility) || Boolean(viewSwitch); | ||
|
|
||
| return ( | ||
| <ToolbarRoot sx={sx}> | ||
| {hasLeftContent && ( | ||
| <Section> | ||
| {primaryActions} | ||
| {secondaryActions} | ||
| </Section> | ||
| )} | ||
| {hasRightContent && ( | ||
| <Section> | ||
| {filter} | ||
| {search} | ||
| {columnVisibility} | ||
| {viewSwitch} | ||
| </Section> | ||
| )} | ||
| </ToolbarRoot> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { SxProps, Theme } from '@mui/material'; | ||
|
|
||
| export interface DataTableToolbarProps { | ||
| /** Left side: primary action buttons (Add, Create, Import) */ | ||
| primaryActions?: React.ReactNode; | ||
|
|
||
| /** Left side next to primary: secondary actions (Export, bulk delete) */ | ||
| secondaryActions?: React.ReactNode; | ||
|
|
||
| /** Right side: SearchBar component */ | ||
| search?: React.ReactNode; | ||
|
|
||
| /** Right side: UniversalFilter component */ | ||
| filter?: React.ReactNode; | ||
|
|
||
| /** Right side: Column visibility control */ | ||
| columnVisibility?: React.ReactNode; | ||
|
|
||
| /** Right side: Grid/table view toggle */ | ||
| viewSwitch?: React.ReactNode; | ||
|
|
||
| /** Custom styles for migration compatibility */ | ||
| sx?: SxProps<Theme>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { DataTableToolbar } from './DataTableToolbar'; | ||
| export type { DataTableToolbarProps } from './DataTableToolbar.types'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.