diff --git a/samples/react-cherry-picked-content/README.md b/samples/react-cherry-picked-content/README.md index 943cd8e43..edee9969e 100644 --- a/samples/react-cherry-picked-content/README.md +++ b/samples/react-cherry-picked-content/README.md @@ -43,6 +43,7 @@ React-Cherry-Picked-Content | [Christophe Humbert](https://github.com/PathToShar Version|Date|Comments -------|----|-------- +0.4.0|March 18, 2022|Update to library REST query 0.3.0|March 9, 2022|4 samples added 0.2.0|March 6, 2022|Refactoring 0.1.0|February 21, 2022|Initial draft diff --git a/samples/react-cherry-picked-content/package-lock.json b/samples/react-cherry-picked-content/package-lock.json index bfdf90d19..94e950efe 100644 --- a/samples/react-cherry-picked-content/package-lock.json +++ b/samples/react-cherry-picked-content/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-cherry-picked-content", - "version": "0.3.0", + "version": "0.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/samples/react-cherry-picked-content/package.json b/samples/react-cherry-picked-content/package.json index 22c412627..2acfd3b92 100644 --- a/samples/react-cherry-picked-content/package.json +++ b/samples/react-cherry-picked-content/package.json @@ -1,6 +1,6 @@ { "name": "react-cherry-picked-content", - "version": "0.3.0", + "version": "0.4.1", "private": true, "main": "lib/index.js", "scripts": { diff --git a/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/CherryPickedContentWebPart.ts b/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/CherryPickedContentWebPart.ts index e29ca3922..9b938ad40 100644 --- a/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/CherryPickedContentWebPart.ts +++ b/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/CherryPickedContentWebPart.ts @@ -103,7 +103,7 @@ export default class CherryPickedContentWebPart extends BaseClientSideWebPart { // Validate approved location 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) .then((response: SPHttpClientResponse) => response.json()) @@ -119,7 +119,10 @@ export default class CherryPickedContentWebPart extends BaseClientSideWebPart { // 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; }) .then(() => this.context.propertyPane.refresh()); @@ -144,7 +147,10 @@ export default class CherryPickedContentWebPart extends BaseClientSideWebPart { if (files.length) { // 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 this.itemsDropdownDisabled = false; // refresh the item selector control by repainting the property pane diff --git a/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/components/CherryPickedContent.tsx b/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/components/CherryPickedContent.tsx index be1f768ec..bfa29ae34 100644 --- a/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/components/CherryPickedContent.tsx +++ b/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/components/CherryPickedContent.tsx @@ -5,12 +5,7 @@ import { escape } from '@microsoft/sp-lodash-subset'; import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http'; import PortalIframe from './PortalIframe'; - -const CherryPickedDiv = ({ htmlFragment }) => -
{ if (ref) { ref.innerHTML = ""; ref.appendChild(document.createRange().createContextualFragment(htmlFragment)); } }}> -
; - -const MemoDiv = React.memo(CherryPickedDiv); +import CherryPickedMemo from './CherryPickedMemo'; const CherryPickedContent: React.FunctionComponent = (props) => { @@ -70,13 +65,13 @@ const CherryPickedContent: React.FunctionComponent = else if (props.isolated) { return ( - + ); } else { return ( - + ); } }; diff --git a/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/components/CherryPickedMemo.tsx b/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/components/CherryPickedMemo.tsx new file mode 100644 index 000000000..5063ae8cf --- /dev/null +++ b/samples/react-cherry-picked-content/src/webparts/cherryPickedContent/components/CherryPickedMemo.tsx @@ -0,0 +1,9 @@ +import * as React from 'react'; + +const CherryPickedDiv = ({ htmlFragment }) => +
{ if (ref) { ref.innerHTML = ""; ref.appendChild(document.createRange().createContextualFragment(htmlFragment)); } }}> +
; + +const CherryPickedMemo = React.memo(CherryPickedDiv); + +export default CherryPickedMemo; \ No newline at end of file