Skip to content

Commit

Permalink
Merge pull request #3809 from SherpasGroup/fix-enable-grouping
Browse files Browse the repository at this point in the history
Fix for enabling results grouping for newly added results webpart
  • Loading branch information
wobba authored Dec 20, 2024
2 parents 2688220 + aea5c36 commit 1064a49
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion search-extensibility/src/models/layouts/ILayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ILayout {
/**
* Check if web part is in display or edit mode
*/
editMode: boolean
editMode: boolean;

/**
* Method called during the Web Part initialization.
Expand Down
8 changes: 4 additions & 4 deletions search-parts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion search-parts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@microsoft/sp-property-pane": "1.20.0",
"@microsoft/sp-webpart-base": "1.20.0",
"@pnp/common": "2.0.13",
"@pnp/modern-search-extensibility": "1.20.0",
"@pnp/modern-search-extensibility": "1.20.1",
"@pnp/spfx-controls-react": "3.20.0",
"@pnp/spfx-property-controls": "3.19.0",
"@pnp/telemetry-js": "2.0.0",
Expand Down
5 changes: 3 additions & 2 deletions search-parts/src/helpers/LayoutHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ILayoutDefinition, ILayout, BaseLayout, LayoutRenderType } from '@pnp/modern-search-extensibility';
import { BuiltinLayoutsKeys } from '../layouts/AvailableLayouts';
import { ServiceKey, ServiceScope, Text } from '@microsoft/sp-core-library';
import { DisplayMode, ServiceKey, ServiceScope, Text } from '@microsoft/sp-core-library';
import { ServiceScopeHelper } from './ServiceScopeHelper';
import { IPropertyPaneChoiceGroupOption } from '@microsoft/sp-property-pane';
import ISearchFiltersWebPartProps from '../webparts/searchFilters/ISearchFiltersWebPartProps';
Expand All @@ -19,7 +19,7 @@ export class LayoutHelper {
* @param layoutDefinitions the available layout definitions
* @returns the data source provider instance
*/
public static async getLayoutInstance(rootScope: ServiceScope, context: WebPartContext, properties: ISearchFiltersWebPartProps | ISearchResultsWebPartProps, layoutKey: string, layoutDefinitions: ILayoutDefinition[]): Promise<ILayout> {
public static async getLayoutInstance(rootScope: ServiceScope, context: WebPartContext, properties: ISearchFiltersWebPartProps | ISearchResultsWebPartProps, layoutKey: string, layoutDefinitions: ILayoutDefinition[], displayMode: DisplayMode): Promise<ILayout> {

let layout: ILayout = undefined;
let serviceKey: ServiceKey<ILayout> = undefined;
Expand Down Expand Up @@ -233,6 +233,7 @@ export class LayoutHelper {

layout.properties = properties.layoutProperties; // Web Parts using layouts must define this sub property
layout.context = context;
layout.editMode = displayMode === DisplayMode.Edit;
await layout.onInit();
resolve(layout);
}
Expand Down
23 changes: 11 additions & 12 deletions search-parts/src/layouts/results/detailsList/DetailListLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,20 @@ export class DetailsListLayout extends BaseLayout<IDetailsListLayoutProperties>
this.properties.additionalGroupByFields = this.properties.additionalGroupByFields ? this.properties.additionalGroupByFields : [];
this.properties.groupsCollapsed = this.properties.groupsCollapsed !== null && this.properties.groupsCollapsed !== undefined ? this.properties.groupsCollapsed : true;

const { PropertyFieldCollectionData, CustomCollectionFieldType } = await import(
if (this.editMode) {
const { PropertyFieldCollectionData, CustomCollectionFieldType } = await import(
/* webpackChunkName: 'pnp-modern-search-results-detailslist-layout' */
'@pnp/spfx-property-controls/lib/PropertyFieldCollectionData'
);
this._propertyFieldCollectionData = PropertyFieldCollectionData;

if (this.properties.enableGrouping) {
const { PropertyPaneWebPartInformation } = await import(
/* webpackChunkName: 'pnp-modern-search-property-pane' */
'@pnp/spfx-property-controls/lib/PropertyPaneWebPartInformation'
);
this._propertyPaneWebPartInformation = PropertyPaneWebPartInformation;
);
this._propertyFieldCollectionData = PropertyFieldCollectionData;
this._customCollectionFieldType = CustomCollectionFieldType;

const { PropertyPaneWebPartInformation } = await import(
/* webpackChunkName: 'pnp-modern-search-property-pane' */
'@pnp/spfx-property-controls/lib/PropertyPaneWebPartInformation'
);
this._propertyPaneWebPartInformation = PropertyPaneWebPartInformation;
}

this._customCollectionFieldType = CustomCollectionFieldType;
}

public getPropertyPaneFieldsConfiguration(availableFields: string[], dataContext?: IDataContext): IPropertyPaneField<any>[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class SearchFiltersWebPart extends BaseWebPart<ISearchFiltersWebP

// Get and initialize layout instance if different (i.e avoid to create a new instance every time)
if (this.lastLayoutKey !== this.properties.selectedLayoutKey) {
this.layout = await LayoutHelper.getLayoutInstance(this.webPartInstanceServiceScope, this.context, this.properties, this.properties.selectedLayoutKey, this.availableLayoutDefinitions);
this.layout = await LayoutHelper.getLayoutInstance(this.webPartInstanceServiceScope, this.context, this.properties, this.properties.selectedLayoutKey, this.availableLayoutDefinitions, this.displayMode);
this.lastLayoutKey = this.properties.selectedLayoutKey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export default class SearchResultsWebPart extends BaseWebPart<ISearchResultsWebP

// Get and initialize layout instance if different (i.e avoid to create a new instance every time)
if (this.lastLayoutKey !== this.properties.selectedLayoutKey) {
this.layout = await LayoutHelper.getLayoutInstance(this.webPartInstanceServiceScope, this.context, this.properties, this.properties.selectedLayoutKey, this.availableLayoutDefinitions);
this.layout = await LayoutHelper.getLayoutInstance(this.webPartInstanceServiceScope, this.context, this.properties, this.properties.selectedLayoutKey, this.availableLayoutDefinitions, this.displayMode);
this.lastLayoutKey = this.properties.selectedLayoutKey;
}

Expand Down

0 comments on commit 1064a49

Please sign in to comment.