Updated react-page-hierarchy to spfx 1.14;

Updated pnpjs to 3.0 and pnp controls to latest
This commit is contained in:
Nick Brown 2022-03-24 11:10:00 +00:00
parent 1049c13a48
commit 1b4bd5f3f5
19 changed files with 15913 additions and 8043 deletions

View File

@ -1,25 +0,0 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# change these settings to your own preference
indent_style = space
indent_size = 2
# we recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[{package,bower}.json]
indent_style = space
indent_size = 2

View File

@ -30,3 +30,5 @@ obj
# Styles Generated Code
*.scss.ts
release

View File

@ -0,0 +1,16 @@
!dist
config
gulpfile.js
release
src
temp
tsconfig.json
tslint.json
*.log
.yo-rc.json
.vscode

View File

@ -2,7 +2,7 @@
"@microsoft/generator-sharepoint": {
"isCreatingSolution": true,
"environment": "spo",
"version": "1.10.0",
"version": "1.14.0",
"libraryName": "react-pages-hierarchy",
"libraryId": "89758fb6-85e2-4e2b-ac88-4f4e7e5f60cb",
"packageManager": "npm",

View File

@ -1,4 +0,0 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}

View File

@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
"workingDir": "./temp/deploy/",
"workingDir": "./release/assets/",
"account": "<!-- STORAGE ACCOUNT NAME -->",
"container": "react-pages-hierarchy",
"accessKey": "<!-- ACCESS KEY -->"

View File

@ -3,9 +3,44 @@
"solution": {
"name": "react-pages-hierarchy",
"id": "89758fb6-85e2-4e2b-ac88-4f4e7e5f60cb",
"version": "1.0.1.0",
"title": "Pages Hierarchy",
"version": "1.0.2.0",
"includeClientSideAssets": true,
"isDomainIsolated": false
"isDomainIsolated": false,
"developer": {
"name": "Bo George",
"privacyUrl": "",
"termsOfUseUrl": "",
"websiteUrl": "https://github.com/bogeorge",
"mpnId": "Undefined-1.14.0"
},
"metadata": {
"shortDescription": {
"default": "This web part allows users to create a faux page hierarchy in their pages library and use it for page-to-page navigation"
},
"longDescription": {
"default": "This web part allows users to create a faux page hierarchy in their pages library and use it for page-to-page navigation. It will ask you to create a page parent property on first use which is then used by the web part to either show a breadcrumb of the current pages ancestors or buttons for the pages children."
},
"screenshotPaths": [
"https://github.com/pnp/sp-dev-fx-webparts/blob/main/samples/react-pages-hierarchy/assets/PagesHierarchy.gif"
],
"videoUrl": "",
"categories": []
},
"features": [
{
"title": "Breadcrumbs",
"description": "Displays breadcrumbs to the current page",
"id": "ce42762f-a823-4f12-80b2-b708cdebfaa4",
"version": "1.0.2.0"
},
{
"title": "Child Pages",
"description": "Displays a list of child pages",
"id": "ce42762f-a823-4f12-80b2-b708cdebfaa5",
"version": "1.0.2.0"
}
]
},
"paths": {
"zippedPackage": "solution/react-pages-hierarchy.sppkg"

View File

@ -2,7 +2,7 @@
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://localhost:5432/workbench",
"initialPage": "https://enter-your-SharePoint-site/_layouts/workbench.aspx",
"api": {
"port": 5432,
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"

View File

@ -19,6 +19,18 @@ build.configureWebpack.mergeConfig({
}
});
var getTasks = build.rig.getTasks;
build.rig.getTasks = function () {
var result = getTasks.call(build.rig);
result.set('serve', result.get('serve-deprecated'));
return result;
};
// disable tslint
build.tslintCmd.enabled = false;
build.initialize(require('gulp'));
var runSequence = require('run-sequence');

File diff suppressed because it is too large Load Diff

View File

@ -1,50 +1,42 @@
{
"name": "react-pages-hierarchy",
"version": "1.0.1",
"version": "1.0.2",
"private": true,
"main": "lib/index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.10.0",
"@microsoft/sp-lodash-subset": "1.10.0",
"@microsoft/sp-office-ui-fabric-core": "1.10.0",
"@microsoft/sp-property-pane": "1.10.0",
"@microsoft/sp-webpart-base": "1.10.0",
"@pnp/common": "^2.0.3",
"@pnp/logging": "^2.0.3",
"@pnp/odata": "^2.0.3",
"@pnp/sp": "^2.0.3",
"@pnp/spfx-controls-react": "1.17.0",
"@pnp/spfx-property-controls": "1.17.0",
"@types/es6-promise": "0.0.33",
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"@types/webpack-env": "1.13.1",
"office-ui-fabric-react": "6.189.2",
"react": "16.8.5",
"react-dom": "16.8.5",
"@microsoft/rush-stack-compiler-4.2": "^0.1.2",
"@microsoft/sp-core-library": "1.14.0",
"@microsoft/sp-lodash-subset": "1.14.0",
"@microsoft/sp-office-ui-fabric-core": "1.14.0",
"@microsoft/sp-property-pane": "1.14.0",
"@microsoft/sp-webpart-base": "1.14.0",
"@pnp/sp": "^3.1.0",
"@pnp/spfx-controls-react": "^3.7.2",
"@pnp/spfx-property-controls": "^3.6.0",
"office-ui-fabric-react": "7.174.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-resize-detector": "^4.2.1"
},
"resolutions": {
"@types/react": "16.8.8"
},
"devDependencies": {
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
"@microsoft/sp-build-web": "1.10.0",
"@microsoft/sp-module-interfaces": "1.10.0",
"@microsoft/sp-tslint-rules": "1.10.0",
"@microsoft/sp-webpart-workbench": "1.10.0",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"@microsoft/sp-build-web": "1.14.0",
"@microsoft/sp-module-interfaces": "1.14.0",
"@microsoft/sp-tslint-rules": "1.14.0",
"@microsoft/sp-webpart-workbench": "^1.12.1",
"@types/es6-promise": "0.0.33",
"@types/react": "16.9.51",
"@types/react-dom": "16.9.8",
"@types/webpack-env": "^1.16.3",
"ajv": "~5.2.2",
"gulp": "^3.9.1",
"gulp": "^4.0.2",
"run-sequence": "^2.2.1"
}
}

View File

@ -1,9 +1,10 @@
import { useReducer, useEffect, useState } from 'react';
import { sp, PermissionKind } from '@pnp/sp/presets/all';
import { PermissionKind, spfi, SPFx } from '@pnp/sp/presets/all';
import { ErrorHelper, LogHelper, ListTitles, PageFields } from '@src/utilities';
import { Action } from "./action";
import { GetRequest } from './getRequest';
import { IPage } from '@src/models/IPage';
import { WebPartContext } from '@microsoft/sp-webpart-base';
// state that we track
interface PagesState {
@ -83,7 +84,7 @@ function pagesReducer(state: PagesState, action: Action): PagesState {
}
}
export function usePageApi(currentPageId: number, pageEditFinished: boolean): PageApi {
export function usePageApi(currentPageId: number, pageEditFinished: boolean, context: WebPartContext): PageApi {
const [pagesState, pagesDispatch] = useReducer(pagesReducer, {
parentPageColumnExists: true,
userCanManagePages: false,
@ -92,6 +93,8 @@ export function usePageApi(currentPageId: number, pageEditFinished: boolean): Pa
getRequest: { isLoading: false, hasError: false, errorMessage: "" },
});
const sp = spfi().using(SPFx(context));
// currentPageId is a dependency only because it can change when on the workbench, otherwise it really wouldn't change while on a page
useEffect(() => {
LogHelper.verbose('usePageApi', 'useEffect', `[currentPageId, ${currentPageId}, pageEditFinished: ${pageEditFinished} ]`);
@ -126,8 +129,7 @@ export function usePageApi(currentPageId: number, pageEditFinished: boolean): Pa
PageFields.PARENTPAGELOOKUP
)
.top(5000)
.orderBy(PageFields.TITLE, true)
.get()
.orderBy(PageFields.TITLE, true)()
.catch(e => {
ErrorHelper.handleHttpError('getPages', e);
pagesDispatch({ type: ActionTypes.GET_PAGES_ERRORED });
@ -153,8 +155,7 @@ export function usePageApi(currentPageId: number, pageEditFinished: boolean): Pa
LogHelper.verbose('usePageApi', 'parentPageExists', ``);
let parentPage = await sp.web.lists.getByTitle(ListTitles.SITEPAGES).fields
.getByInternalNameOrTitle(PageFields.PARENTPAGELOOKUP)
.get()
.getByInternalNameOrTitle(PageFields.PARENTPAGELOOKUP)()
.catch(e => {
// swallow the exception we'll handle below
});
@ -185,11 +186,10 @@ export function usePageApi(currentPageId: number, pageEditFinished: boolean): Pa
async function addParentPageFieldToSitePages(): Promise<void> {
LogHelper.verbose('usePageApi', 'addParentPageFieldToSitePages', ``);
let list = await sp.web.lists.getByTitle(ListTitles.SITEPAGES)
.get();
let list = await sp.web.lists.getByTitle(ListTitles.SITEPAGES)();
let lookup = await sp.web.lists.getByTitle(ListTitles.SITEPAGES).fields
.addLookup(PageFields.PARENTPAGELOOKUP, list.Id, PageFields.TITLE)
.addLookup(PageFields.PARENTPAGELOOKUP, { LookupListId: list.Id, LookupFieldName: PageFields.TITLE })
.catch(e => {
return null;
ErrorHelper.handleHttpError('canUserUpdateSitePages', e);

View File

@ -424,7 +424,7 @@ export class MockResponse {
let result: IItemUpdateResult = {
item: item,
data: { 'odata.etag': '' }
data: { 'etag': '' }
};
body = JSON.stringify(result);

View File

@ -1,6 +1,5 @@
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import { Environment, EnvironmentType } from '@microsoft/sp-core-library';
import { sp } from "@pnp/sp";
import { Logger, ConsoleListener, LogLevel } from "@pnp/logging";
import { CustomFetchClient } from '@src/mocks/customfetchclient';
@ -14,15 +13,6 @@ export default class BaseWebPart<TProperties> extends BaseClientSideWebPart<TPro
}
return super.onInit().then(_ => {
sp.setup({
spfxContext: this.context,
sp: {
fetchClientFactory: () => {
return new CustomFetchClient(isUsingSharePoint);
},
}
});
// subscribe a listener
Logger.subscribe(new ConsoleListener());

View File

@ -53,7 +53,8 @@ export default class PageHierarchyWebPart extends BaseWebPart<IPageHierarchyWebP
displayMode: this.displayMode,
updateTitle: (t) => { this.properties.title = t; this.render(); },
onConfigure: () => { this.onConfigure(); },
pageEditFinished: this.pageEditFinished
pageEditFinished: this.pageEditFinished,
context: this.context
}
);
ReactDom.render(element, this.domElement, () => {

View File

@ -9,7 +9,7 @@ import { usePageApi } from '@src/apiHooks/usePageApi';
import { Placeholder } from "@pnp/spfx-controls-react/lib/Placeholder";
export const Container: React.FunctionComponent<IContainerProps> = props => {
const pagesApi = usePageApi(props.currentPageId, props.pageEditFinished);
const pagesApi = usePageApi(props.currentPageId, props.pageEditFinished, props.context);
let controlToRender = undefined;
switch (props.pagesToDisplay) {

View File

@ -1,11 +1,13 @@
import { IReadonlyTheme } from '@microsoft/sp-component-base';
import { PagesToDisplay } from '@src/utilities';
import { DisplayMode } from "@microsoft/sp-core-library";
import { WebPartContext } from '@microsoft/sp-webpart-base';
export interface IContainerProps {
currentPageId: number;
pagesToDisplay: PagesToDisplay;
themeVariant: IReadonlyTheme;
context: WebPartContext;
domElement: HTMLElement;
// all this is just for WebPartTitle control
showTitle: boolean;

View File

@ -1,5 +1,5 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.3/includes/tsconfig-web.json",
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.2/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
@ -25,22 +25,18 @@
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
// commented out to allow for this.constructor.name support
// "es5",
"es2015.promise",
"es2017",
"dom",
"es2015.collection"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
"src/**/*.ts",
"src/**/*.tsx"
]
}

View File

@ -1,5 +1,5 @@
{
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
"extends": "./node_modules/@microsoft/sp-tslint-rules/base-tslint.json",
"rules": {
"class-name": false,
"export-name": false,
@ -17,7 +17,6 @@
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,