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(piece-framework): support array of objects #2960

Merged
merged 11 commits into from
Jan 24, 2024

Conversation

iam-dev0
Copy link
Contributor

feat: add nested property access support in array for nested forms

Testing:
Manual testing confirms that refreshers mechanisms, dynamic property assignment, and validations are fully functional.

Sample Code:

    simpleArray: Property.Array({
      displayName: 'Simple Array',
      required: false,
    }),
    array: Property.Array({
      displayName: 'Nested Array',
      required: false,
      properties: {
        text: Property.ShortText({
          displayName: 'short',
          required: true,
        }),
        staticSelect: Property.StaticDropdown({
          displayName: 'Key-2',
          required: true,
          options: {
            options: [
              { label: 'val1', value: 1 },
              { label: 'val2', value: 2 },
            ],
          },
        }),
        checkbox: Property.Checkbox({
          displayName: 'Agree to Terms',
          description: 'Check this box to agree to the terms',
          required: true,
          defaultValue: false,
        }),
        number: Property.Number({
          displayName: 'Quantity',
          description: 'Enter a number',
          required: true,
        }),
        mutlistatic: Property.StaticMultiSelectDropdown({
          displayName: 'Colors',
          description: 'Select one or more colors',
          required: true,
          options: {
            options: [
              {
                label: 'Red',
                value: 'red',
              },
              {
                label: 'Green',
                value: 'green',
              },
              {
                label: 'Blue',
                value: 'blue',
              },
            ],
          },
        }),
        dropdown: Property.Dropdown<string>({
          displayName: 'Options',
          description: 'Select an option',
          required: true,
          refreshers: [],
          options: async () => {
            return {
              options: [
                {
                  label: 'Option One',
                  value: '1',
                },
                {
                  label: 'Option Two',
                  value: '2',
                },
              ],
            };
          },
        }),
        multi: Property.MultiSelectDropdown<string>({
          displayName: 'Options',
          description: 'Select one or more options',
          required: true,
          refreshers: [],
          options: async () => {
            const apiEndpoint = 'https://jsonplaceholder.typicode.com/todos';
            const response = await fetch(apiEndpoint);
            const data: { id: number; title: string }[] = await response.json();
            return {
              options: data.map((item) => {
                return { value: item.id?.toString(), label: item.title };
              }),
            };
          },
        }),
        dynamic: Property.DynamicProperties({
          description: 'Dynamic Form',
          displayName: 'Dynamic Form',
          required: true,
          refreshers: [],
          props: async (propsValue) => {
            const apiEndpoint = 'https://jsonplaceholder.typicode.com/todos';
            const response = await fetch(apiEndpoint);
            const data: { id: number; title: string }[] = await response.json();

            const properties = {
              prop1: Property.StaticDropdown({
                displayName: 'Property 1',
                description: 'Enter property 1',
                required: true,
                options: {
                  options: data.map((item) => {
                    return { value: item.id?.toString(), label: item.title };
                  }),
                },
              }),
            };

            return properties;
          },
        }),
      },
    }),

Screenshot from 2023-10-16 18-45-02
Screenshot from 2023-10-16 18-44-49

@abuaboud
Copy link
Contributor

Hi @Awais000 give me some more time, I am going to get back to that soon!

Sorry

Copy link

nx-cloud bot commented Nov 2, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 8f0110f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

@CLAassistant
Copy link

CLAassistant commented Nov 2, 2023

CLA assistant check
All committers have signed the CLA.

@abuaboud abuaboud changed the title Feature/array nested form feat(piece-frameowrk): support array of objects Nov 14, 2023
@fardeenpanjwani-codeglo
Copy link
Contributor

fardeenpanjwani-codeglo commented Dec 20, 2023

@Awais000, very useful feature! Thanks! Just out of curiosity, is there a way to make one property's config depend on the value from another property ( both properties being in the same array )?

Copy link

nx-cloud bot commented Jan 24, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit aa98b41. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx affected --target=build -c production --parallel=3
✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@abuaboud abuaboud changed the title feat(piece-frameowrk): support array of objects feat(piece-framework): support array of objects Jan 24, 2024
@abuaboud
Copy link
Contributor

abuaboud commented Jan 24, 2024

Thank you, @Anomaly314, for this great contribution.

As we discussed, let's temporarily remove the dynamic dropdown and dynamic properties, and then merge that.

I have merged with the main branch and pushed the changes we discussed.

@AbdulTheActivePiecer, could you please take a look at the user interface and make the necessary changes?

I believe we should take look at the design of groups at #3206 and ensure that we have a design for grouping (card), that we will be using in both these feature.

@AbdulTheActivePiecer I have pushed an edits to hackernews, I will revert them before we merge to main, as they are just for testing.

So please checkout the branch and check hackernews piece.

@abuaboud abuaboud added the 🛠️ piece-framework Changes Related to Piece framework label Jan 24, 2024
@AbdulTheActivePiecer
Copy link
Collaborator

Hi there guys, I adjusted some stuff in the UI code to make it more coherent with our design, thanks a lot @Anomaly314.
One of the thing I would like to recommend is moving shared code/logic into a separate file, instead of passing it as an input parameter to a child component, that's just a recipe of disaster because of side-effects that could happen, believe me I tried it before 😂
Another thing is to not include the "valueChanges" listener in writeValue as that's not recommended in Angular, because writeValue can be called programatically and not only on initialization of the form control.
Other than that all was great

@abuaboud abuaboud merged commit e273f3b into activepieces:main Jan 24, 2024
10 of 12 checks passed
@abuaboud abuaboud mentioned this pull request Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ piece-framework Changes Related to Piece framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants