Skip to content

Commit b66e2d3

Browse files
authored
Merge pull request #1335 from PaoloPia/dynamicFormDocumentSet
Improvements to DynamicForm to support creation of document sets
2 parents 4186a81 + 1481d8b commit b66e2d3

File tree

5 files changed

+80
-15
lines changed

5 files changed

+80
-15
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 3.11.0
44

5+
### New control(s)
6+
7+
- `ProgressStepsIndicator`: New control that shows a progress of steps. [#1322](https://github.com/pnp/sp-dev-fx-controls-react/pull/1322)
8+
59
### Enhancements
610

711
- `DynamicForm`: Add taxonomy tree to test harness [#1269](https://github.com/pnp/sp-dev-fx-controls-react/pull/1269)
@@ -10,6 +14,7 @@
1014
- `DynamicForm`: Support for hidden fields [#1307](https://github.com/pnp/sp-dev-fx-controls-react/pull/1307/)
1115
- `Placeholder`: Documentation example to only display in edit mode [#1280](https://github.com/pnp/sp-dev-fx-controls-react/issues/1280)
1216
- `DynamicForm`: Update documentation regarding onBeforeSubmit [#1319](https://github.com/pnp/sp-dev-fx-controls-react/issues/1319)
17+
- `DynamicForm`: FirstDayOfWeek in DatePickers from webs regional settings [#1317](https://github.com/pnp/sp-dev-fx-controls-react/issues/1317)
1318

1419
### Fixes
1520

@@ -20,10 +25,11 @@
2025
- `TaxonomyPicker`: Does not show term set labels in Version 3.10.0 [#1299](https://github.com/pnp/sp-dev-fx-controls-react/issues/1299)
2126
- `TaxonomyPicker`: Dynamic form select term not working [#1303](https://github.com/pnp/sp-dev-fx-controls-react/issues/1303)
2227
- `DynamicForm`: Check if hiddenfields property is undefined [#1314](https://github.com/pnp/sp-dev-fx-controls-react/pull/1314)
28+
- `DynamicForm`: PeoplePicker preselects wrong user if PrincipalType allows groups [#1315](https://github.com/pnp/sp-dev-fx-controls-react/issues/1315)
2329

2430
### Contributors
2531

26-
Special thanks to our contributors (in alphabetical order): [Chad Eiserloh](https://github.com/c-eiser13), [Hilton Giesenow](https://github.com/HiltonGiesenow), [Jake Stanger](https://github.com/JakeStanger), [Jasey Waegebaert](https://github.com/Jwaegebaert), [Josef Benda](https://github.com/SmarterJB), [Mark Bice](https://github.com/mbice), [Paolo Pialorsi](https://github.com/PaoloPia), [Victor Romanov](https://github.com/VRomanovTau).
32+
Special thanks to our contributors (in alphabetical order): [Chad Eiserloh](https://github.com/c-eiser13), [Hilton Giesenow](https://github.com/HiltonGiesenow), [Jake Stanger](https://github.com/JakeStanger), [Jasey Waegebaert](https://github.com/Jwaegebaert), [João Mendes](https://github.com/joaojmendes), [Josef Benda](https://github.com/SmarterJB), [Mark Bice](https://github.com/mbice), [Paolo Pialorsi](https://github.com/PaoloPia), [Victor Romanov](https://github.com/VRomanovTau).
2733

2834
## 3.10.0
2935

docs/documentation/docs/about/release-notes.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 3.11.0
44

5+
### New control(s)
6+
7+
- `ProgressStepsIndicator`: New control that shows a progress of steps. [#1322](https://github.com/pnp/sp-dev-fx-controls-react/pull/1322)
8+
59
### Enhancements
610

711
- `DynamicForm`: Add taxonomy tree to test harness [#1269](https://github.com/pnp/sp-dev-fx-controls-react/pull/1269)
@@ -10,6 +14,7 @@
1014
- `DynamicForm`: Support for hidden fields [#1307](https://github.com/pnp/sp-dev-fx-controls-react/pull/1307/)
1115
- `Placeholder`: Documentation example to only display in edit mode [#1280](https://github.com/pnp/sp-dev-fx-controls-react/issues/1280)
1216
- `DynamicForm`: Update documentation regarding onBeforeSubmit [#1319](https://github.com/pnp/sp-dev-fx-controls-react/issues/1319)
17+
- `DynamicForm`: FirstDayOfWeek in DatePickers from webs regional settings [#1317](https://github.com/pnp/sp-dev-fx-controls-react/issues/1317)
1318

1419
### Fixes
1520

@@ -20,10 +25,11 @@
2025
- `TaxonomyPicker`: Does not show term set labels in Version 3.10.0 [#1299](https://github.com/pnp/sp-dev-fx-controls-react/issues/1299)
2126
- `TaxonomyPicker`: Dynamic form select term not working [#1303](https://github.com/pnp/sp-dev-fx-controls-react/issues/1303)
2227
- `DynamicForm`: Check if hiddenfields property is undefined [#1314](https://github.com/pnp/sp-dev-fx-controls-react/pull/1314)
28+
- `DynamicForm`: PeoplePicker preselects wrong user if PrincipalType allows groups [#1315](https://github.com/pnp/sp-dev-fx-controls-react/issues/1315)
2329

2430
### Contributors
2531

26-
Special thanks to our contributors (in alphabetical order): [Chad Eiserloh](https://github.com/c-eiser13), [Hilton Giesenow](https://github.com/HiltonGiesenow), [Jake Stanger](https://github.com/JakeStanger), [Jasey Waegebaert](https://github.com/Jwaegebaert), [Josef Benda](https://github.com/SmarterJB), [Mark Bice](https://github.com/mbice), [Paolo Pialorsi](https://github.com/PaoloPia), [Victor Romanov](https://github.com/VRomanovTau).
32+
Special thanks to our contributors (in alphabetical order): [Chad Eiserloh](https://github.com/c-eiser13), [Hilton Giesenow](https://github.com/HiltonGiesenow), [Jake Stanger](https://github.com/JakeStanger), [Jasey Waegebaert](https://github.com/Jwaegebaert), [João Mendes](https://github.com/joaojmendes), [Josef Benda](https://github.com/SmarterJB), [Mark Bice](https://github.com/mbice), [Paolo Pialorsi](https://github.com/PaoloPia), [Victor Romanov](https://github.com/VRomanovTau).
2733

2834
## 3.10.0
2935

src/common/telemetry/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const version: string = "3.10.0";
1+
export const version: string = "3.11.0";

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import styles from './DynamicForm.module.scss';
1616
import { IDynamicFormProps } from './IDynamicFormProps';
1717
import { IDynamicFormState } from './IDynamicFormState';
1818

19+
import '@pnp/sp/lists';
20+
import '@pnp/sp/content-types';
21+
import '@pnp/sp/folders';
22+
import '@pnp/sp/items';
23+
1924
const stackTokens: IStackTokens = { childrenGap: 20 };
2025

2126
/**
@@ -103,6 +108,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
103108
const {
104109
listId,
105110
listItemId,
111+
contentTypeId,
106112
onSubmitted,
107113
onBeforeSubmit,
108114
onSubmitError
@@ -215,6 +221,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
215221
}
216222
}
217223

224+
// If we have the item ID, we simply need to update it
218225
if (listItemId) {
219226
try {
220227
const iur = await sp.web.lists.getById(listId).items.getById(listItemId).update(objects);
@@ -230,20 +237,61 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
230237
}
231238

232239
}
240+
// Otherwise, depending on the content type ID of the item, if any, we need to behave accordingly
233241
else {
234-
try {
235-
const iar = await sp.web.lists.getById(listId).items.add(objects);
236-
if (onSubmitted) {
237-
onSubmitted(iar.data, this.props.returnListItemInstanceOnSubmit !== false ? iar.item : undefined);
242+
if (contentTypeId === undefined || contentTypeId === '' || !contentTypeId.startsWith('0x0120')) {
243+
// We are adding a new list item
244+
try {
245+
const iar = await sp.web.lists.getById(listId).items.add(objects);
246+
if (onSubmitted) {
247+
onSubmitted(iar.data, this.props.returnListItemInstanceOnSubmit !== false ? iar.item : undefined);
248+
}
249+
}
250+
catch (error) {
251+
if (onSubmitError) {
252+
onSubmitError(objects, error);
253+
}
254+
console.log("Error", error);
255+
}
256+
} else if (contentTypeId !== undefined && contentTypeId !== '' && contentTypeId.startsWith('0x0120')) {
257+
// We are adding a folder or a Document Set
258+
try {
259+
const idField = 'ID';
260+
const titleField = 'Title';
261+
const contentTypeIdField = 'ContentTypeId';
262+
263+
const library = await sp.web.lists.getById(listId);
264+
const folderTitle = (objects[titleField] !== undefined && objects[titleField] !== '') ?
265+
(objects[titleField] as string).replace(/["|*|:|<|>|?|/|\\||]/g, "_") : // Replace not allowed chars in folder name
266+
''; // Empty string will be replaced by SPO with Folder Item ID
267+
const newFolder = await library.rootFolder.addSubFolderUsingPath(folderTitle);
268+
const fields = await newFolder.listItemAllFields();
269+
if (fields[idField]) {
270+
271+
// Read the ID of the just created folder or Document Set
272+
const folderId = fields[idField];
273+
274+
// Set the content type ID for the target item
275+
objects[contentTypeIdField] = contentTypeId;
276+
277+
// Update the just created folder or Document Set
278+
const iur = await library.items.getById(folderId).update(objects);
279+
if (onSubmitted) {
280+
onSubmitted(iur.data, this.props.returnListItemInstanceOnSubmit !== false ? iur.item : undefined);
281+
}
282+
} else {
283+
throw new Error('Unable to read the ID of the just created folder or Document Set');
284+
}
238285
}
239-
}
240-
catch (error) {
241-
if (onSubmitError) {
242-
onSubmitError(objects, error);
286+
catch (error) {
287+
if (onSubmitError) {
288+
onSubmitError(objects, error);
289+
}
290+
console.log("Error", error);
243291
}
244-
console.log("Error", error);
245292
}
246293
}
294+
247295
this.setState({
248296
isSaving: false
249297
});
@@ -313,10 +361,10 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
313361
const defaultContentType = await spList.contentTypes.select("Id", "Name").get();
314362
contentTypeId = defaultContentType[0].Id.StringValue;
315363
}
316-
const listFeilds = await this.getFormFields(listId, contentTypeId, this.webURL);
364+
const listFields = await this.getFormFields(listId, contentTypeId, this.webURL);
317365
const tempFields: IDynamicFieldProps[] = [];
318366
let order: number = 0;
319-
const responseValue = listFeilds.value;
367+
const responseValue = listFields.value;
320368
const hiddenFields = this.props.hiddenFields !== undefined ? this.props.hiddenFields : [];
321369
let defaultDayOfWeek: number = 0;
322370
for (let i = 0, len = responseValue.length; i < len; i++) {
@@ -537,7 +585,11 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
537585
const webAbsoluteUrl = !webUrl ? this.webURL : webUrl;
538586
let apiUrl = '';
539587
if (contentTypeId !== undefined && contentTypeId !== '') {
540-
apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/contenttypes('${contentTypeId}')/fields?@listId=guid'${encodeURIComponent(listId)}'&$filter=ReadOnlyField eq false and Hidden eq false and (FromBaseType eq false or StaticName eq 'Title')`;
588+
if (contentTypeId.startsWith('0x0120')) {
589+
apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/contenttypes('${contentTypeId}')/fields?@listId=guid'${encodeURIComponent(listId)}'&$filter=ReadOnlyField eq false and (Hidden eq false or StaticName eq 'Title') and (FromBaseType eq false or StaticName eq 'Title')`;
590+
} else {
591+
apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/contenttypes('${contentTypeId}')/fields?@listId=guid'${encodeURIComponent(listId)}'&$filter=ReadOnlyField eq false and Hidden eq false and (FromBaseType eq false or StaticName eq 'Title')`;
592+
}
541593
}
542594
else {
543595
apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/fields?@listId=guid'${encodeURIComponent(listId)}'&$filter=ReadOnlyField eq false and Hidden eq false and (FromBaseType eq false or StaticName eq 'Title')`;

src/controls/dynamicForm/dynamicField/DynamicField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
222222
defaultSelectedItems={defaultValue}
223223
columnInternalName={lookupField}
224224
className={styles.feildDisplay}
225+
enableDefaultSuggestions={true}
225226
keyColumnInternalName='Id'
226227
itemLimit={1}
227228
onSelectedItem={(newValue) => { this.onChange(newValue); }}

0 commit comments

Comments
 (0)