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

feat: add data binding predicate #57

Merged
merged 2 commits into from
Sep 14, 2021
Merged

feat: add data binding predicate #57

merged 2 commits into from
Sep 14, 2021

Conversation

dpilch
Copy link
Contributor

@dpilch dpilch commented Sep 10, 2021

  • add data binding predicate filter
  • add collection binding model imports

Example component:

/** *************************************************************************
 * The contents of this file were generated with Amplify Studio.           *
 * Please refrain from making any modifications to this file.              *
 * Any changes to this file will be overwritten when running amplify pull. *
 ************************************************************************* */

/* eslint-disable */
import React from "react";
import { User, UserPreferences } from "../models";
import {
  Button,
  Collection,
  EscapeHatchProps,
  Flex,
  getOverrideProps,
} from "@aws-amplify/ui-react";

export type CollectionOfCustomButtonsProps = {
  width: Number,
  backgroundColor: String,
  buttonColor?: UserPreferences,
} & {
  overrides?: EscapeHatchProps | undefined | null,
};
export default function CollectionOfCustomButtons(
  props: CollectionOfCustomButtonsProps
): JSX.Element {
  const buttonUserFilter = {
    and: [
      { field: "age", operand: "10", operator: "gt" },
      { field: "lastName", operand: "L", operator: "beginsWith" },
    ],
  };
  const { buttonUser } = useDataStoreBinding({
    type: "collection",
    model: User,
    criteria: buttonUserFilter,
  });
  const buttonColorFilter = {
    field: "userID",
    operand: "user@email.com",
    operator: "eq",
  };
  const { buttonColor } = useDataStoreBinding({
    type: "record",
    model: UserPreferences,
    criteria: buttonColorFilter,
  });
  return (
    <Collection
      type="list"
      gap="1.5rem"
      backgroundColor={backgroundColor}
      items={buttonUser}
      {...props}
      {...getOverrideProps(props.overrides, "Collection")}
    >
      {(item, index) => (
        <Flex {...props} {...getOverrideProps(props.overrides, "Flex")}>
          <Button
            label={item.username || "hspain@gmail.com"}
            labelWidth={width}
            backgroundColor={buttonColor.favoriteColor}
            disabled={isDisabled}
            {...props}
            {...getOverrideProps(props.overrides, "Button")}
          ></Button>
        </Flex>
      )}
    </Collection>
  );
}

Changes needed in schema:

diff --git a/packages/amplify-ui-codegen-schema/lib/types/index.ts b/packages/amplify-ui-codegen-schema/lib/types/index.ts
index ed7917d..2ba31b1 100644
--- a/packages/amplify-ui-codegen-schema/lib/types/index.ts
+++ b/packages/amplify-ui-codegen-schema/lib/types/index.ts
@@ -378,10 +378,17 @@ export enum StudioComponentPropertyBindingType {
  */
 export type StudioComponentDataBindingProperty = {
   model: string;
-  field?: string;
-  predicate?: string;
+  predicate?: StudioComponentPredicate;
 };
 
diff --git a/packages/amplify-ui-codegen-schema/lib/types/index.ts b/packages/amplify-ui-codegen-schema/lib/types/index.ts
index ed7917d..2ba31b1 100644
--- a/packages/amplify-ui-codegen-schema/lib/types/index.ts
+++ b/packages/amplify-ui-codegen-schema/lib/types/index.ts
@@ -378,10 +378,17 @@ export enum StudioComponentPropertyBindingType {
  */
 export type StudioComponentDataBindingProperty = {
   model: string;
-  field?: string;
-  predicate?: string;
+  predicate?: StudioComponentPredicate;
 };
 
+export interface StudioComponentPredicate {
+  and?: StudioComponentPredicate[];
+  field?: String;
+  operand?: String;
+  operator?: String;
+  or?: StudioComponentPredicate[];
+}
+

@dpilch dpilch marked this pull request as ready for review September 10, 2021 17:03
@dpilch dpilch changed the title predicate feat: add data binding predicate Sep 10, 2021
@frimfram
Copy link
Contributor

wondering if some sample json can be added to test-generator?

@dpilch
Copy link
Contributor Author

dpilch commented Sep 14, 2021

@dpilch dpilch merged commit d9e0216 into main Sep 14, 2021
@dpilch dpilch deleted the predicate branch September 14, 2021 17:38
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.

None yet

2 participants