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

Dynamic Form to Dev #903

Merged
merged 2 commits into from
May 21, 2021
Merged

Dynamic Form to Dev #903

merged 2 commits into from
May 21, 2021

Conversation

ravichandran-blog
Copy link
Contributor

Q A
Bug fix? [ ]
New feature? [ x ]
New sample? [ ]
Related issues? fixes #X, partially #Y, mentioned in #Z

What's in this Pull Request?

Dynamic form control

This was referenced May 16, 2021
@AJIXuMuK AJIXuMuK merged commit 61c8dd8 into pnp:v2-dev May 21, 2021
@AJIXuMuK
Copy link
Collaborator

Thank you @ravichandran-blog for the PR!
It is a great addition to the library!

The PR has been merged with some additional modifications.
You can review the modifications in the history, but I want to point out some important edits for your future contributions.

Localization

All the texts were hardcoded. We are using standard SPFx localization mechanism to make the controls available on different languages.

Styling

Most of the colors were directly included in scss file. Usually in SPFx solutions it makes sense to use theme variables.

Testing the Functionality

Some of the methods/functions were failing in simple situations.
For example, saveIntoSharePoint in DynamicForm.tsx. It uploads a file using the next request:

let fileresult = await sp.web.getFolderByServerRelativeUrl(this.props.context.pageContext.web.serverRelativeUrl + "/SiteAssets/Lists/" + this.props.listId).files.add(file.fileName, resultcontent, false);

It will fail if SiteAssets/Lists/ListId folder (or any part of it) doesn't exist.

Another example: getLookUpValue in SPService.ts:

const data = await this._context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1);
if (data.ok) {
  const results = await data.json();
  if (results) {
    return [{ key: results.value[0][fieldName].ID, name: results.value[0][fieldName].Title }];
  }
}

We can pass if (results) condition, but the code will fail if results.value.length === 0 or results.value[0][fieldName] is undefined. And it happens if there is an item but the value for this specific field is not set.

Naming of the Methods

I would recommend to use more clear names for the methods based on what exactly is done.
For example, getListInfo in SPService. It actually requests fields for the list with additional filter based on content type and excluding some additional fields like read-only and hidden. So the name of the method confuses in that case.

Additional Remarks

listFeilds["value"].forEach(async (field) => {
  // do some async stuff
});

// code that should run after all array items are processed

forEach is always synchronous. It will not await for the async callback. You either need to use for loop or other approaches like async-foreach module.

let hiddenname = "";
let TermSetId = "";
let lookupField = "";
let selectedtags: any = [];

You're using different notations for variables names. It makes code harder to read. I would recommend to use camelCase notation everywhere.

Thank you again for the great feature! Hope this code review will be helpful!

@AJIXuMuK AJIXuMuK added this to the 2.8.0 milestone May 21, 2021
@ravichandran-blog
Copy link
Contributor Author

Hi @AJIXuMuK,

Many thanks! it is helpful

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