diff --git a/samples/react-property-bag-editor/src/webparts/propertyBagDisplay/components/PropertyBagDisplay.tsx b/samples/react-property-bag-editor/src/webparts/propertyBagDisplay/components/PropertyBagDisplay.tsx index 786655216..11c0a7757 100644 --- a/samples/react-property-bag-editor/src/webparts/propertyBagDisplay/components/PropertyBagDisplay.tsx +++ b/samples/react-property-bag-editor/src/webparts/propertyBagDisplay/components/PropertyBagDisplay.tsx @@ -132,19 +132,18 @@ export default class PropertyBagDisplay extends React.Component {this.state.workingStorage.DisplayProps.map((dp, i) => { - return ( + return ( {dp.managedPropertyName} {this.state.workingStorage[dp.managedPropertyName]} {dp.crawledPropertyName} , newValue?: string) => { - const selectedProperty = dp.crawledPropertyName; - const temp: DisplayProp = _.find(this.state.workingStorage.DisplayProps, p => { return p.crawledPropertyName === selectedProperty; }); - dp.value = newValue; - this.setState(this.state); + debugger; + const ws = _.clone(this.state.workingStorage); + _.find(ws.DisplayProps, p => { return p.crawledPropertyName === dp.crawledPropertyName; }).value = newValue; + this.setState((current) => ({ ...current, workingStorage: ws })); }} /> @@ -328,9 +327,6 @@ export default class PropertyBagDisplay extends React.Component { debugger; @@ -400,7 +395,6 @@ export default class PropertyBagDisplay extends React.Component ({ ...current, selectedIndex: index })); } @@ -425,15 +419,15 @@ export default class PropertyBagDisplay extends React.Component ({ ...current, workingStorage: null, isediting: false })); - this.setState(this.state); }).catch((err) => { debugger; - this.state.workingStorage.errorMessages.push(new md.Message(err)); - this.setState(this.state); console.log(err); + const temp = _.clone(this.state.workingStorage); + temp.errorMessages.push(new md.Message(err)); + this.setState(current => ({ ...current, workingStorage: temp })) }); } /** @@ -444,8 +438,6 @@ export default class PropertyBagDisplay extends React.Component ({ ...current, workingStorage: null, isediting: false })); } /** @@ -457,24 +449,10 @@ export default class PropertyBagDisplay extends React.Component} event - * - * @memberOf PropertyBagDisplay - */ - public onPropertyValueChanged(event: React.FormEvent, newValue: string) { - const selectedProperty = newValue;//event.currentTarget.attributes["data-crawledpropertyname"].value; - const dp: DisplayProp = _.find(this.state.workingStorage.DisplayProps, p => { return p.crawledPropertyName === selectedProperty; }); - dp.value = event.currentTarget.value; - this.setState(this.state); + public onForceCrawlChange(newValue: boolean): void { + this.setState(current => ({ ...current, workingStorage: ({ ...current.workingStorage, forceCrawl: newValue }) })); } + public createSearcheableOnChangedHandler = (managedPropertyName) => (value) => { const dp: DisplayProp = _.find(this.state.workingStorage.DisplayProps, p => { return p.crawledPropertyName === managedPropertyName; }); dp.searchable = value; @@ -495,23 +473,21 @@ export default class PropertyBagDisplay extends React.Component { - console.log(context.context); - const crawledProps: Array = context.props.propertiesToDisplay.map(item => { + const crawledProps: Array = this.props.propertiesToDisplay.map(item => { return item.split("|")[0]; }); let temp = _.clone(selectedSite); temp.searchableProps = utils.decodeSearchableProps(r.AllProperties["vti_x005f_indexedpropertykeys"]); - // temp.DisplayProps = utils.SelectProperties(r.AllProperties, crawledProps, context.state.workingStorage.searchableProps); temp.DisplayProps = utils.SelectProperties(r.AllProperties, crawledProps, temp.searchableProps); temp.errorMessages = new Array(); // now add in the managed Prop for (const dp of temp.DisplayProps) { dp.managedPropertyName = - _.find(context.state.managedToCrawedMapping, mtc => { return mtc.crawledPropertyName === dp.crawledPropertyName; }).managedPropertyName; + _.find(this.state.managedToCrawedMapping, mtc => { return mtc.crawledPropertyName === dp.crawledPropertyName; }).managedPropertyName; } - context.setState((current) => ({ + this.setState((current) => ({ ...current, workingStorage: temp, isediting: true diff --git a/samples/react-property-bag-editor/src/webparts/propertyBagEditor/components/PropertyBagEditor.tsx b/samples/react-property-bag-editor/src/webparts/propertyBagEditor/components/PropertyBagEditor.tsx index e3d94d391..4ca3b37a1 100644 --- a/samples/react-property-bag-editor/src/webparts/propertyBagEditor/components/PropertyBagEditor.tsx +++ b/samples/react-property-bag-editor/src/webparts/propertyBagEditor/components/PropertyBagEditor.tsx @@ -80,22 +80,16 @@ export default class PropertyBagEditor extends React.Component ({ ...current, searchableProps: sp, displayProps: dp })) - - }); } /** event hadlers */ public stopediting() { - //this.state.isediting = false; + this.setState((current) => ({ ...current, isediting: false })) } public onActiveItemChanged(item?: any, index?: number) { - //this.state.selectedIndex = index; this.setState((current) => ({ ...current, selectedIndex: index })) } /** @@ -107,10 +101,6 @@ export default class PropertyBagEditor extends React.Component ({ ...current, workingStorage: ({ ...current.workingStorage, searchable: newValue }) })); } @@ -124,7 +114,6 @@ export default class PropertyBagEditor extends React.Component ({ ...current, workingStorage: ({ @@ -143,9 +132,6 @@ export default class PropertyBagEditor extends React.Component ({ ...current, isediting: true, workingStorage: _.clone(current.displayProps[current.selectedIndex]) })) } /** @@ -161,10 +147,8 @@ export default class PropertyBagEditor extends React.Component { this.changeSearchable(this.state.workingStorage.crawledPropertyName, this.state.workingStorage.searchable) .then(s => { - //this.state.displayProps[this.state.selectedIndex] = this.state.workingStorage; const temp = _.clone(this.state.displayProps);// this.state.workingStorage = null; temp[this.state.selectedIndex] = this.state.workingStorage;// this.state.isediting = false; - // this.setState(this.state); this.setState((current) => ({ ...current, isediting: false, workingStorage: null, displayProps: temp })) }); }); @@ -177,9 +161,6 @@ export default class PropertyBagEditor extends React.Component ({ ...current, isediting: false, workingStorage: null })) } @@ -196,7 +177,6 @@ export default class PropertyBagEditor extends React.Component { if (newValue) {//make prop searchable if (_.indexOf(this.state.searchableProps, propname) === -1) {// wasa not searchable, mpw it is - //this.state.searchableProps.push(propname); const temp = _.clone(this.state.searchableProps); temp.push(propname); this.setState(current => ({ ...current, searchableProps: temp })); diff --git a/samples/react-property-bag-editor/src/webparts/propertyBagFilteredSiteList/components/PropertyBagFilteredSiteList.tsx b/samples/react-property-bag-editor/src/webparts/propertyBagFilteredSiteList/components/PropertyBagFilteredSiteList.tsx index 5c0867e7c..241ca9c75 100644 --- a/samples/react-property-bag-editor/src/webparts/propertyBagFilteredSiteList/components/PropertyBagFilteredSiteList.tsx +++ b/samples/react-property-bag-editor/src/webparts/propertyBagFilteredSiteList/components/PropertyBagFilteredSiteList.tsx @@ -8,9 +8,8 @@ import { Label } from "office-ui-fabric-react/lib/Label"; import MessageDisplay, * as md from "../../shared/MessageDisplay"; import utils from "../../shared/utils"; import { IPropertyBagFilteredSiteListProps } from "./IPropertyBagFilteredSiteListProps"; - import { IContextualMenuItem, } from "office-ui-fabric-react/lib/ContextualMenu"; -import { DetailsList } from "office-ui-fabric-react"; + export interface IPropertyBagFilteredSiteListState { errorMessages: Array; sites: Array; @@ -83,10 +82,6 @@ export default class PropertyBagFilteredSiteList extends React.Component ({ ...current, errorMessages: messages })); } - /** - * Initializes the list of user filters. - * A user filter is created for each UserFilter name specified in the props. - * - * @param {Array} userFilterNames - * - * @memberOf PropertyBagFilteredSiteList - */ - // public setupUserFilters(userFilterNames: Array): void { - // // this.state.userFilters = []; - // // for (const userFilterName of userFilterNames) { - // // this.state.userFilters.push(new UserFilter(userFilterName)); - // // } - // let userFilters = []; - // for (const userFilterName of userFilterNames) { - // userFilters.push(new UserFilter(userFilterName)); - // } - // this.setState((current) => ({ ...current, userFilters: userFilters })); - - // } /** * Adds values to All the UserFilters for a given SearchResults. @@ -193,19 +168,6 @@ export default class PropertyBagFilteredSiteList extends React.Component { - // this.state.sites = []; - // debugger; - // this.setupUserFilters(userFilterNameArray); - // for (const r of results.PrimarySearchResults) { - // const index = this.state.sites.push(new Site(r.Title, r.Description, r.SPSiteUrl)); - - // for (const mp of this.props.userFilters) { - // this.state.sites[index-1][mp] = r[mp]; - // } - // this.extractUserFilterValues(r); - // } - // this.filterSites(); - // this.setState(this.state); let sites = []; debugger; let userFilters: UserFilter[] = []; @@ -243,20 +205,7 @@ export default class PropertyBagFilteredSiteList extends React.Component, item?: IContextualMenuItem) { const newFilters = this.ToggleAppliedUserFilter(this.state.appliedUserFilters, item); - // this.filterSites(); - // this.setState(this.state); this.setState((current) => ({ ...current, appliedUserFilters: newFilters, filteredSites: this.filterSites(newFilters, current.sites) })); } diff --git a/samples/react-property-bag-editor/src/webparts/propertyBagGlobalNav/components/PropertyBagGlobalNav.tsx b/samples/react-property-bag-editor/src/webparts/propertyBagGlobalNav/components/PropertyBagGlobalNav.tsx index 4d3cc11dc..de5142ba1 100644 --- a/samples/react-property-bag-editor/src/webparts/propertyBagGlobalNav/components/PropertyBagGlobalNav.tsx +++ b/samples/react-property-bag-editor/src/webparts/propertyBagGlobalNav/components/PropertyBagGlobalNav.tsx @@ -90,11 +90,6 @@ export default class PropertyBagGlobalNav extends React.Component { - // this.state.menuitems = []; - // for (const r of results.PrimarySearchResults) { - // this.addMenuItem(r); - // } - // this.setState(this.state); let menuitems = []; for (const r of results.PrimarySearchResults) { this.addMenuItem(menuitems, r); @@ -106,11 +101,13 @@ export default class PropertyBagGlobalNav extends React.Component { debugger; - this.state.errorMessages.push(new md.Message(err)); - this.setState(this.state); + + const em = this.state.errorMessages; + em.push(new md.Message(err)); + this.setState(current => ({ ...current, errorMessages: em })); }); } - /** react lifecycle */ + public componentDidMount(): void { this.getSites(this.props.siteTemplatesToInclude, this.props.filters, this.props.managedProperties); diff --git a/samples/react-property-bag-editor/tsconfig.json b/samples/react-property-bag-editor/tsconfig.json index bf6820147..314d48352 100644 --- a/samples/react-property-bag-editor/tsconfig.json +++ b/samples/react-property-bag-editor/tsconfig.json @@ -4,7 +4,7 @@ "skipLibCheck": true, "inlineSources": false, "strictNullChecks": false, - "noUnusedLocals": false, + "noUnusedLocals": true, "target": "es5", "forceConsistentCasingInFileNames": true, "module": "esnext",