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

[FEAT] custom function convert filters to searchForm data in useTable and useList #6620

Open
hongfanmeng opened this issue Jan 1, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@hongfanmeng
Copy link

hongfanmeng commented Jan 1, 2025

Is your feature request related to a problem? Please describe.

In @refinedev/antd, when syncWithLocation is True, useTable and useList will convert the filters value to form values in searchForm, but this conversion is very simple. For example, when filter id=1, it will be converted to id='1', which will cause some problems

Origin conversion code in @refinedev/antd, i think it's possible to provide a custom function convert filters to filterFilterMap

React.useEffect(() => {
  if (shouldSyncWithLocation) {
    // get registered fields of form
    const registeredFields = formSF.form.getFieldsValue() as Record<
      string,
      any
    >;
    // map `filters` for registered fields
    const filterFilterMap = Object.keys(registeredFields).reduce(
      (acc, curr) => {
        // find filter for current field
        const filter = filters.find(
          (filter) => "field" in filter && filter.field === curr,
        );
        // if filter exists, set value to filter value
        if (filter) {
          acc[curr] = filter?.value;
        }
        return acc;
      },
      {} as Record<string, any>,
    );
    // set values to form
    formSF.form.setFieldsValue(filterFilterMap as any);
  }
}, [shouldSyncWithLocation]);

Describe alternatives you've considered

No response

Additional context

No response

Describe the thing to improve

Originally there was a function onSearch in useTable and useList that converts form values ​​to CRUDFilters. I wish to provide a reverse function to convert CRUDFilters to form values

@hongfanmeng hongfanmeng added the enhancement New feature or request label Jan 1, 2025
@alicanerdurmaz
Copy link
Member

Hello @hongfanmeng, I think providing a custom function for that is a great idea, but our hands are pretty full at the moment. Would you like to work on this?

About second question, the code you shared already sets the filters values to the form. (CrudFilters -> Form FieldsValue) I didn't fully understand that question.

@hongfanmeng
Copy link
Author

hongfanmeng commented Jan 3, 2025

The code is how @refinedev/antd convert CrudFilters to Form FieldsValue, but it can only handle simple situation, I think we can put the custom function here

I can implement this feature, but I may not be free until one or two month later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants