-
Notifications
You must be signed in to change notification settings - Fork 342
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ export const ExternalInput = ({ | |
readOnly?: boolean; | ||
}) => { | ||
const { | ||
mapProp = (val: any) => val, | ||
mapProp = (val: any,filters: object) => val, | ||
mapRow = (val: any) => val, | ||
filterFields, | ||
} = field || {}; | ||
|
@@ -41,8 +41,8 @@ export const ExternalInput = ({ | |
const [isLoading, setIsLoading] = useState(true); | ||
|
||
const hasFilterFields = !!filterFields; | ||
|
||
const [filters, setFilters] = useState(field.initialFilters || {}); | ||
// @ts-ignore | ||
const [filters, setFilters] = useState(field.initialFilters || value?.[name] || {}); | ||
const [filtersToggled, setFiltersToggled] = useState(hasFilterFields); | ||
|
||
const mappedData = useMemo(() => { | ||
|
@@ -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 commentThe 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 |
||
|
||
setOpen(false); | ||
}} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe 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
Suggested change
|
||||||
mapRow?: (value: any) => Record<string, string | number>; | ||||||
getItemSummary?: (item: Props, index?: number) => string; | ||||||
showSearch?: boolean; | ||||||
|
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