Bugfix: Added backwards compability for old sort configurations

Bugfix: Added backwards compability for old empty refiner configurations
This commit is contained in:
Mikael Svenson 2019-01-07 13:32:25 +01:00
parent e587071d01
commit 2ec6d1504f
3 changed files with 162 additions and 133 deletions

View File

@ -56,14 +56,15 @@ Version|Date|Comments
1.3 | Apr1, 2018 | Added the result count + entered keywords option 1.3 | Apr1, 2018 | Added the result count + entered keywords option
1.4 | May 10, 2018 | <ul><li>Added the query suggestions feature to the search box Web Part</li><li>Added the automatic translation for taxonomy filter values according to the current site locale.</li> <li>Added the option in the search box Web Part to send the query to an other page</ul> 1.4 | May 10, 2018 | <ul><li>Added the query suggestions feature to the search box Web Part</li><li>Added the automatic translation for taxonomy filter values according to the current site locale.</li> <li>Added the option in the search box Web Part to send the query to an other page</ul>
1.5 | Jul 2, 2018 | <ul><li>Added a templating feature for search results with Handlebars inspired by the [react-content-query-webpart](https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-content-query-webpart) sample.</li><li>Upgraded to 1.5.1-plusbeta to use the new SPFx dynamic data feature instead of event aggregator for Web Parts communication.</li> <li>Code refactoring and reorganization.</ul> 1.5 | Jul 2, 2018 | <ul><li>Added a templating feature for search results with Handlebars inspired by the [react-content-query-webpart](https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-content-query-webpart) sample.</li><li>Upgraded to 1.5.1-plusbeta to use the new SPFx dynamic data feature instead of event aggregator for Web Parts communication.</li> <li>Code refactoring and reorganization.</ul>
2.0.0.5 | Sept 18, 2018 | <ul><li>Upgraded to 1.6.0-plusbeta.</li><li>Added dynamic loading of parts needed in edit mode to reduce web part footprint.</li><li>Added configuration to sort.</li><li>Added option to set web part title.</li><li>Added result count tokens.</li><li>Added toggle to load/use handlebars helpers/moment.</li></ul> 2.0.5 | Sept 18, 2018 | <ul><li>Upgraded to 1.6.0-plusbeta.</li><li>Added dynamic loading of parts needed in edit mode to reduce web part footprint.</li><li>Added configuration to sort.</li><li>Added option to set web part title.</li><li>Added result count tokens.</li><li>Added toggle to load/use handlebars helpers/moment.</li></ul>
2.1.0.0 | Oct 14, 2018 | <ul><li>Bug fixes ([#641](https://github.com/SharePoint/sp-dev-fx-webparts/issues/641),[#642](https://github.com/SharePoint/sp-dev-fx-webparts/issues/642))</li><li>Added document and Office 365 videos previews for the list template.</li><li>Added SharePoint best bets support.</li></ul> 2.1.0 | Oct 14, 2018 | <ul><li>Bug fixes ([#641](https://github.com/SharePoint/sp-dev-fx-webparts/issues/641),[#642](https://github.com/SharePoint/sp-dev-fx-webparts/issues/642))</li><li>Added document and Office 365 videos previews for the list template.</li><li>Added SharePoint best bets support.</li></ul>
2.1.1.0 | Oct 30, 2018 | <ul><li>Bug fix for editing custom template.</li><li>Bug fix for dynamic loading of video helper library.</li><li>Added support for Page context query variables.</li><li>Added `getUniqueCount` helper function.</li></ul> 2.1.1 | Oct 30, 2018 | <ul><li>Bug fix for editing custom template.</li><li>Bug fix for dynamic loading of video helper library.</li><li>Added support for Page context query variables.</li><li>Added `getUniqueCount` helper function.</li></ul>
2.1.2.0 | Nov 9, 2018 | <ul><li>Bug fix for IE11.</li><li>Added date query variables.</li><li>Added support for both result source id and query template.</li><li>Added `getUniqueCount` helper function.</li></ul> 2.1.2 | Nov 9, 2018 | <ul><li>Bug fix for IE11.</li><li>Added date query variables.</li><li>Added support for both result source id and query template.</li><li>Added `getUniqueCount` helper function.</li></ul>
2.2.0.0 | Nov 11, 2018 | <ul><li>Upgraded to SPFx 1.7.0</li><li>Added a TypeScript Azure Function to demonstrate NLP processing on search query</li><li>Removed extension data source. Now we use the default SPFx 'Page Environment' data source.</li></ul> 2.2.0 | Nov 11, 2018 | <ul><li>Upgraded to SPFx 1.7.0</li><li>Added a TypeScript Azure Function to demonstrate NLP processing on search query</li><li>Removed extension data source. Now we use the default SPFx 'Page Environment' data source.</li></ul>
2.2.0.1 | Dec 3, 2018 | <ul><li>Remove switch for handlebar helpers, and instead load helpers if used in the template.</li></ul> 2.2.0 | Dec 3, 2018 | <ul><li>Remove switch for handlebar helpers, and instead load helpers if used in the template.</li></ul>
2.3.0.0 | Dec 13, 2018 | <ul><li>Upgraded to @pnp/controls 1.13.0</li><li>Added a result types features</li><li>Fix bug regarding dynamic data source connection</li></ul> 2.3.0 | Dec 13, 2018 | <ul><li>Upgraded to @pnp/controls 1.13.0</li><li>Added a result types features</li><li>Fix bug regarding dynamic data source connection</li></ul>
2.4.0.0 | Jan 03, 2019 | Added custom code renderer support. 2.4.0 | Jan 03, 2019 | Added custom code renderer support.
2.4.1 | Jan 07, 2019 | Added backwards compability for older sort configurations, and old empty refiner configurations
## Important notice on upgrading the solution from pre v2.2.0.0 ## Important notice on upgrading the solution from pre v2.2.0.0
**Due to code restucturing we have hit an edge case which impacts upgrades from previous versions. To solve the issue go to `https://<tenant>.sharepoint.com/sites/<appcatalog>/Lists/ComponentManifests` and remove the entries for SearchBox and Search Results, and then upload the .sppkg for the new release.** **Due to code restucturing we have hit an edge case which impacts upgrades from previous versions. To solve the issue go to `https://<tenant>.sharepoint.com/sites/<appcatalog>/Lists/ComponentManifests` and remove the entries for SearchBox and Search Results, and then upload the .sppkg for the new release.**

View File

@ -1,6 +1,6 @@
{ {
"name": "pnp-react-search-refiners", "name": "pnp-react-search-refiners",
"version": "2.4.0", "version": "2.4.1",
"private": true, "private": true,
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=0.10.0"

View File

@ -94,24 +94,24 @@ export default class SearchResultsWebPart extends BaseClientSideWebPart<ISearchR
let queryKeywords; let queryKeywords;
let renderElement = null; let renderElement = null;
let dataSourceValue; let dataSourceValue;
let source = this.properties.queryKeywords.tryGetSource(); let source = this.properties.queryKeywords.tryGetSource();
// Try to get the source if a source id is present // Try to get the source if a source id is present
if (!source && this.properties.sourceId) { if (!source && this.properties.sourceId) {
source = this.context.dynamicDataProvider.tryGetSource(this.properties.sourceId); source = this.context.dynamicDataProvider.tryGetSource(this.properties.sourceId);
if (source && this.properties.propertyId) { if (source && this.properties.propertyId) {
dataSourceValue = source.getPropertyValue(this.properties.propertyId)[this.properties.propertyPath]; dataSourceValue = source.getPropertyValue(this.properties.propertyId)[this.properties.propertyPath];
} }
} else { } else {
dataSourceValue = this.properties.queryKeywords.tryGetValue(); dataSourceValue = this.properties.queryKeywords.tryGetValue();
} }
if (typeof(dataSourceValue) !== 'string') { if (typeof (dataSourceValue) !== 'string') {
dataSourceValue = ''; dataSourceValue = '';
this.context.propertyPane.refresh(); this.context.propertyPane.refresh();
} }
@ -121,7 +121,7 @@ export default class SearchResultsWebPart extends BaseClientSideWebPart<ISearchR
queryKeywords = dataSourceValue; queryKeywords = dataSourceValue;
} }
const isValueConnected = !!source; const isValueConnected = !!source;
const searchContainer: React.ReactElement<ISearchResultsContainerProps> = React.createElement( const searchContainer: React.ReactElement<ISearchResultsContainerProps> = React.createElement(
SearchResultsContainer, SearchResultsContainer,
{ {
@ -195,10 +195,10 @@ export default class SearchResultsWebPart extends BaseClientSideWebPart<ISearchR
this._resultService = new ResultService(); this._resultService = new ResultService();
this._codeRenderers = this._resultService.getRegisteredRenderers(); this._codeRenderers = this._resultService.getRegisteredRenderers();
if (this.properties.sourceId) { if (this.properties.sourceId) {
// Needed to retrieve manually the value for the dynamic property at render time. See the associated SPFx bug // Needed to retrieve manually the value for the dynamic property at render time. See the associated SPFx bug
// https://github.com/SharePoint/sp-dev-docs/issues/2985 // https://github.com/SharePoint/sp-dev-docs/issues/2985
this.context.dynamicDataProvider.registerSourceChanged(this.properties.sourceId, this.render); this.context.dynamicDataProvider.registerSourceChanged(this.properties.sourceId, this.render);
} }
// Set the default search results layout // Set the default search results layout
@ -207,6 +207,24 @@ export default class SearchResultsWebPart extends BaseClientSideWebPart<ISearchR
return super.onInit(); return super.onInit();
} }
private _convertToSortConfig(sortList: string): ISortFieldConfiguration[] {
let pairs = sortList.split(',');
return pairs.map(sort => {
let direction;
let kvp = sort.split(':');
if (kvp[1].toLocaleLowerCase().trim() === "ascending") {
direction = ISortFieldDirection.Ascending;
} else {
direction = ISortFieldDirection.Descending;
}
return {
sortField: kvp[0].trim(),
sortDirection: direction
} as ISortFieldConfiguration;
});
}
private _convertToSortList(sortList: ISortFieldConfiguration[]): Sort[] { private _convertToSortList(sortList: ISortFieldConfiguration[]): Sort[] {
return sortList.map(e => { return sortList.map(e => {
@ -247,6 +265,11 @@ export default class SearchResultsWebPart extends BaseClientSideWebPart<ISearchR
private initializeRequiredProperties() { private initializeRequiredProperties() {
this.properties.queryTemplate = this.properties.queryTemplate ? this.properties.queryTemplate : "{searchTerms} Path:{Site}"; this.properties.queryTemplate = this.properties.queryTemplate ? this.properties.queryTemplate : "{searchTerms} Path:{Site}";
if(isEmpty(this.properties.refiners)) {
this.properties.refiners = [];
}
this.properties.refiners = Array.isArray(this.properties.refiners) ? this.properties.refiners : [ this.properties.refiners = Array.isArray(this.properties.refiners) ? this.properties.refiners : [
{ {
refinerName: "Created", refinerName: "Created",
@ -261,6 +284,11 @@ export default class SearchResultsWebPart extends BaseClientSideWebPart<ISearchR
displayValue: "Tags" displayValue: "Tags"
} }
]; ];
if(!Array.isArray(this.properties.sortList) && !isEmpty(this.properties.sortList)) {
this.properties.sortList = this._convertToSortConfig(this.properties.sortList);
}
this.properties.sortList = Array.isArray(this.properties.sortList) ? this.properties.sortList : [ this.properties.sortList = Array.isArray(this.properties.sortList) ? this.properties.sortList : [
{ {
sortField: "Created", sortField: "Created",
@ -375,7 +403,7 @@ export default class SearchResultsWebPart extends BaseClientSideWebPart<ISearchR
await this.loadPropertyPaneResources(); await this.loadPropertyPaneResources();
} }
protected onBeforeSerialize() { protected onBeforeSerialize() {
this._saveDataSourceInfo(); this._saveDataSourceInfo();
super.onBeforeSerialize(); super.onBeforeSerialize();
} }
@ -384,16 +412,16 @@ export default class SearchResultsWebPart extends BaseClientSideWebPart<ISearchR
* Save the useful information for the connected data source. * Save the useful information for the connected data source.
* They will be used to get the value of the dynamic property if this one fails. * They will be used to get the value of the dynamic property if this one fails.
*/ */
private _saveDataSourceInfo() { private _saveDataSourceInfo() {
if (this.properties.queryKeywords.reference) { if (this.properties.queryKeywords.reference) {
this.properties.sourceId = this.properties.queryKeywords["_reference"]._sourceId; this.properties.sourceId = this.properties.queryKeywords["_reference"]._sourceId;
this.properties.propertyId = this.properties.queryKeywords["_reference"]._property; this.properties.propertyId = this.properties.queryKeywords["_reference"]._property;
this.properties.propertyPath = this.properties.queryKeywords["_reference"]._propertyPath; this.properties.propertyPath = this.properties.queryKeywords["_reference"]._propertyPath;
} else { } else {
this.properties.sourceId = null; this.properties.sourceId = null;
this.properties.propertyId = null; this.properties.propertyId = null;
this.properties.propertyPath = null; this.properties.propertyPath = null;
} }
} }