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

Enhance ExternalInput: Pass filters to mapProp for custom data mapping #714

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

haidv1992
Copy link

Enhance ExternalInput: Pass filters to mapProp for custom data mapping

  • Updated mapProp function to accept filters as an argument.
  • Modified ExternalInput component to pass current filters when selecting data from the table.
  • Enabled dynamic data mapping based on filters for better flexibility.

Copy link

vercel bot commented Nov 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
puck-docs ✅ Ready (Inspect) Visit Preview Dec 2, 2024 6:18am

Copy link

vercel bot commented Nov 29, 2024

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.
Copy link
Member

@chrisvxd chrisvxd left a 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
Copy link
Member

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));
Copy link
Member

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;
Copy link
Member

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 -

Suggested change
mapProp?: (value: any,filters:any) => Props;
mapProp?: (value: any, options: { filters: Record<string, any> }) => Props;

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

Successfully merging this pull request may close these issues.

2 participants