Skip to content

CRUD component#4486

Merged
apedroferreira merged 94 commits intomui:masterfrom
apedroferreira:crud-list
Mar 7, 2025
Merged

CRUD component#4486
apedroferreira merged 94 commits intomui:masterfrom
apedroferreira:crud-list

Conversation

@apedroferreira
Copy link
Collaborator

@apedroferreira apedroferreira commented Nov 27, 2024

Implement CRUD feature as specified in #4146

https://deploy-preview-4486--mui-toolpad-docs.netlify.app/toolpad/core/react-crud/

Tests and examples will be added in separate PRs as this PR has already grown too large.

To help review, the contents of this PR are mostly:

  • Relevant changes for the new feature (new components) in packages/toolpad-core.
  • Documentation added in docs, many examples but with a lot of repetition between them, feel free to just mostly take a look at the new documentation page for the Crud component.
  • Added orders CRUD to the playgrounds for Vite, Next.js App Router and Next.js Pages Router.
  • Other than that there are very few changes.

It took a while to reach this first version but still feel free to provide any major or minor feedback!

@apedroferreira apedroferreira added type: new feature Expand the scope of the product to solve a new problem. scope: toolpad-core Abbreviated to "core" labels Nov 27, 2024
@apedroferreira apedroferreira self-assigned this Nov 27, 2024
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 27, 2024
@apedroferreira apedroferreira changed the title CRUD List component CRUD component Dec 24, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 22, 2025
@mui-bot
Copy link

mui-bot commented Jan 22, 2025

Netlify deploy preview

https://deploy-preview-4486--mui-toolpad-docs.netlify.app/

Generated by 🚫 dangerJS against 94f029e

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 29, 2025

An `id` field (string or number) is mandatory so that individual items can be identified.

An additional type `longString` is provided for multiline form fields.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
An additional type `longString` is provided for multiline form fields.
- An additional type `longString` is provided for multiline form fields.

components: Crud, CrudProvider, List, Show, Create, Edit, CrudForm
---

# Crud
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be CRUD or Crud?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to what we discussed about MUI component casing the component should be called Crud.


The `Crud` component automatically generates CRUD pages for your data source, automatically integrated with your routing solution. All that is required is a `dataSource` definition and a `rootPath` for the CRUD pages.

{{"demo": "CrudBasic.js", "height": 600, "iframe": true}}
Copy link
Contributor

@prakhargupta1 prakhargupta1 Feb 27, 2025

Choose a reason for hiding this comment

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

In case of TS, code highlight doesn't seem to be applied for the preview code. It's happening for some other demos as well. I'm not sure if it's an issue and can be fixed. Just thought of sharing this observation.

Copy link
Collaborator Author

@apedroferreira apedroferreira Mar 5, 2025

Choose a reason for hiding this comment

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

I know, it doesn't seem like it's ready for components like <Crud<Note> but that's valid Typescript, I guess it's an issue with the coloring/highlighting in the editor...

Copy link
Collaborator

@bharatkashyap bharatkashyap left a comment

Choose a reason for hiding this comment

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

Looks great @apedroferreira! A huge addition to the component set.

I think the only missing piece is integration with the new LocalizationProvider (#4620) so that we're not using any hard-coded strings and all text can be overridden.


Displays a form for creating a new item for a data source, automatically generated from the given `fields` and field `type`s.

The supported field types are `string`, `longString`, `number`, `boolean`, `date`, `dateTime` and `singleSelect`.
Copy link
Member

Choose a reason for hiding this comment

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

Wondering whether longstring makes sense as its own type. I'd expect users wanting to add all kinds of refinements and validations to the basic string type such as min/max length, regex, email,...

"multiline" could be one such refinement. I'd rather expect the data model type to be loosely coupled to the UI control in the form. i.e. we use the data model type to generate a good default, then add ways on top to refine this control further.

But perhaps we can keep this for now and see where users want to take this?

Copy link
Collaborator Author

@apedroferreira apedroferreira Mar 5, 2025

Choose a reason for hiding this comment

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

Got it, wouldn't be a lot of work to already include a slot for this and get rid of longString, it would also be more consistent with the data grid types. So will probably do it quickly if that sounds ok.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nevermind a slot will not be changeable per field type. I'll remove longString for now and we could improve things in the future.


This function will run automatically against the current values when the user tries to submit a form inside the `Crud` component, or changes any of its fields.

#### Integration with external schema libraries
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
Collaborator Author

Choose a reason for hiding this comment

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

Hadn't seen it, we can probably make the validate function be compatible with this standard.

Copy link
Collaborator Author

@apedroferreira apedroferreira Mar 6, 2025

Choose a reason for hiding this comment

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

I've changed the format of the validate function to follow the Standard Schema, this should make it really straightforward to integrate with schema libraries that adhere to it: https://deploy-preview-4486--mui-toolpad-docs.netlify.app/toolpad/core/react-crud/#form-validation

Copy link
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

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

I believe we can start with this initial feature set 👍

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 6, 2025
@apedroferreira
Copy link
Collaborator Author

apedroferreira commented Mar 6, 2025

Looks great @apedroferreira! A huge addition to the component set.

I think the only missing piece is integration with the new LocalizationProvider (#4620) so that we're not using any hard-coded strings and all text can be overridden.

Here are the localization changes if you want to take a look, anyway it seems to work fine just followed the work you did in the other components. 00342c9

Tagging you for review just in case but I'll merge soon anyway probably.

Oh, and interpolation in these would be useful because the delete confirmation messages used to include the id of the item to be deleted.
But I guess we can wait until we add interpolation and then improve the delete messages.

@apedroferreira
Copy link
Collaborator Author

apedroferreira commented Mar 6, 2025

Review feedback has been addressed, will merge and release soon.
Tests and examples can be merged right after the release.

@apedroferreira apedroferreira merged commit f368972 into mui:master Mar 7, 2025
14 of 15 checks passed
@apedroferreira apedroferreira deleted the crud-list branch March 7, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: toolpad-core Abbreviated to "core" type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CRUD component

5 participants