Skip to content

Commit 378452f

Browse files
author
Alex Terentiev
committed
wip
1 parent 83d6a9d commit 378452f

File tree

5 files changed

+12
-87
lines changed

5 files changed

+12
-87
lines changed

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
340340
lookupListId = field["LookupList"];
341341
lookupField = field["LookupField"];
342342
if (item !== null) {
343-
defaultValue = await this._spService.getLookupValue(listId, listItemId, field.InternalName, context.pageContext.web.absoluteUrl);
343+
defaultValue = await this._spService.getLookupValue(listId, listItemId, field.InternalName, lookupField, context.pageContext.web.absoluteUrl);
344344
}
345345
else {
346346
defaultValue = [];
@@ -351,7 +351,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
351351
lookupListId = field["LookupList"];
352352
lookupField = field["LookupField"];
353353
if (item !== null) {
354-
defaultValue = await this._spService.getLookupValues(listId, listItemId, field.InternalName, context.pageContext.web.absoluteUrl);
354+
defaultValue = await this._spService.getLookupValues(listId, listItemId, field.InternalName, lookupField, context.pageContext.web.absoluteUrl);
355355
}
356356
else {
357357
defaultValue = [];

src/services/SPService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,16 @@ export default class SPService implements ISPService {
430430
return;
431431
}
432432

433-
public async getLookupValue(listId: string, listItemID: number, fieldName: string, webUrl?: string): Promise<any[]> {
433+
public async getLookupValue(listId: string, listItemID: number, fieldName: string, lookupFieldName: string | undefined, webUrl?: string): Promise<any[]> {
434434
try {
435435
const webAbsoluteUrl = !webUrl ? this._context.pageContext.web.absoluteUrl : webUrl;
436-
let apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/items(${listItemID})/?@listId=guid'${encodeURIComponent(listId)}'&$select=${fieldName}/ID,${fieldName}/Title&$expand=${fieldName}`;
436+
let apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/items(${listItemID})/?@listId=guid'${encodeURIComponent(listId)}'&$select=${fieldName}/ID,${fieldName}/${lookupFieldName || 'Title'}&$expand=${fieldName}`;
437437

438438
const data = await this._context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1);
439439
if (data.ok) {
440440
const result = await data.json();
441441
if (result && result[fieldName]) {
442-
return [{ key: result[fieldName].ID, name: result[fieldName].Title }];
442+
return [{ key: result[fieldName].ID, name: result[fieldName][lookupFieldName || 'Title'] }];
443443
}
444444
}
445445

@@ -450,18 +450,18 @@ export default class SPService implements ISPService {
450450
}
451451
}
452452

453-
public async getLookupValues(listId: string, listItemID: number, fieldName: string, webUrl?: string): Promise<any[]> {
453+
public async getLookupValues(listId: string, listItemID: number, fieldName: string, lookupFieldName: string | undefined, webUrl?: string): Promise<any[]> {
454454
try {
455455
const webAbsoluteUrl = !webUrl ? this._context.pageContext.web.absoluteUrl : webUrl;
456-
let apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/items(${listItemID})?@listId=guid'${encodeURIComponent(listId)}'&$select=${fieldName}/ID,${fieldName}/Title&$expand=${fieldName}`;
456+
let apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/items(${listItemID})?@listId=guid'${encodeURIComponent(listId)}'&$select=${fieldName}/ID,${fieldName}/${lookupFieldName || 'Title'}&$expand=${fieldName}`;
457457

458458
const data = await this._context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1);
459459
if (data.ok) {
460460
const result = await data.json();
461461
if (result && result[fieldName]) {
462462
let lookups = [];
463463
result[fieldName].forEach(element => {
464-
lookups.push({ key: element.ID, name: element.Title });
464+
lookups.push({ key: element.ID, name: element[lookupFieldName || 'Title'] });
465465
});
466466
return lookups;
467467
}

src/webparts/controlsTest/ControlsTestWebPart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "@microsoft/sp-property-pane";
1616
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
1717

18-
import ControlsTest from "./components/ControlsTest";
18+
import ControlsTest from "./components/ControlsTest_SingleComponent";
1919
import { IControlsTestProps } from "./components/IControlsTestProps";
2020
import { IControlsTestWebPartProps } from "./IControlsTestWebPartProps";
2121

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
888888
<div className={styles.controlsTest}>
889889
<div className="ms-font-m">
890890
{/* Change the list Id and list item id before you start to test this control */}
891-
{/* <DynamicForm context={this.props.context} listId={"3071c058-549f-461d-9d73-8b9a52049a80"} listItemId={1} onCancelled={() => { console.log('Cancelled'); }} onSubmitted={async (listItem) => { let itemdata = await listItem.get(); console.log(itemdata["ID"]); }}></DynamicForm> */}
891+
<DynamicForm context={this.props.context} listId={"b1416fca-dc77-4198-a082-62a7657dcfa9"} onCancelled={() => { console.log('Cancelled'); }} onSubmitted={async (listItem) => { let itemdata = await listItem.get(); console.log(itemdata["ID"]); }}></DynamicForm>
892892
</div>
893893
<WebPartTitle displayMode={this.props.displayMode}
894894
title={this.props.title}

src/webparts/controlsTest/components/ControlsTest_SingleComponent.tsx

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -464,87 +464,12 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
464464
}];
465465

466466
const onContextualMenuClick = (id: string) => {
467-
this.setState({termPanelIsOpen: true, actionTermId: id});
467+
this.setState({ termPanelIsOpen: true, actionTermId: id });
468468
};
469469

470470
return (
471471
<div>
472-
<ModernTaxonomyPicker
473-
allowMultipleSelections={true}
474-
termSetId={"36d21c3f-b83b-4acc-a223-4df6fa8e946d"}
475-
panelTitle="Panel title"
476-
label={"Field title"}
477-
context={this.props.context}
478-
required={false}
479-
// initialValues={[{labels: [{name: "Subprocess A1", isDefault: true, languageTag: "en-US"}], id: "29eced8f-cf08-454b-bd9e-6443bc0a0f5e", childrenCount: 0, createdDateTime: "", lastModifiedDateTime: "", descriptions: [], customSortOrder: [], properties: [], localProperties: [], isDeprecated: false, isAvailableForTagging: [], topicRequested: false}]}
480-
// onChange={(values) => alert(values.map((value) => `${value?.id} - ${value?.labels[0].name}`).join("\n"))}
481-
disabled={false}
482-
customPanelWidth={700}
483-
isLightDismiss={false}
484-
isBlocking={false}
485-
onRenderActionButton={(termStoreInfo: ITermStoreInfo, termSetInfo: ITermSetInfo, termInfo?: ITermInfo) => {
486-
const menuIcon: IIconProps = { iconName: 'MoreVertical', "aria-label": "More actions", style: { fontSize: "medium" } };
487-
if (termInfo) {
488-
const menuProps: IContextualMenuProps = {
489-
items: [
490-
{
491-
key: 'addTerm',
492-
text: 'Add Term',
493-
iconProps: { iconName: 'Tag' },
494-
onClick: () => onContextualMenuClick(termInfo.id)
495-
},
496-
{
497-
key: 'deleteTerm',
498-
text: 'Delete term',
499-
iconProps: { iconName: 'Untag' },
500-
onClick: () => onContextualMenuClick(termInfo.id)
501-
},
502-
],
503-
};
504-
505-
return (
506-
<IconButton
507-
menuProps={menuProps}
508-
menuIconProps={menuIcon}
509-
style={this.state.clickedActionTerm && this.state.clickedActionTerm.id === termInfo.id ? {opacity: 1} : null}
510-
onMenuClick={(ev?: React.MouseEvent<HTMLElement, MouseEvent> | React.KeyboardEvent<HTMLElement>, button?: IButtonProps) => {
511-
this.setState({clickedActionTerm: termInfo});
512-
}}
513-
onAfterMenuDismiss={() => this.setState({clickedActionTerm: null})}
514-
/>
515-
);
516-
}
517-
else {
518-
const menuProps: IContextualMenuProps = {
519-
items: [
520-
{
521-
key: 'addTerm',
522-
text: 'Add term',
523-
iconProps: { iconName: 'Tag' },
524-
onClick: () => onContextualMenuClick(termSetInfo.id)
525-
},
526-
],
527-
};
528-
return (
529-
<IconButton
530-
menuProps={menuProps}
531-
menuIconProps={menuIcon}
532-
style={{opacity: 1}}
533-
/>
534-
);
535-
}
536-
}}
537-
/>
538-
<Panel
539-
isOpen={this.state.termPanelIsOpen}
540-
onDismiss={() => this.setState({termPanelIsOpen: false, actionTermId: null})}
541-
hasCloseButton={true}
542-
isLightDismiss={false}
543-
isBlocking={false}
544-
545-
>
546-
<span>{this.state.actionTermId && this.state.actionTermId}</span>
547-
</Panel>
472+
<DynamicForm context={this.props.context} listId={"b1416fca-dc77-4198-a082-62a7657dcfa9"} listItemId={1} onCancelled={() => { console.log('Cancelled'); }} onSubmitted={async (listItem) => { let itemdata = await listItem.get(); console.log(itemdata["ID"]); }}></DynamicForm>
548473
</div>
549474
);
550475
}

0 commit comments

Comments
 (0)