search-ui icon indicating copy to clipboard operation
search-ui copied to clipboard

Allow custom metadata to be passed to views

Open PhaedrusTheGreek opened this issue 3 years ago • 1 comments

For example,

(A) A Facet view might operate in different modes, e.g., compressed, or show/hide icons. Today, to accomplish that it is necessary to name each component in accordance with it's variation, e.g.:

const SearchMultiIconFacetsView = (props: FacetViewProps & Props) => {
...
}

export const SearchMultiIconFacetsViewLogos = (props: any) => (
  <SearchMultiIconFacetsView {...props} logos />
);

export const SearchMultiIconFacetsViewCompressed = (props: any) => (
  <SearchMultiIconFacetsView {...props} compressed />
);

export const SearchMultiIconFacetsViewCompressedLogos = (props: any) => (
  <SearchMultiIconFacetsView {...props} compressed logos />
);

As another example,

(B) It seems that the field used to create the facet is not passed as a prop to a custom Facet view. This is useful for customizing the view based on the field. e.g., the "Product" facet view might have icons that need to be loaded.

It would be helpful if we could pass this sort of data as props to the end view component, or some metadata object as a prop. e.g.,

 <Facet
    field="priority"
    filterType="all"
    label={priority}
    view={SearchMultiIconFacetsView}
    meta={{field: 'priority', compressed: true, logos: true}}
  />

PhaedrusTheGreek avatar Oct 12 '22 18:10 PhaedrusTheGreek

Hey @PhaedrusTheGreek. I think that all properties you pass to the Facet component will ultimately get passed down to the view, can you try it out to confirm?

Meaning, if you pass meta as you do above, it should be passed through to your view for you to use.

Another approach you could take is something like this:

 <Facet
    field="priority"
    filterType="all"
    label={priority}
    view={props => {
      return <SearchMultiIconFacetsView {...props} meta={{field: 'priority', compressed: true, logos: true}} />
    }}
  />

Do you think either of those solutions would work for you?

JasonStoltz avatar Oct 13 '22 15:10 JasonStoltz

Thanks. Option 1 doesn't seem to work due to TS issues, but the 2nd approach works well, thank you!

PhaedrusTheGreek avatar Oct 18 '22 18:10 PhaedrusTheGreek

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

botelastic[bot] avatar Dec 17 '22 19:12 botelastic[bot]