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

[BUG] useModal pass metadata with show() #6495

Open
aress31 opened this issue Nov 17, 2024 · 2 comments
Open

[BUG] useModal pass metadata with show() #6495

aress31 opened this issue Nov 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@aress31
Copy link

aress31 commented Nov 17, 2024

Describe the bug

Can a feature get implemented to pass metadata within useModalForm, this way id, action and any other relevant parameter can be passed down to the dialog component.

Steps To Reproduce

N/A

Expected behavior

show({foo, bar})

Packages

N/A

Additional Context

No response

@aress31 aress31 added the bug Something isn't working label Nov 17, 2024
@alicanerdurmaz
Copy link
Member

alicanerdurmaz commented Nov 19, 2024

Hello @aress31,

Can you please give me more details about your use case? You labeled it a bug. What issue or error did you encounter?

@aress31
Copy link
Author

aress31 commented Nov 19, 2024

@alicanerdurmaz my bad should have been a feat, see the following use case:

const MySuperView = () => {
  // --- SNIP ---

  const [refineCoreProps, setRefineCoreProps] = useState();
  const modal = useModal();

  return (
    <Box>
      <DataGridComponent
        // --- SNIP ---
        slotProps={{
          toolbar: {
            modal: (action, id) => {
              setRefineCoreProps({ action, id });
              modal.show();
            },
          },
        }}
      />
      {modal.visible && <ModalForm modalProps={{ modal, refineCoreProps }} />}
    </Box>
  );
};

const DataGridToolbar = ({ modal }) => {
  /// --- SNIP ---

  const renderActions = () => (
    <>
      {/* --- SNIP --- */}
      <Button
        // --- SNIP ---
        onClick={() => modal("show", selectedRows.keys().next().value)}
      >
        Show
      </Button>
      <Button
        // --- SNIP ---
        onClick={() => modal("edit", selectedRows.keys().next().value)}
      >
        Edit
      </Button>
      <Button
        // --- SNIP ---
        onClick={() => modal("create")}
      >
        Create
      </Button>
    </>
  );

  return (
    <GridToolbarContainer>
      {/* --- SNIP --- */}
      {renderActions()}
    </GridToolbarContainer>
  );
};

Here I only pass action and id but in an ideal world we would have a meta prop - to stay consistent with the naming scheme to pass down to the ModalForm any relevant information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants