-
Notifications
You must be signed in to change notification settings - Fork 341
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
Enhance ExternalInput: Pass filters to mapProp for custom data mapping #714
base: main
Are you sure you want to change the base?
Enhance ExternalInput: Pass filters to mapProp for custom data mapping #714
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Someone is attempting to deploy a commit to the Measured Team on Vercel. A member of the Team first needs to authorize it. |
- Added `useState` to manage filters based on initial values from `field.initialFilters` or existing `value[name]`. - Ensures filters are initialized properly when loading or updating the component state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @haidv1992!
Filters are not really intended to be used in this way, and are designed for filtering the data, not mutating it. I worry that applying them to the mapProp field might make the naming of filters
a little unclear.
Can you share an example use-case?
@@ -41,8 +41,8 @@ export const ExternalInput = ({ | |||
const [isLoading, setIsLoading] = useState(true); | |||
|
|||
const hasFilterFields = !!filterFields; | |||
|
|||
const [filters, setFilters] = useState(field.initialFilters || {}); | |||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ideally shouldn't be introducing @ts-ignore
, if at all possible
@@ -244,7 +244,7 @@ export const ExternalInput = ({ | |||
style={{ whiteSpace: "nowrap" }} | |||
className={getClassNameModal("tr")} | |||
onClick={() => { | |||
onChange(mapProp(data[i])); | |||
onChange(mapProp(data[i],filters)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be formatted, otherwise it will fail linting. You can run npm run format
to address it.
@@ -90,7 +90,7 @@ export type ExternalField< | |||
query: string; | |||
filters: Record<string, any>; | |||
}) => Promise<any[] | null>; | |||
mapProp?: (value: any) => Props; | |||
mapProp?: (value: any,filters:any) => Props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second param would probably be better as an object, and we may as well use the correct type for filters
-
mapProp?: (value: any,filters:any) => Props; | |
mapProp?: (value: any, options: { filters: Record<string, any> }) => Props; |
Enhance ExternalInput: Pass filters to mapProp for custom data mapping
mapProp
function to accept filters as an argument.ExternalInput
component to pass current filters when selecting data from the table.