Fixed linting, npmrc, sample.json, devcontainer. readme

This commit is contained in:
Hugo Bernier 2024-04-17 21:53:19 -04:00
parent 882ec700ae
commit 64aa132a24
16 changed files with 93 additions and 60 deletions

View File

@ -1,39 +1,38 @@
// For more information on how to run this SPFx project in a VS Code Remote Container, please visit https://aka.ms/spfx-devcontainer
{ {
"name": "SPFx 1.11.0", "name": "SPFx 1.18.2",
"image": "docker.io/m365pnp/spfx:1.11.0", "image": "docker.io/m365pnp/spfx:1.18.2",
// Set *default* container specific settings.json values on container create. "customizations": {
"settings": {}, "vscode": {
// Add the IDs of extensions you want installed when the container is created. "extensions": [
"extensions": [ "editorconfig.editorconfig",
"editorconfig.editorconfig", "dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint" ]
], }
// Use 'forwardPorts' to make a list of ports inside the container available locally. },
"forwardPorts": [ "forwardPorts": [
4321, 4321,
35729, 35729,
5432 5432
], ],
"portsAttributes": { "portsAttributes": {
"4321": { "4321": {
"protocol": "https", "protocol": "https",
"label": "Manifest", "label": "Manifest",
"onAutoForward": "silent", "onAutoForward": "silent",
"requireLocalPort": true "requireLocalPort": true
}, },
"5432": { "5432": {
"protocol": "https", "protocol": "https",
"label": "Workbench", "label": "Workbench",
"onAutoForward": "silent" "onAutoForward": "silent"
}, },
"35729": { "35729": {
"protocol": "https", "protocol": "https",
"label": "LiveReload", "label": "LiveReload",
"onAutoForward": "silent", "onAutoForward": "silent",
"requireLocalPort": true "requireLocalPort": true
} }
}, },
"postCreateCommand": "bash .devcontainer/spfx-startup.sh", "postCreateCommand": "bash .devcontainer/spfx-startup.sh",
"remoteUser": "node" "remoteUser": "node"
} }

View File

@ -7,9 +7,11 @@ echo
echo -e "\e[1;94mGenerating dev certificate\e[0m" echo -e "\e[1;94mGenerating dev certificate\e[0m"
gulp trust-dev-cert gulp trust-dev-cert
# Convert the generated PEM certificate to a CER certificate
openssl x509 -inform PEM -in ~/.rushstack/rushstack-serve.pem -outform DER -out ./spfx-dev-cert.cer
cp ~/.gcb-serve-data/gcb-serve.cer ./spfx-dev-cert.cer # Copy the PEM ecrtificate for non-Windows hosts
cp ~/.gcb-serve-data/gcb-serve.cer ./spfx-dev-cert.pem cp ~/.rushstack/rushstack-serve.pem ./spfx-dev-cert.pem
## add *.cer to .gitignore to prevent certificates from being saved in repo ## add *.cer to .gitignore to prevent certificates from being saved in repo
if ! grep -Fxq '*.cer' ./.gitignore if ! grep -Fxq '*.cer' ./.gitignore

View File

@ -0,0 +1 @@
v18.19.0

View File

@ -14,14 +14,17 @@ While the original web part was based on an **XSLT** templating engine, this *Re
| :warning: Important | | :warning: Important |
|:---------------------------| |:---------------------------|
| Every SPFx version is only compatible with specific version(s) of Node.js. In order to be able to build this sample, please ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node.| | Every SPFx version is optimally compatible with specific versions of Node.js. In order to be able to build this sample, you need to ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node.|
|Refer to <https://aka.ms/spfx-matrix> for more information on SPFx compatibility. | |Refer to <https://aka.ms/spfx-matrix> for more information on SPFx compatibility. |
![SPFx 1.11](https://img.shields.io/badge/SPFx-1.11.0-green.svg) This sample is optimally compatible with the following environment configuration:
![Node.js v10](https://img.shields.io/badge/Node.js-v10-green.svg) ![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
![SPFx 1.18.2](https://img.shields.io/badge/SPFx-1.18.2-green.svg)
![Node.js v16 | v18](https://img.shields.io/badge/Node.js-v16%20%7C%20v18-green.svg)
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower") ![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower")
![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1") ![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1")
![Local Workbench Incompatible](https://img.shields.io/badge/Local%20Workbench-Incompatible-red.svg "The solution requires access to content") ![Local Workbench Unsupported](https://img.shields.io/badge/Local%20Workbench-Unsupported-red.svg "Local workbench is no longer available as of SPFx 1.13 and above")
![Hosted Workbench Compatible](https://img.shields.io/badge/Hosted%20Workbench-Compatible-green.svg) ![Hosted Workbench Compatible](https://img.shields.io/badge/Hosted%20Workbench-Compatible-green.svg)
![Compatible with Remote Containers](https://img.shields.io/badge/Remote%20Containers-Compatible-green.svg) ![Compatible with Remote Containers](https://img.shields.io/badge/Remote%20Containers-Compatible-green.svg)

View File

@ -9,7 +9,7 @@
"The React Content Query Web Part is a modern version of the good old Content by Query Web Part that was introduced in SharePoint 2007. Built for SharePoint Online, this modern version is built against the new SharePoint Framework (SPFx) and uses the latest Web Stack practices. While the original Web Part was based on a XSLT templating engine, this React Web Part is based on the well known Handlebars templating engine, which empowers users to create simple, yet powerfull HTML templates for rendering the queried content. This new version also lets the user query any site collections which resides on the same domain url, add unlimited filters, query DateTime fields to the nearest minute rather than being limited to a day, and much more." "The React Content Query Web Part is a modern version of the good old Content by Query Web Part that was introduced in SharePoint 2007. Built for SharePoint Online, this modern version is built against the new SharePoint Framework (SPFx) and uses the latest Web Stack practices. While the original Web Part was based on a XSLT templating engine, this React Web Part is based on the well known Handlebars templating engine, which empowers users to create simple, yet powerfull HTML templates for rendering the queried content. This new version also lets the user query any site collections which resides on the same domain url, add unlimited filters, query DateTime fields to the nearest minute rather than being limited to a day, and much more."
], ],
"creationDateTime": "2021-01-07", "creationDateTime": "2021-01-07",
"updateDateTime": "2023-05-04", "updateDateTime": "2024-03-31",
"products": [ "products": [
"SharePoint" "SharePoint"
], ],
@ -20,7 +20,7 @@
}, },
{ {
"key": "SPFX-VERSION", "key": "SPFX-VERSION",
"value": "1.11.0" "value": "1.18.2"
} }
], ],
"thumbnails": [ "thumbnails": [
@ -138,10 +138,15 @@
"name": "Abderahman Moujahid" "name": "Abderahman Moujahid"
}, },
{ {
"gitHubAccount": "ChrisLizon", "gitHubAccount": "ChrisLizon",
"name": "Chris Lizon", "name": "Chris Lizon",
"pictureUrl": "https://github.com/ChrisLizon.png" "pictureUrl": "https://github.com/ChrisLizon.png"
} },
{
"gitHubAccount": "nemortu",
"name": "nemortu",
"pictureUrl": "https://github.com/nemortu.png"
}
], ],
"references": [ "references": [
{ {

View File

@ -291,7 +291,9 @@ export class CamlQueryHelper {
if (!url) { if (!url) {
url = window.location.href; url = window.location.href;
} }
// eslint-disable-next-line no-useless-escape
name = name.replace(/[\[\]]/g, "\\$&"); name = name.replace(/[\[\]]/g, "\\$&");
// eslint-disable-next-line @rushstack/security/no-unsafe-regexp
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url); results = regex.exec(url);
if (!results) return null; if (!results) return null;

View File

@ -295,6 +295,7 @@ export class ContentQueryService implements IContentQueryService {
this.listService.getListFields(webUrl, listId, ['InternalName', 'Title', 'Sortable'], 'Title').then((data: any) => { this.listService.getListFields(webUrl, listId, ['InternalName', 'Title', 'Sortable'], 'Title').then((data: any) => {
const sortableFields: any[] = data.value.filter((field) => { return field.Sortable == true; }); const sortableFields: any[] = data.value.filter((field) => { return field.Sortable == true; });
let options: IDropdownOption[] = [{ key: "", text: strings.queryFilterPanelStrings.queryFilterStrings.fieldSelectLabel }]; let options: IDropdownOption[] = [{ key: "", text: strings.queryFilterPanelStrings.queryFilterStrings.fieldSelectLabel }];
// eslint-disable-next-line no-useless-escape
const orderByOptions: IDropdownOption[] = sortableFields.map((field) => { return { key: field.InternalName, text: Text.format("{0} \{\{{1}\}\}", field.Title, field.InternalName) }; }); const orderByOptions: IDropdownOption[] = sortableFields.map((field) => { return { key: field.InternalName, text: Text.format("{0} \{\{{1}\}\}", field.Title, field.InternalName) }; });
options = options.concat(orderByOptions); options = options.concat(orderByOptions);
this.orderByOptions = options; this.orderByOptions = options;
@ -371,7 +372,8 @@ export class ContentQueryService implements IContentQueryService {
let items: IChecklistItem[] = fields.map((field) => { let items: IChecklistItem[] = fields.map((field) => {
return { return {
id: field.InternalName, id: field.InternalName,
label: Text.format("{0} \{\{{1}\}\}", field.Title, field.InternalName) // eslint-disable-next-line no-useless-escape
label: Text.format("{0} \{\{{1}\}}", field.Title, field.InternalName)
}; };
}); });
this.viewFields = items; this.viewFields = items;
@ -479,6 +481,7 @@ export class ContentQueryService implements IContentQueryService {
* @param itemSelectorEnabled: Defines whether to render the item selector element in the template * @param itemSelectorEnabled: Defines whether to render the item selector element in the template
*************************************************************************************************/ *************************************************************************************************/
public generateDefaultTemplate(viewFields: string[], itemSelectorEnabled: boolean): string { public generateDefaultTemplate(viewFields: string[], itemSelectorEnabled: boolean): string {
// eslint-disable-next-line no-useless-escape
let viewFieldsStr = viewFields.map((field) => { return Text.format(" <span class='ms-DetailsRow-cell'><strong>{0}: </strong>\{\{{0}.textValue\}\}</span>", field); }).join("\n"); let viewFieldsStr = viewFields.map((field) => { return Text.format(" <span class='ms-DetailsRow-cell'><strong>{0}: </strong>\{\{{0}.textValue\}\}</span>", field); }).join("\n");
let selectItemStr = "\n <span><button class='selectItem' data-itemId='{{ID.textValue}}'>Select</button></span>"; let selectItemStr = "\n <span><button class='selectItem' data-itemId='{{ID.textValue}}'>Select</button></span>";
let template = Text.format(`<style type="text/css"> let template = Text.format(`<style type="text/css">

View File

@ -19,8 +19,8 @@ export class PropertyPaneAsyncChecklist implements IPropertyPaneField<IPropertyP
/***************************************************************************************** /*****************************************************************************************
* Property pane's contructor * Property pane's contructor
* @param targetProperty * @param targetProperty
* @param properties * @param properties
*****************************************************************************************/ *****************************************************************************************/
constructor(targetProperty: string, properties: IPropertyPaneAsyncChecklistProps) { constructor(targetProperty: string, properties: IPropertyPaneAsyncChecklistProps) {
this.targetProperty = targetProperty; this.targetProperty = targetProperty;
@ -65,6 +65,7 @@ export class PropertyPaneAsyncChecklist implements IPropertyPaneField<IPropertyP
stateKey: new Date().toString() stateKey: new Date().toString()
}); });
// eslint-disable-next-line @microsoft/spfx/pair-react-dom-render-unmount
ReactDom.render(asyncChecklist, elem); ReactDom.render(asyncChecklist, elem);
this.loadedItems = true; this.loadedItems = true;
} }
@ -76,4 +77,4 @@ export class PropertyPaneAsyncChecklist implements IPropertyPaneField<IPropertyP
private onChange(checkedKeys: string[]): void { private onChange(checkedKeys: string[]): void {
this.properties.onPropertyChange(this.targetProperty, checkedKeys); this.properties.onPropertyChange(this.targetProperty, checkedKeys);
} }
} }

View File

@ -73,6 +73,7 @@ export class AsyncChecklist extends React.Component<IAsyncChecklistProps, IAsync
* Loads the checklist items asynchronously * Loads the checklist items asynchronously
*************************************************************************************/ *************************************************************************************/
private loadItems() { private loadItems() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let _this_ = this; let _this_ = this;
_this_.checkedItems = this.getDefaultCheckedItems(); _this_.checkedItems = this.getDefaultCheckedItems();

View File

@ -70,6 +70,7 @@ export class PropertyPaneAsyncDropdown implements IPropertyPaneField<IPropertyPa
stateKey: new Date().toString() stateKey: new Date().toString()
}); });
// eslint-disable-next-line @microsoft/spfx/pair-react-dom-render-unmount
ReactDom.render(asyncDropDown, elem); ReactDom.render(asyncDropDown, elem);
} }

View File

@ -70,6 +70,7 @@ export class PropertyPaneQueryFilterPanel implements IPropertyPaneField<IPropert
stateKey: new Date().toString() stateKey: new Date().toString()
}); });
// eslint-disable-next-line @microsoft/spfx/pair-react-dom-render-unmount
ReactDom.render(queryFilterpanel, elem); ReactDom.render(queryFilterpanel, elem);
} }

View File

@ -1,3 +1,4 @@
/* eslint-disable react/no-direct-mutation-state */
import * as React from 'react'; import * as React from 'react';
import * as moment from 'moment'; import * as moment from 'moment';
import { cloneDeep, isEmpty } from '@microsoft/sp-lodash-subset'; import { cloneDeep, isEmpty } from '@microsoft/sp-lodash-subset';
@ -104,6 +105,7 @@ export class QueryFilter extends React.Component<IQueryFilterProps, IQueryFilter
* When the NormalPeoplePicker value changes * When the NormalPeoplePicker value changes
*************************************************************************************/ *************************************************************************************/
private onTaxonomyPickerResolve(items: ITag[]) { private onTaxonomyPickerResolve(items: ITag[]) {
// eslint-disable-next-line react/no-direct-mutation-state
this.state.filter.value = items; this.state.filter.value = items;
this.onAnyChange(); this.onAnyChange();
} }
@ -126,6 +128,7 @@ export class QueryFilter extends React.Component<IQueryFilterProps, IQueryFilter
private onDateExpressionChange(newValue: string): string { private onDateExpressionChange(newValue: string): string {
// Validates the picker // Validates the picker
// eslint-disable-next-line no-useless-escape
let regex = new RegExp(/^\[Today\](\s{0,}[\+-]\s{0,}\[{0,1}\d{1,4}\]{0,1}){0,1}$/); let regex = new RegExp(/^\[Today\](\s{0,}[\+-]\s{0,}\[{0,1}\d{1,4}\]{0,1}){0,1}$/);
let isValid = regex.test(newValue) || isEmpty(newValue); let isValid = regex.test(newValue) || isEmpty(newValue);
let errorMsg = isValid ? '' : this.props.strings.datePickerExpressionError; let errorMsg = isValid ? '' : this.props.strings.datePickerExpressionError;
@ -133,7 +136,9 @@ export class QueryFilter extends React.Component<IQueryFilterProps, IQueryFilter
if(isValid) { if(isValid) {
// If the change is NOT triggered by the date picker change // If the change is NOT triggered by the date picker change
if(!(isEmpty(newValue) && this.state.filter.value != null)) { if(!(isEmpty(newValue) && this.state.filter.value != null)) {
// eslint-disable-next-line react/no-direct-mutation-state
this.state.filter.value = null; this.state.filter.value = null;
// eslint-disable-next-line react/no-direct-mutation-state
this.state.filter.expression = newValue; this.state.filter.expression = newValue;
this.setState({ filter: this.state.filter, pickersKey: this.state.pickersKey }); this.setState({ filter: this.state.filter, pickersKey: this.state.pickersKey });
this.onAnyChange(); this.onAnyChange();
@ -150,6 +155,7 @@ export class QueryFilter extends React.Component<IQueryFilterProps, IQueryFilter
* @param checked : Whether the checkbox is not checked or not * @param checked : Whether the checkbox is not checked or not
*************************************************************************************/ *************************************************************************************/
private onDateIncludeTimeChange(ev?: React.FormEvent<HTMLInputElement>, checked?: boolean) { private onDateIncludeTimeChange(ev?: React.FormEvent<HTMLInputElement>, checked?: boolean) {
// eslint-disable-next-line react/no-direct-mutation-state
this.state.filter.includeTime = checked; this.state.filter.includeTime = checked;
this.onAnyChange(); this.onAnyChange();
} }
@ -160,6 +166,7 @@ export class QueryFilter extends React.Component<IQueryFilterProps, IQueryFilter
*************************************************************************************/ *************************************************************************************/
private onJoinChoiceChange(ev?: React.FormEvent<HTMLInputElement>, option?: IChoiceGroupOption) { private onJoinChoiceChange(ev?: React.FormEvent<HTMLInputElement>, option?: IChoiceGroupOption) {
if(option) { if(option) {
// eslint-disable-next-line react/no-direct-mutation-state
this.state.filter.join = QueryFilterJoin[option.key]; this.state.filter.join = QueryFilterJoin[option.key];
this.onAnyChange(); this.onAnyChange();
} }
@ -185,6 +192,7 @@ export class QueryFilter extends React.Component<IQueryFilterProps, IQueryFilter
]; ];
for(let field of this.props.fields) { for(let field of this.props.fields) {
// eslint-disable-next-line no-useless-escape
let option:IDropdownOption = { key: field.internalName, text: Text.format("{0} \{\{{1}\}\}", field.displayName, field.internalName) }; let option:IDropdownOption = { key: field.internalName, text: Text.format("{0} \{\{{1}\}\}", field.displayName, field.internalName) };
options.push(option); options.push(option);
} }

View File

@ -1,3 +1,4 @@
/* eslint-disable react/no-direct-mutation-state */
import * as React from 'react'; import * as React from 'react';
import { cloneDeep } from '@microsoft/sp-lodash-subset'; import { cloneDeep } from '@microsoft/sp-lodash-subset';
import { Text } from '@microsoft/sp-core-library'; import { Text } from '@microsoft/sp-core-library';

View File

@ -18,8 +18,8 @@ export class PropertyPaneTextDialog implements IPropertyPaneField<IPropertyPaneT
/***************************************************************************************** /*****************************************************************************************
* Property pane's contructor * Property pane's contructor
* @param targetProperty * @param targetProperty
* @param properties * @param properties
*****************************************************************************************/ *****************************************************************************************/
constructor(targetProperty: string, properties: IPropertyPaneTextDialogProps) { constructor(targetProperty: string, properties: IPropertyPaneTextDialogProps) {
this.targetProperty = targetProperty; this.targetProperty = targetProperty;
@ -62,6 +62,7 @@ export class PropertyPaneTextDialog implements IPropertyPaneField<IPropertyPaneT
stateKey: new Date().toString() stateKey: new Date().toString()
}); });
// eslint-disable-next-line @microsoft/spfx/pair-react-dom-render-unmount
ReactDom.render(textDialog, elem); ReactDom.render(textDialog, elem);
} }
@ -72,4 +73,4 @@ export class PropertyPaneTextDialog implements IPropertyPaneField<IPropertyPaneT
private onChanged(text: string): void { private onChanged(text: string): void {
this.properties.onPropertyChange(this.targetProperty, text); this.properties.onPropertyChange(this.targetProperty, text);
} }
} }

View File

@ -139,6 +139,7 @@ export default class ContentQueryWebPart
if (this.properties.enableMGT) if (this.properties.enableMGT)
{ {
// Add MGT dependencies // Add MGT dependencies
// eslint-disable-next-line @typescript-eslint/no-var-requires
const MGT:any = require('@microsoft/mgt'); const MGT:any = require('@microsoft/mgt');
// We only need to re-register the SharePoint provider if we didn't register it before // We only need to re-register the SharePoint provider if we didn't register it before
@ -168,6 +169,7 @@ export default class ContentQueryWebPart
themeVariant: this._themeVariant themeVariant: this._themeVariant
} }
); );
// eslint-disable-next-line @microsoft/spfx/pair-react-dom-render-unmount
ReactDom.render(element, this.domElement); ReactDom.render(element, this.domElement);
} }
@ -548,7 +550,7 @@ export default class ContentQueryWebPart
/*************************************************************************** /***************************************************************************
* Validates the templateUrl property * Validates the templateUrl property
***************************************************************************/ ***************************************************************************/
private onTemplateUrlChange(value: string): Promise<String> { private onTemplateUrlChange(value: string): Promise<string> {
Log.verbose(this.logSource, "WebPart property 'templateUrl' has changed, refreshing WebPart...", this.context.serviceScope); Log.verbose(this.logSource, "WebPart property 'templateUrl' has changed, refreshing WebPart...", this.context.serviceScope);
return new Promise<string>((resolve, reject) => { return new Promise<string>((resolve, reject) => {
@ -576,7 +578,7 @@ export default class ContentQueryWebPart
/*************************************************************************** /***************************************************************************
* Validates the itemLimit property * Validates the itemLimit property
***************************************************************************/ ***************************************************************************/
private onItemLimitChange(value: string): Promise<String> { private onItemLimitChange(value: string): Promise<string> {
Log.verbose(this.logSource, "WebPart property 'itemLimit' has changed, refreshing WebPart...", this.context.serviceScope); Log.verbose(this.logSource, "WebPart property 'itemLimit' has changed, refreshing WebPart...", this.context.serviceScope);
return new Promise<string>((resolve, reject) => { return new Promise<string>((resolve, reject) => {

View File

@ -41,6 +41,7 @@ export default class ContentQuery extends React.Component<IContentQueryProps, IC
super(props); super(props);
// Imports the handlebars-helpers // Imports the handlebars-helpers
// eslint-disable-next-line @typescript-eslint/no-var-requires
let helpers = require<any>('handlebars-helpers')({ let helpers = require<any>('handlebars-helpers')({
handlebars: Handlebars handlebars: Handlebars
}); });
@ -65,6 +66,7 @@ export default class ContentQuery extends React.Component<IContentQueryProps, IC
*************************************************************************************/ *************************************************************************************/
private loadExternalScriptsSequentially(scriptUrls: string[]): Promise<{}> { private loadExternalScriptsSequentially(scriptUrls: string[]): Promise<{}> {
var index = 0; var index = 0;
// eslint-disable-next-line @typescript-eslint/no-this-alias
var _this_ = this; var _this_ = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -386,7 +388,7 @@ export default class ContentQuery extends React.Component<IContentQueryProps, IC
{/* Shows the query results once loaded */} {/* Shows the query results once loaded */}
{mandatoryFieldsConfigured && !this.state.loading && !this.state.error && {mandatoryFieldsConfigured && !this.state.loading && !this.state.error &&
<div dangerouslySetInnerHTML={this.createMarkup(this.state.processedTemplateResult)}></div> <div dangerouslySetInnerHTML={this.createMarkup(this.state.processedTemplateResult)} />
} }
</div> </div>