Merge pull request #2049 from Abderahman88/patch-2034

[react-advanced-page-properties] Fix webpart on sites in a different language
This commit is contained in:
Hugo Bernier 2021-09-23 02:18:50 -04:00 committed by GitHub
commit e8e49c3e18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 19 deletions

View File

@ -38,18 +38,14 @@ None
Solution|Author(s) Solution|Author(s)
--------|--------- --------|---------
src/react-advanced-page-properties | [Mike Homol](https://homol.work), Principal Consultant, [ThreeWill](https://threewill.com/) src/react-advanced-page-properties | [Mike Homol](https://homol.work), Principal Consultant, [ThreeWill](https://threewill.com/)
react-advanced-page-properties | Abderahman Moujahid
## Version history ## Version history
Version|Date|Comments Version|Date|Comments
-------|----|-------- -------|----|--------
1.0|March 30, 2021|Initial release 1.0.0|March 30, 2021|Initial release
1.0.1|September 22, 2021|Added support for multi-language sites
## Disclaimer
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
---
## Minimal Path to Awesome ## Minimal Path to Awesome
@ -59,17 +55,15 @@ Version|Date|Comments
- **npm install** - **npm install**
- **gulp serve** - **gulp serve**
> Include any additional steps as needed.
## Features ## Features
> Add the part ### Add the part
Once the solution is installed in the app catalog and the app has been added to the site, you should see it available to a page. Once the solution is installed in the app catalog and the app has been added to the site, you should see it available to a page.
![add the part](./assets/add-to-page.png) ![add the part](./assets/add-to-page.png)
> Familiarity is key ### Familiarity is key
This web part tries to mimic the original Page Properties web part as much as possible. You should recognize the functionality of the property setup. This web part tries to mimic the original Page Properties web part as much as possible. You should recognize the functionality of the property setup.

View File

@ -15,7 +15,7 @@
"- Improved support for dates" "- Improved support for dates"
], ],
"creationDateTime": "2021-03-30", "creationDateTime": "2021-03-30",
"updateDateTime": "2021-03-30", "updateDateTime": "2021-09-22",
"products": [ "products": [
"SharePoint", "SharePoint",
"Office" "Office"
@ -57,6 +57,12 @@
"pictureUrl": "https://github.com/mhomol.png", "pictureUrl": "https://github.com/mhomol.png",
"name": "Mike Homol", "name": "Mike Homol",
"twitter": "homol" "twitter": "homol"
},
{
"gitHubAccount": "Abderahman88",
"company": "",
"pictureUrl": "https://avatars.githubusercontent.com/u/36161889?s=460\u0026u=afdd5f6681bc375ee3811482dec79824c12d8170\u0026v=4",
"name": "Abderahman Moujahid"
} }
], ],
"references": [ "references": [

View File

@ -3,7 +3,7 @@
"solution": { "solution": {
"name": "Advanced Page Properties", "name": "Advanced Page Properties",
"id": "daae06a2-8599-445c-93c0-3bd739305f56", "id": "daae06a2-8599-445c-93c0-3bd739305f56",
"version": "1.0.0.0", "version": "1.0.1.0",
"includeClientSideAssets": true, "includeClientSideAssets": true,
"isDomainIsolated": false, "isDomainIsolated": false,
"developer": { "developer": {

View File

@ -68,13 +68,13 @@ export default class AdvancedPagePropertiesWebPart extends BaseClientSideWebPart
private async getPageProperties(): Promise<void> { private async getPageProperties(): Promise<void> {
Log.Write("Getting Site Page fields..."); Log.Write("Getting Site Page fields...");
const list = sp.web.lists.getByTitle("Site Pages"); const list = await sp.web.lists.ensureSiteAssetsLibrary();
const fi = await list.fields(); const fi = await list.fields();
this.availableProperties = []; this.availableProperties = [];
Log.Write(`${fi.length.toString()} fields retrieved!`); Log.Write(`${fi.length.toString()} fields retrieved!`);
fi.forEach((f) => { fi.forEach((f) => {
if (!f.FromBaseType && !f.Hidden && !f.Sealed && f.SchemaXml.indexOf("ShowInListSettings=\"FALSE\"") === -1 if (!f.FromBaseType && !f.Hidden && f.SchemaXml.indexOf("ShowInListSettings=\"FALSE\"") === -1
&& f.TypeAsString !== "Boolean" && f.TypeAsString !== "Note" && f.TypeAsString !== "User") { && f.TypeAsString !== "Boolean" && f.TypeAsString !== "Note" && f.TypeAsString !== "User") {
this.availableProperties.push({ key: f.InternalName, text: f.Title }); this.availableProperties.push({ key: f.InternalName, text: f.Title });
Log.Write(f.TypeAsString); Log.Write(f.TypeAsString);

View File

@ -42,9 +42,9 @@ const AdvancedPageProperties: React.FunctionComponent<IAdvancedPagePropertiesPro
// Get the value(s) for the field from the list item itself // Get the value(s) for the field from the list item itself
var allValues: any = {}; var allValues: any = {};
const siteAssetsList = await sp.web.lists.ensureSitePagesLibrary();
if (props.context.pageContext.listItem !== undefined && props.context.pageContext.listItem !== null) { if (props.context.pageContext.listItem !== undefined && props.context.pageContext.listItem !== null) {
allValues = await sp.web.lists.getByTitle("Site Pages").items.getById(props.context.pageContext.listItem.id).select(...props.selectedProperties).get(); allValues = await siteAssetsList.items.getById(props.context.pageContext.listItem.id).select(...props.selectedProperties).get();
console.log(allValues);
} }
for (let i = 0; i < props.selectedProperties.length; i++) { for (let i = 0; i < props.selectedProperties.length; i++) {
@ -53,7 +53,7 @@ const AdvancedPageProperties: React.FunctionComponent<IAdvancedPagePropertiesPro
Log.Write(`Selected Property: ${prop}`); Log.Write(`Selected Property: ${prop}`);
// Get field information, in case anything is needed in conjunction with value types // Get field information, in case anything is needed in conjunction with value types
const field = await sp.web.lists.getByTitle("Site Pages").fields.getByInternalNameOrTitle(prop)(); const field = await siteAssetsList.fields.getByInternalNameOrTitle(prop)();
// Establish the values array // Establish the values array
var values: any[] = []; var values: any[] = [];
@ -123,7 +123,6 @@ const AdvancedPageProperties: React.FunctionComponent<IAdvancedPagePropertiesPro
* @returns * @returns
*/ */
const RenderPagePropValue = (prop: PageProperty) => { const RenderPagePropValue = (prop: PageProperty) => {
console.log(prop);
var retVal = _.map(prop.values, (val) => { var retVal = _.map(prop.values, (val) => {
if (val !== null) { if (val !== null) {
switch (prop.info.TypeAsString) { switch (prop.info.TypeAsString) {