Skip to content

Commit

Permalink
reorganize package folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Jan 18, 2024
1 parent 6b9b6d7 commit 0799d4b
Show file tree
Hide file tree
Showing 85 changed files with 461 additions and 482 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,11 @@ function useUpdateUsers() {
},
//client side optimistic update
onMutate: (newUsers: User[]) => {
queryClient.setQueryData(
['users'],
(prevUsers: any) =>
prevUsers?.map((user: User) => {
const newUser = newUsers.find((u) => u.id === user.id);
return newUser ? newUser : user;
}),
queryClient.setQueryData(['users'], (prevUsers: any) =>
prevUsers?.map((user: User) => {
const newUser = newUsers.find((u) => u.id === user.id);
return newUser ? newUser : user;
}),
);
},
// onSettled: () => queryClient.invalidateQueries({ queryKey: ['users'] }), //refetch users after mutation, disabled for demo
Expand All @@ -321,10 +319,8 @@ function useDeleteUser() {
},
//client side optimistic update
onMutate: (userId: string) => {
queryClient.setQueryData(
['users'],
(prevUsers: any) =>
prevUsers?.filter((user: User) => user.id !== userId),
queryClient.setQueryData(['users'], (prevUsers: any) =>
prevUsers?.filter((user: User) => user.id !== userId),
);
},
// onSettled: () => queryClient.invalidateQueries({ queryKey: ['users'] }), //refetch users after mutation, disabled for demo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,10 @@ function useUpdateUser() {
},
//client side optimistic update
onMutate: (newUserInfo: User) => {
queryClient.setQueryData(
['users'],
(prevUsers: any) =>
prevUsers?.map((prevUser: User) =>
prevUser.id === newUserInfo.id ? newUserInfo : prevUser,
),
queryClient.setQueryData(['users'], (prevUsers: any) =>
prevUsers?.map((prevUser: User) =>
prevUser.id === newUserInfo.id ? newUserInfo : prevUser,
),
);
},
// onSettled: () => queryClient.invalidateQueries({ queryKey: ['users'] }), //refetch users after mutation, disabled for demo
Expand All @@ -322,10 +320,8 @@ function useDeleteUser() {
},
//client side optimistic update
onMutate: (userId: string) => {
queryClient.setQueryData(
['users'],
(prevUsers: any) =>
prevUsers?.filter((user: User) => user.id !== userId),
queryClient.setQueryData(['users'], (prevUsers: any) =>
prevUsers?.filter((user: User) => user.id !== userId),
);
},
// onSettled: () => queryClient.invalidateQueries({ queryKey: ['users'] }), //refetch users after mutation, disabled for demo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,10 @@ function useUpdateUser() {
},
//client side optimistic update
onMutate: (newUserInfo: User) => {
queryClient.setQueryData(
['users'],
(prevUsers: any) =>
prevUsers?.map((prevUser: User) =>
prevUser.id === newUserInfo.id ? newUserInfo : prevUser,
),
queryClient.setQueryData(['users'], (prevUsers: any) =>
prevUsers?.map((prevUser: User) =>
prevUser.id === newUserInfo.id ? newUserInfo : prevUser,
),
);
},
// onSettled: () => queryClient.invalidateQueries({ queryKey: ['users'] }), //refetch users after mutation, disabled for demo
Expand All @@ -285,10 +283,8 @@ function useDeleteUser() {
},
//client side optimistic update
onMutate: (userId: string) => {
queryClient.setQueryData(
['users'],
(prevUsers: any) =>
prevUsers?.filter((user: User) => user.id !== userId),
queryClient.setQueryData(['users'], (prevUsers: any) =>
prevUsers?.filter((user: User) => user.id !== userId),
);
},
// onSettled: () => queryClient.invalidateQueries({ queryKey: ['users'] }), //refetch users after mutation, disabled for demo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,11 @@ function useUpdateUsers() {
},
//client side optimistic update
onMutate: (newUsers: User[]) => {
queryClient.setQueryData(
['users'],
(prevUsers: any) =>
prevUsers?.map((user: User) => {
const newUser = newUsers.find((u) => u.id === user.id);
return newUser ? newUser : user;
}),
queryClient.setQueryData(['users'], (prevUsers: any) =>
prevUsers?.map((user: User) => {
const newUser = newUsers.find((u) => u.id === user.id);
return newUser ? newUser : user;
}),
);
},
// onSettled: () => queryClient.invalidateQueries({ queryKey: ['users'] }), //refetch users after mutation, disabled for demo
Expand All @@ -321,10 +319,8 @@ function useDeleteUser() {
},
//client side optimistic update
onMutate: (userId: string) => {
queryClient.setQueryData(
['users'],
(prevUsers: any) =>
prevUsers?.filter((user: User) => user.id !== userId),
queryClient.setQueryData(['users'], (prevUsers: any) =>
prevUsers?.filter((user: User) => user.id !== userId),
);
},
// onSettled: () => queryClient.invalidateQueries({ queryKey: ['users'] }), //refetch users after mutation, disabled for demo
Expand Down
13 changes: 6 additions & 7 deletions apps/material-react-table-docs/pages/api/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default async function handler(
if (process.env.NODE_ENV === 'development') {
await new Promise((resolve) => setTimeout(resolve, 500));
}

let dbData = getData();
const { start, size, filters, sorting, globalFilter } = req.query as Record<
string,
Expand All @@ -40,12 +40,11 @@ export default async function handler(

if (globalFilter) {
dbData = dbData.filter((row) =>
Object.keys(row).some(
(columnId) =>
row[columnId]
?.toString()
?.toLowerCase()
?.includes?.((globalFilter as string).toLowerCase()),
Object.keys(row).some((columnId) =>
row[columnId]
?.toString()
?.toLowerCase()
?.includes?.((globalFilter as string).toLowerCase()),
),
);
}
Expand Down
12 changes: 6 additions & 6 deletions apps/material-react-table-docs/pages/docs/api/mrt-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ In previous versions of `material-react-table`, you only had the option to use t

### \<MaterialReactTable /\>

[View Source Code on GitHub](https://github.com/KevinVandy/material-react-table/blob/v2/packages/material-react-table/src/MaterialReactTable.tsx)
[View Source Code on GitHub](https://github.com/KevinVandy/material-react-table/blob/v2/packages/material-react-table/src/components/MaterialReactTable.tsx)

For most use cases, you will probably just use the default `<MaterialReactTable />` component.

Expand Down Expand Up @@ -69,7 +69,7 @@ Material React Table now exports all of its internal components. You can use the

#### Table Components

[View Table Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/table)
[View Table Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/components/table)

##### \<MRT_TablePaper /\>

Expand All @@ -95,7 +95,7 @@ Shows a loading spinner over the table above the `MRT_Table` component when the

#### TableHead Components

[View TableHead Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/head)
[View TableHead Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/components/head)

##### \<MRT_TableHead /\>

Expand Down Expand Up @@ -135,7 +135,7 @@ The Filter Container that contains the filter input and filter actions

#### TableBody Components

[View TableBody Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/body)
[View TableBody Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/components/body)

##### \<MRT_TableBody /\>

Expand Down Expand Up @@ -167,7 +167,7 @@ A button or buttons for pinning a row.

#### TableFooter Components

[View TableFooter Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/footer)
[View TableFooter Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/components/footer)

##### \<MRT_TableFooter /\>

Expand All @@ -183,7 +183,7 @@ The `<MRT_TableFooterCell />` is a `<td>` element that surrounds the cell value

#### Input Components

[View Input Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/inputs)
[View Input Components Source Code on GitHub](https://github.com/KevinVandy/material-react-table/tree/v2/packages/material-react-table/src/components/inputs)

##### \<MRT_EditCellTextField /\>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MRT has been adopting more and more of a hooks based approach for its internal l

### useMaterialReactTable

[Source Code](https://github.com/KevinVandy/material-react-table/blob/v2/packages/material-react-table/src/useMaterialReactTable.ts)
[Source Code](https://github.com/KevinVandy/material-react-table/blob/v2/packages/material-react-table/src/hooks/useMaterialReactTable.ts)

> This is probably the only MRT hook you will need to use, unless you are writing a custom headless table.
Expand Down
1 change: 1 addition & 0 deletions packages/material-react-table/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default [
external: [
'@mui/icons-material',
'@mui/material',
'@mui/x-date-pickers',
'@tanstack/match-sorter-utils',
'@tanstack/react-table',
'@tanstack/react-virtual',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MRT_TablePaper } from './table/MRT_TablePaper';
import { useMaterialReactTable } from '../hooks/useMaterialReactTable';
import {
type MRT_RowData,
type MRT_TableInstance,
type MRT_TableOptions,
type Xor,
} from './types';
import { useMaterialReactTable } from './useMaterialReactTable';
} from '../types';
import { MRT_TablePaper } from './table/MRT_TablePaper';

type TableInstanceProp<TData extends MRT_RowData> = {
table: MRT_TableInstance<TData>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { type VirtualItem } from '@tanstack/react-virtual';
import TableBody, { type TableBodyProps } from '@mui/material/TableBody';
import Typography from '@mui/material/Typography';
import { MRT_TableBodyRow, Memo_MRT_TableBodyRow } from './MRT_TableBodyRow';
import { parseFromValuesOrFunc } from '../column.utils';
import { useMRT_RowVirtualizer } from '../hooks/useMRT_RowVirtualizer';
import { useMRT_Rows } from '../hooks/useMRT_Rows';
import { useMRT_RowVirtualizer } from '../../hooks/useMRT_RowVirtualizer';
import { useMRT_Rows } from '../../hooks/useMRT_Rows';
import {
type MRT_ColumnVirtualizer,
type MRT_Row,
type MRT_RowData,
type MRT_TableInstance,
} from '../types';
} from '../../types';
import { parseFromValuesOrFunc } from '../../utils/utils';

interface Props<TData extends MRT_RowData> extends TableBodyProps {
columnVirtualizer?: MRT_ColumnVirtualizer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ import Skeleton from '@mui/material/Skeleton';
import TableCell, { type TableCellProps } from '@mui/material/TableCell';
import { useTheme } from '@mui/material/styles';
import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
import {
getIsFirstColumn,
getIsLastColumn,
parseFromValuesOrFunc,
} from '../column.utils';
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
import { getCommonMRTCellStyles, getMRTTheme } from '../style.utils';
import {
type MRT_Cell,
type MRT_RowData,
type MRT_TableInstance,
} from '../types';
} from '../../types';
import { getIsFirstColumn, getIsLastColumn } from '../../utils/column.utils';
import { getCommonMRTCellStyles, getMRTTheme } from '../../utils/style.utils';
import { parseFromValuesOrFunc } from '../../utils/utils';
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';

interface Props<TData extends MRT_RowData> extends TableCellProps {
cell: MRT_Cell<TData>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type ReactNode, type RefObject } from 'react';
import Box from '@mui/material/Box';
import { getMRTTheme } from '../style.utils';
import {
type MRT_Cell,
type MRT_RowData,
type MRT_TableInstance,
} from '../types';
} from '../../types';
import { getMRTTheme } from '../../utils/style.utils';
import highlightWords from 'highlight-words';

const allowedTypes = ['string', 'number'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import {
} from '@mui/material/styles';
import { MRT_TableBodyCell, Memo_MRT_TableBodyCell } from './MRT_TableBodyCell';
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
import { parseFromValuesOrFunc } from '../column.utils';
import { getMRTTheme } from '../style.utils';
import {
type MRT_Cell,
type MRT_ColumnVirtualizer,
type MRT_Row,
type MRT_RowData,
type MRT_RowVirtualizer,
type MRT_TableInstance,
} from '../types';
} from '../../types';
import { getMRTTheme } from '../../utils/style.utils';
import { parseFromValuesOrFunc } from '../../utils/utils';

interface Props<TData extends MRT_RowData> {
columnVirtualizer?: MRT_ColumnVirtualizer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { type DragEvent, type RefObject } from 'react';
import { type IconButtonProps } from '@mui/material/IconButton';
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
import { parseFromValuesOrFunc } from '../column.utils';
import {
type MRT_Row,
type MRT_RowData,
type MRT_TableInstance,
} from '../types';
} from '../../types';
import { parseFromValuesOrFunc } from '../../utils/utils';
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';

interface Props<TData extends MRT_RowData> extends IconButtonProps {
row: MRT_Row<TData>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Box from '@mui/material/Box';
import { type IconButtonProps } from '@mui/material/IconButton';
import { MRT_RowPinButton } from '../buttons/MRT_RowPinButton';
import { parseFromValuesOrFunc } from '../column.utils';
import {
type MRT_Row,
type MRT_RowData,
type MRT_TableInstance,
} from '../types';
} from '../../types';
import { parseFromValuesOrFunc } from '../../utils/utils';
import { MRT_RowPinButton } from '../buttons/MRT_RowPinButton';

interface Props<TData extends MRT_RowData> extends IconButtonProps {
row: MRT_Row<TData>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { type RefObject } from 'react';
import Collapse from '@mui/material/Collapse';
import TableCell, { type TableCellProps } from '@mui/material/TableCell';
import TableRow from '@mui/material/TableRow';
import { parseFromValuesOrFunc } from '../column.utils';
import { getMRTTheme } from '../style.utils';
import {
type MRT_Row,
type MRT_RowData,
type MRT_RowVirtualizer,
type MRT_TableInstance,
type MRT_VirtualItem,
} from '../types';
} from '../../types';
import { getMRTTheme } from '../../utils/style.utils';
import { parseFromValuesOrFunc } from '../../utils/utils';

interface Props<TData extends MRT_RowData> extends TableCellProps {
parentRowRef: RefObject<HTMLTableRowElement>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Box, { type BoxProps } from '@mui/material/Box';
import IconButton from '@mui/material/IconButton';
import Tooltip from '@mui/material/Tooltip';
import { parseFromValuesOrFunc } from '../column.utils';
import {
type MRT_Column,
type MRT_RowData,
type MRT_TableInstance,
} from '../types';
} from '../../types';
import { parseFromValuesOrFunc } from '../../utils/utils';

interface Props<TData extends MRT_RowData> extends BoxProps {
column: MRT_Column<TData>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { type MouseEvent, useState } from 'react';
import Button, { type ButtonProps } from '@mui/material/Button';
import Tooltip from '@mui/material/Tooltip';
import { parseFromValuesOrFunc } from '../column.utils';
import { getCommonTooltipProps } from '../style.utils';
import {
type MRT_Cell,
type MRT_RowData,
type MRT_TableInstance,
} from '../types';
} from '../../types';
import { getCommonTooltipProps } from '../../utils/style.utils';
import { parseFromValuesOrFunc } from '../../utils/utils';

interface Props<TData extends MRT_RowData> extends ButtonProps {
cell: MRT_Cell<TData>;
Expand Down
Loading

2 comments on commit 0799d4b

@vercel
Copy link

@vercel vercel bot commented on 0799d4b Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 0799d4b Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.