Merge commit 'accda9ccda129906c1ebdb070ab90b728ab84e8f'
This commit is contained in:
commit
d76fee2ef0
|
@ -43,6 +43,7 @@ React-Cherry-Picked-Content | [Christophe Humbert](https://github.com/PathToShar
|
||||||
|
|
||||||
Version|Date|Comments
|
Version|Date|Comments
|
||||||
-------|----|--------
|
-------|----|--------
|
||||||
|
0.4.0|March 18, 2022|Update to library REST query
|
||||||
0.3.0|March 9, 2022|4 samples added
|
0.3.0|March 9, 2022|4 samples added
|
||||||
0.2.0|March 6, 2022|Refactoring
|
0.2.0|March 6, 2022|Refactoring
|
||||||
0.1.0|February 21, 2022|Initial draft
|
0.1.0|February 21, 2022|Initial draft
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "react-cherry-picked-content",
|
"name": "react-cherry-picked-content",
|
||||||
"version": "0.3.0",
|
"version": "0.4.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "react-cherry-picked-content",
|
"name": "react-cherry-picked-content",
|
||||||
"version": "0.3.0",
|
"version": "0.4.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -103,7 +103,7 @@ export default class CherryPickedContentWebPart extends BaseClientSideWebPart<IC
|
||||||
private getLibraryItemsList = (library) => {
|
private getLibraryItemsList = (library) => {
|
||||||
// Validate approved location
|
// Validate approved location
|
||||||
const filesLocation = this.approvedLibraries.filter(loc => loc.key == library)[0];
|
const filesLocation = this.approvedLibraries.filter(loc => loc.key == library)[0];
|
||||||
const filesQuery = window.location.origin + filesLocation.siteRelativeURL + "/_api/web/lists/getbytitle('" + filesLocation.library + "')/files?$select=Name";
|
const filesQuery = window.location.origin + filesLocation.siteRelativeURL + "/_api/web/lists/getbytitle('" + filesLocation.library + "')/Items?$select=FileLeafRef";
|
||||||
|
|
||||||
return this.context.spHttpClient.get(filesQuery, SPHttpClient.configurations.v1)
|
return this.context.spHttpClient.get(filesQuery, SPHttpClient.configurations.v1)
|
||||||
.then((response: SPHttpClientResponse) => response.json())
|
.then((response: SPHttpClientResponse) => response.json())
|
||||||
|
@ -119,7 +119,10 @@ export default class CherryPickedContentWebPart extends BaseClientSideWebPart<IC
|
||||||
this.getLibraryItemsList(this.properties.libraryPicker)
|
this.getLibraryItemsList(this.properties.libraryPicker)
|
||||||
.then((files): void => {
|
.then((files): void => {
|
||||||
// store items
|
// store items
|
||||||
this.libraryItemsList = files.map(file => file.Name).sort().map(name => { return { key: name, text: name }; });
|
this.libraryItemsList = files.map(file => file.FileLeafRef)
|
||||||
|
.filter(rf => rf.match(/\.(htm?l|txt)$/i))
|
||||||
|
.sort()
|
||||||
|
.map(name => ({ key: name, text: name }));
|
||||||
this.itemsDropdownDisabled = false;
|
this.itemsDropdownDisabled = false;
|
||||||
})
|
})
|
||||||
.then(() => this.context.propertyPane.refresh());
|
.then(() => this.context.propertyPane.refresh());
|
||||||
|
@ -144,7 +147,10 @@ export default class CherryPickedContentWebPart extends BaseClientSideWebPart<IC
|
||||||
.then((files): void => {
|
.then((files): void => {
|
||||||
if (files.length) {
|
if (files.length) {
|
||||||
// store items
|
// store items
|
||||||
this.libraryItemsList = files.map(file => { return { key: file.Name, text: file.Name }; });
|
this.libraryItemsList = files.map(file => file.FileLeafRef)
|
||||||
|
.filter(rf => rf.match(/\.(htm?l|txt)$/i))
|
||||||
|
.sort()
|
||||||
|
.map(name => ({ key: name, text: name }));
|
||||||
// enable item selector
|
// enable item selector
|
||||||
this.itemsDropdownDisabled = false;
|
this.itemsDropdownDisabled = false;
|
||||||
// refresh the item selector control by repainting the property pane
|
// refresh the item selector control by repainting the property pane
|
||||||
|
|
|
@ -5,12 +5,7 @@ import { escape } from '@microsoft/sp-lodash-subset';
|
||||||
|
|
||||||
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';
|
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';
|
||||||
import PortalIframe from './PortalIframe';
|
import PortalIframe from './PortalIframe';
|
||||||
|
import CherryPickedMemo from './CherryPickedMemo';
|
||||||
const CherryPickedDiv = ({ htmlFragment }) =>
|
|
||||||
<div ref={ref => { if (ref) { ref.innerHTML = ""; ref.appendChild(document.createRange().createContextualFragment(htmlFragment)); } }}>
|
|
||||||
</div>;
|
|
||||||
|
|
||||||
const MemoDiv = React.memo(CherryPickedDiv);
|
|
||||||
|
|
||||||
const CherryPickedContent: React.FunctionComponent<ICherryPickedContentProps> = (props) => {
|
const CherryPickedContent: React.FunctionComponent<ICherryPickedContentProps> = (props) => {
|
||||||
|
|
||||||
|
@ -70,13 +65,13 @@ const CherryPickedContent: React.FunctionComponent<ICherryPickedContentProps> =
|
||||||
else if (props.isolated) {
|
else if (props.isolated) {
|
||||||
return (
|
return (
|
||||||
<PortalIframe {...props}>
|
<PortalIframe {...props}>
|
||||||
<MemoDiv htmlFragment={htmlFragment} />
|
<CherryPickedMemo htmlFragment={htmlFragment} />
|
||||||
</PortalIframe>
|
</PortalIframe>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return (
|
return (
|
||||||
<MemoDiv htmlFragment={htmlFragment} />
|
<CherryPickedMemo htmlFragment={htmlFragment} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
const CherryPickedDiv = ({ htmlFragment }) =>
|
||||||
|
<div ref={ref => { if (ref) { ref.innerHTML = ""; ref.appendChild(document.createRange().createContextualFragment(htmlFragment)); } }}>
|
||||||
|
</div>;
|
||||||
|
|
||||||
|
const CherryPickedMemo = React.memo(CherryPickedDiv);
|
||||||
|
|
||||||
|
export default CherryPickedMemo;
|
Loading…
Reference in New Issue