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

fix(studio-ui-codegen-react): collection items props takes precedent #96

Merged
merged 1 commit into from
Sep 24, 2021

Conversation

dpilch
Copy link
Contributor

@dpilch dpilch commented Sep 22, 2021

Resolves #90

  • Explicitly pass items when there is no binding
  • items prop take precedent over useDataStoreBinding

See snapshot tests for examples

@dpilch dpilch requested a review from cwoolum September 22, 2021 15:29
export default function CollectionOfCustomButtons(
props: CollectionOfCustomButtonsProps
): JSX.Element {
const { width, backgroundColor, buttonColor } = props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we had intended to always allow the items of a collection to be overridden and just not call datastore if so. Might be good to ask at standup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you saying if items is passed in props then props.items should be used in place of const { boundItems } = useDataStoreBinding...?

So even if we have boundItems defined props.items should take precedent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that is the intended functionality. @renebrandel can you confirm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll have to bring it up as "parking lot item" during standup. @dpilch

Copy link
Contributor

@cwoolum cwoolum Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just talked with Rene to nail this down. Any component that is a collection will always expose a prop where items can be passed in to be rendered by the collection. If a predicate is provided and that prop is empty, a datastore call should be made and that data used to render.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking into the fix for this.

I think it would look something like this.

export type CollectionOfCustomButtonsProps = { 
  items?: any[],
}
export default function CollectionOfCustomButtons(                                                                       
  props: CollectionOfCustomButtonsProps                                                                                  
): JSX.Element {                                                                                                         
  const { items } = props;                                                          
  const buttonUserFilter = {                                                                                             
     and: [                                                                                                               
       { field: "age", operand: "10", operator: "gt" },                                                       
       { field: "lastName", operand: "L", operator: "beginsWith" },                                           
    ],                                                                                                                   
  };
  const displayedItems = items !== undefined
    ? items
    : useDataStoreBinding({                                                                           
      type: "collection",                                                                                              
      model: User,                                                                                                         
      criteria: buttonUserFilter,                                                                                          
    }).buttonUser;        
  return (
    <Collection
      items={displayedItems}
      ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dpilch dpilch marked this pull request as draft September 23, 2021 20:52
@dpilch dpilch marked this pull request as ready for review September 24, 2021 01:50
@dpilch dpilch changed the title fix: pass items from props on collection with no binding fix(studio-ui-codegen-react): collection items props takes precedent Sep 24, 2021
Copy link
Contributor

@cwoolum cwoolum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@frimfram frimfram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dpilch dpilch merged commit 0149ca2 into main Sep 24, 2021
@dpilch dpilch deleted the fix-collection-no-binding branch September 24, 2021 19:33
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.

Collections rendering invalid items variable
3 participants