Skip to content

Commit aef5604

Browse files
committed
wip
1 parent f0c35c3 commit aef5604

25 files changed

+261
-158
lines changed

src/controls/siteBreadcrumb/SiteBreadcrumb.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/// <reference types="sinon" />
22

3-
import * as React from 'react';
4-
import { assert, expect } from 'chai';
5-
import { mount, ReactWrapper } from 'enzyme';
6-
import { SiteBreadcrumb } from './SiteBreadcrumb';
7-
import { ISiteBreadcrumbProps } from './ISiteBreadcrumb';
8-
import styles from './SiteBreadcrumb.module.scss';
9-
10-
declare const sinon;
3+
// import * as React from 'react';
4+
// import { assert, expect } from 'chai';
5+
// import { mount, ReactWrapper } from 'enzyme';
6+
// import { SiteBreadcrumb } from './SiteBreadcrumb';
7+
// import { ISiteBreadcrumbProps } from './ISiteBreadcrumb';
8+
// import styles from './SiteBreadcrumb.module.scss';
9+
10+
// declare const sinon;
1111

1212
/**
1313
* DISCLAIMER: Currently does not work because of the following issue:

src/controls/siteBreadcrumb/SiteBreadcrumb.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export class SiteBreadcrumb extends React.Component<ISiteBreadcrumbProps, ISiteB
3030
/**
3131
* React component lifecycle hook, runs after render
3232
*/
33-
public componentDidMount() {
33+
public componentDidMount(): void {
3434
// Start generating the links for the breadcrumb
3535
this._generateLinks();
3636
}
3737

3838
/**
3939
* Start the link generation for the breadcrumb
4040
*/
41-
private _generateLinks() {
41+
private _generateLinks(): void {
4242
// Add the current site to the links list
4343
this._linkItems.push({
4444
text: this.props.context.pageContext.web.title,
@@ -76,7 +76,7 @@ export class SiteBreadcrumb extends React.Component<ISiteBreadcrumbProps, ISiteB
7676
* Retrieve the parent web URLs
7777
* @param webUrl Current URL of the web to process
7878
*/
79-
private _getParentWeb(webUrl: string) {
79+
private _getParentWeb(webUrl: string): void {
8080
// Retrieve the parent web info
8181
const apiUrl = `${webUrl}/_api/web/parentweb?$select=Id,Title,ServerRelativeUrl`;
8282
this.props.context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1)
@@ -110,6 +110,9 @@ export class SiteBreadcrumb extends React.Component<ISiteBreadcrumbProps, ISiteB
110110
// Set the current breadcrumb data which is already retrieved
111111
this._setBreadcrumbData();
112112
}
113+
})
114+
.catch(() => {
115+
// no-op;
113116
});
114117
}
115118

src/controls/sitePicker/SitePicker.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ export const SitePicker: React.FunctionComponent<ISitePickerProps> = (props: Rea
103103
if (existingIndex >= 0) {
104104
newSelectedSites.splice(existingIndex, 1);
105105
}
106-
else {
106+
else if (item.data) {
107107
newSelectedSites.push({
108-
...item.data!
108+
...item.data
109109
});
110110
}
111111
}
112-
else {
112+
else if (item.data) {
113113
newSelectedSites = [{
114114
...item.data!
115115
}];
@@ -188,7 +188,7 @@ export const SitePicker: React.FunctionComponent<ISitePickerProps> = (props: Rea
188188
return <div className={styles.siteOption}>
189189
<div className={styles.siteOptionContent}>
190190
<span className={styles.siteOptionTitle}>{option.text}</span>
191-
<span className={styles.siteOptionUrl}>{toRelativeUrl(option.data!.url)}</span>
191+
<span className={styles.siteOptionUrl}>{toRelativeUrl(option.data ? option.data.url : '')}</span>
192192
</div>
193193
</div>;
194194
};
@@ -244,6 +244,9 @@ export const SitePicker: React.FunctionComponent<ISitePickerProps> = (props: Rea
244244
const copy = orderBy(newSites, [propOrderBy || 'title'], [isDesc ? 'desc' : 'asc']);
245245
setAllSites(copy);
246246
setIsLoading(false);
247+
})
248+
.catch(() => {
249+
// no-op;
247250
});
248251

249252
}, [context, isLoading, mode, limitToCurrentSiteCollection]);

src/controls/taxonomyPicker/ITermPicker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export interface IPropertyFieldTermPickerProps {
5454
* Normally this function must be always defined with the 'this.onPropertyChange'
5555
* method of the web part object.
5656
*/
57-
onPropertyChange(propertyPath: string, oldValue: any, newValue: any): void;
57+
onPropertyChange(propertyPath: string, oldValue: any, newValue: any): void; // eslint-disable-line @typescript-eslint/no-explicit-any
5858
/**
5959
* Parent Web Part properties
6060
*/
61-
properties: any;
61+
properties: any; // eslint-disable-line @typescript-eslint/no-explicit-any
6262
/**
6363
* An UNIQUE key indicates the identity of this control
6464
*/

src/controls/taxonomyPicker/TaxonomyPicker.tsx

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
6969
/**
7070
* componentDidMount lifecycle hook
7171
*/
72-
public componentDidMount() {
73-
this.validateTerms();
72+
public componentDidMount(): void {
73+
this.validateTerms()
74+
.then(() => {
75+
// no-op;
76+
})
77+
.catch(() => {
78+
// no-op;
79+
});
7480
}
7581

7682
/**
@@ -82,7 +88,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
8288
});
8389
}
8490

85-
public UNSAFE_componentWillReceiveProps(nextProps: ITaxonomyPickerProps) {
91+
public UNSAFE_componentWillReceiveProps(nextProps: ITaxonomyPickerProps): void {
8692
let newState: ITaxonomyPickerState | undefined;
8793
// Check if the initial values objects are not equal, if that is the case, data can be refreshed
8894
if (!isEqual(this.props.initialValues, nextProps.initialValues)) {
@@ -117,7 +123,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
117123
useSessionStorage
118124
} = this.props;
119125

120-
let isValidateOnLoad = validateOnLoad && initialValues && initialValues.length >= 1;
126+
const isValidateOnLoad = validateOnLoad && initialValues && initialValues.length >= 1;
121127
if (isValidateOnLoad) {
122128

123129
const notFoundTerms: string[] = [];
@@ -149,20 +155,27 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
149155
*/
150156
private loadTermStores(): void {
151157
if (this.props.termActions && this.props.termActions.initialize) {
152-
this.props.termActions.initialize(this.termsService);
153-
// this.props.termActions.actions.forEach(x => {
154-
// x.initialize(this.termsService);
155-
// });
158+
this.props.termActions.initialize(this.termsService)
159+
.then(() => {
160+
// no-op;
161+
})
162+
.catch(() => {
163+
// no-op;
164+
});
156165
}
157166

158-
this.termsService.getAllTerms(this.props.termsetNameOrID, this.props.hideDeprecatedTags, this.props.hideTagsNotAvailableForTagging, this.props.useSessionStorage).then((response: ITermSet) => {
159-
// Check if a response was retrieved
160-
let termSetAndTerms = response ? response : null;
161-
this.setState({
162-
termSetAndTerms,
163-
loaded: true
167+
this.termsService.getAllTerms(this.props.termsetNameOrID, this.props.hideDeprecatedTags, this.props.hideTagsNotAvailableForTagging, this.props.useSessionStorage)
168+
.then((response: ITermSet) => {
169+
// Check if a response was retrieved
170+
const termSetAndTerms = response ? response : null;
171+
this.setState({
172+
termSetAndTerms,
173+
loaded: true
174+
});
175+
})
176+
.catch(() => {
177+
// no-op;
164178
});
165-
});
166179
}
167180

168181
/**
@@ -223,7 +236,13 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
223236
this.cancel = false;
224237
this.onClosePanel();
225238

226-
this.validate(this.state.activeNodes);
239+
this.validate(this.state.activeNodes)
240+
.then(() => {
241+
// no-op;
242+
})
243+
.catch(() => {
244+
// no-op;
245+
});
227246
}
228247

229248
/**
@@ -322,12 +341,18 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
322341
* Fires When Items Changed in TermPicker
323342
* @param node
324343
*/
325-
private termsFromPickerChanged(terms: IPickerTerms) {
344+
private termsFromPickerChanged(terms: IPickerTerms): void {
326345
this.setState({
327346
activeNodes: terms
328347
});
329348

330-
this.validate(terms);
349+
this.validate(terms)
350+
.then(() => {
351+
// no-op;
352+
})
353+
.catch(() => {
354+
// no-op;
355+
});
331356
}
332357

333358
/**
@@ -389,14 +414,14 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
389414
return !errorMessage;
390415
}
391416

392-
private onNewTerm = (newLabel: string) => {
417+
private onNewTerm = (newLabel: string): void => {
393418
this.props.onNewTerm(
394-
{
395-
key: EmptyGuid,
396-
name: newLabel,
397-
path: newLabel,
398-
termSet: this.termsService.cleanGuid(this.props.termsetNameOrID)
399-
}
419+
{
420+
key: EmptyGuid,
421+
name: newLabel,
422+
path: newLabel,
423+
termSet: this.termsService.cleanGuid(this.props.termsetNameOrID)
424+
}
400425
);
401426
}
402427

@@ -410,9 +435,9 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
410435
const target: HTMLInputElement = event.target as HTMLInputElement;
411436
const targetValue = !!target ? target.value : null;
412437

413-
if(!!this.props.onGetErrorMessage && !!targetValue) {
414-
await this.validateOnGetErrorMessage(targetValue);
415-
} else {
438+
if (!!this.props.onGetErrorMessage && !!targetValue) {
439+
await this.validateOnGetErrorMessage(targetValue);
440+
} else {
416441
if (!!targetValue) {
417442
this.invalidTerm = targetValue;
418443
}
@@ -442,7 +467,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
442467
* @param termSet
443468
* @param isChecked
444469
*/
445-
private termSetSelectedChange = (termSet: ITermSet, isChecked: boolean) => {
470+
private termSetSelectedChange = (termSet: ITermSet, isChecked: boolean): void => {
446471
const ts: ITermSet = { ...termSet };
447472
// Clean /Guid.../ from the ID
448473
ts.Id = this.termsService.cleanGuid(ts.Id);

src/controls/taxonomyPicker/Term.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class Term extends React.Component<ITermProps, ITermState> {
1717
super(props);
1818

1919
// Check if current term is selected
20-
let active = this.props.activeNodes.filter(item => item.key === this.props.term.Id);
20+
const active = this.props.activeNodes.filter(item => item.key === this.props.term.Id);
2121

2222
this.state = {
2323
selected: active.length > 0,
@@ -32,7 +32,7 @@ export default class Term extends React.Component<ITermProps, ITermState> {
3232
/**
3333
* Handle the checkbox change trigger
3434
*/
35-
private _handleChange(ev: React.FormEvent<HTMLElement>, isChecked: boolean) {
35+
private _handleChange(ev: React.FormEvent<HTMLElement>, isChecked: boolean): void {
3636
this.setState({
3737
selected: isChecked
3838
});
@@ -44,10 +44,10 @@ export default class Term extends React.Component<ITermProps, ITermState> {
4444
* @param nextProps
4545
* @param nextContext
4646
*/
47-
public UNSAFE_componentWillReceiveProps?(nextProps: ITermProps, nextContext: any): void {
47+
public UNSAFE_componentWillReceiveProps(nextProps: ITermProps, nextContext: any): void { // eslint-disable-line @typescript-eslint/no-explicit-any
4848
// If multi-selection is turned off, only a single term can be selected
4949
//if (!this.props.multiSelection) {
50-
let active = nextProps.activeNodes.filter(item => item.key === this.props.term.Id);
50+
const active = nextProps.activeNodes.filter(item => item.key === this.props.term.Id);
5151
this.setState ({
5252
selected: active.length > 0,
5353
termLabel: this.state.termLabel
@@ -58,7 +58,7 @@ export default class Term extends React.Component<ITermProps, ITermState> {
5858
/**
5959
* Get the right class name for the term
6060
*/
61-
private getClassName() {
61+
private getClassName(): string {
6262
if (this.props.term.IsDeprecated) {
6363
return styles.termDisabled;
6464
}

src/controls/taxonomyPicker/TermParent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class TermParent extends React.Component<ITermParentProps, ITermP
3131
/**
3232
* componentWillMount
3333
*/
34-
public UNSAFE_componentWillMount() {
34+
public UNSAFE_componentWillMount(): void {
3535
// fix term depth if anchroid for rendering
3636
if (this.props.anchorId)
3737
{
@@ -57,7 +57,7 @@ export default class TermParent extends React.Component<ITermParentProps, ITermP
5757
/**
5858
* Handle the click event: collapse or expand
5959
*/
60-
private _handleClick() {
60+
private _handleClick(): void {
6161
this.setState({
6262
expanded: !this.state.expanded
6363
});
@@ -86,7 +86,7 @@ export default class TermParent extends React.Component<ITermParentProps, ITermP
8686
// Check if the terms have been loaded
8787
if (this.state.loaded) {
8888
if (this._terms.length > 0) {
89-
let disabledPaths = [];
89+
const disabledPaths = [];
9090
termElm = (
9191
<div style={styleProps}>
9292
{

0 commit comments

Comments
 (0)