Merge branch 'react-list-form' of https://github.com/sharepointknight/sp-dev-fx-webparts into pr/1501

This commit is contained in:
Hugo Bernier 2020-09-23 23:37:11 -04:00
commit d2e09e3eac
3 changed files with 11 additions and 12 deletions

View File

@ -10,4 +10,4 @@
"paths": { "paths": {
"zippedPackage": "solution/FAQ-Accordion.sppkg" "zippedPackage": "solution/FAQ-Accordion.sppkg"
} }
} }

View File

@ -47,4 +47,4 @@
"ajv": "~5.2.2", "ajv": "~5.2.2",
"gulp": "~3.9.1" "gulp": "~3.9.1"
} }
} }

View File

@ -35,26 +35,25 @@ export default class ReactAccordion extends React.Component<IReactAccordionProps
} }
private getListItems(): void { private getListItems(): void {
if (typeof this.props.listId !== "undefined" && this.props.listId.length > 0) { if(typeof this.props.listId !== "undefined" && this.props.listId.length > 0) {
sp.web.lists.getById(this.props.listId).items.select("Title", "Content").get() sp.web.lists.getById(this.props.listId).items.select("Title","Content").get()
.then((results: Array<any>) => { .then((results: Array<any>) => {
this.setState({ this.setState({
items: results items: results
}); });
}) })
.catch((error: any) => { .catch((error:any) => {
console.log("Failed to get list items!"); console.log("Failed to get list items!");
console.log(error); console.log(error);
}); });
} }
} }
public componentDidUpdate(prevProps: IReactAccordionProps): void { public componentDidUpdate(prevProps:IReactAccordionProps): void {
if (prevProps.listId !== this.props.listId) { if(prevProps.listId !== this.props.listId) {
this.getListItems(); this.getListItems();
} }
if(prevProps.allowMultipleExpanded !== this.props.allowMultipleExpanded || prevProps.allowZeroExpanded !== this.props.allowZeroExpanded) { if(prevProps.allowMultipleExpanded !== this.props.allowMultipleExpanded || prevProps.allowZeroExpanded !== this.props.allowZeroExpanded) {
this.setState({ this.setState({
allowMultipleExpanded: this.props.allowMultipleExpanded, allowMultipleExpanded: this.props.allowMultipleExpanded,
@ -67,7 +66,7 @@ export default class ReactAccordion extends React.Component<IReactAccordionProps
const listSelected:boolean = typeof this.props.listId !== "undefined" && this.props.listId.length > 0; const listSelected:boolean = typeof this.props.listId !== "undefined" && this.props.listId.length > 0;
const { allowMultipleExpanded, allowZeroExpanded } = this.state; const { allowMultipleExpanded, allowZeroExpanded } = this.state;
return ( return (
<div className={styles.reactAccordion}> <div className={ styles.reactAccordion }>
{!listSelected && {!listSelected &&
<Placeholder <Placeholder
iconName='MusicInCollectionFill' iconName='MusicInCollectionFill'
@ -92,9 +91,9 @@ export default class ReactAccordion extends React.Component<IReactAccordionProps
</AccordionItemButton> </AccordionItemButton>
</AccordionItemHeading> </AccordionItemHeading>
<AccordionItemPanel> <AccordionItemPanel>
<p dangerouslySetInnerHTML={{ __html: item.Content }} /> <p dangerouslySetInnerHTML={{__html: item.Content}} />
</AccordionItemPanel> </AccordionItemPanel>
</AccordionItem> </AccordionItem>
); );
}) })
} }
@ -102,6 +101,6 @@ export default class ReactAccordion extends React.Component<IReactAccordionProps
</div> </div>
} }
</div> </div>
); );
} }
} }