Skip to content
Open
Changes from all 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
11 changes: 7 additions & 4 deletions demo/admin/src/products/ProductsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
getGridStringOperators,
GridFilterInputSingleSelect,
type GridRowSelectionModel,
type GridSlotsComponent,
type GridSlotProps,
GridToolbarQuickFilter,
} from "@mui/x-data-grid-pro";
import { ProductCategoryFilterOperators } from "@src/products/ProductCategoryFilter";
Expand All @@ -56,7 +56,10 @@ type ProductsGridToolbarProps = {
selectionModel: GridRowSelectionModel;
};

function ProductsGridToolbar({ exportApi, selectionModel }: ProductsGridToolbarProps) {
const ProductsGridToolbar: React.JSXElementConstructor<GridSlotProps["toolbar"] & ProductsGridToolbarProps> = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this explicit type definition here better than the as cast? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I know as does disable any check. this kind of definition provides more type-safety. If the function is defined differently a typescript error is thrown for initializing the data-grid.

And as mentioned in the description in my application I needed to change the additional props to optional. I don't know why this wasn't necessary here.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Module augmentation solution worked in this file, but resulted in issues in an other file. also I didn't found a solution for local module augmentation only, so augmented fields are also "available" in other grid-components.

Copy link
Member

Choose a reason for hiding this comment

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

module augmentation is always global, I was thinking about something like that:

type ToolbarProps = PropsFromSlot<GridSlots['toolbar']> & ProductsGridToolbarProps;

exportApi,
selectionModel,
}: ProductsGridToolbarProps) => {
const client = useApolloClient();
const theme = useTheme();

Expand Down Expand Up @@ -117,7 +120,7 @@ function ProductsGridToolbar({ exportApi, selectionModel }: ProductsGridToolbarP
</Button>
</DataGridToolbar>
);
}
};

export function ProductsGrid() {
const dataGridProps = { ...useDataGridRemote(), ...usePersistentColumnState("ProductsGrid") };
Expand Down Expand Up @@ -378,7 +381,7 @@ export function ProductsGrid() {
columns={columns}
loading={loading}
slots={{
toolbar: ProductsGridToolbar as GridSlotsComponent["toolbar"],
toolbar: ProductsGridToolbar,
}}
slotProps={{
toolbar: { exportApi, selectionModel } as ProductsGridToolbarProps,
Expand Down