From 4b6ee6c140eb5b367cfbae1e1a97f9b21333e5e8 Mon Sep 17 00:00:00 2001 From: Ole Martin Pettersen Date: Fri, 22 Sep 2023 11:50:41 +0200 Subject: [PATCH] Fix for 2.2 #1267 --- .../PortfolioWebParts/package.json | 1 + .../ColumnFormPanel/index.tsx | 7 --- .../ColumnFormPanel/useColumnFormPanel.ts | 24 ++++----- .../components/PortfolioAggregation/index.tsx | 1 - .../PortfolioAggregation/reducer/actions.ts | 2 +- .../createPortfolioAggregationReducer.ts | 50 ++++++++----------- ...rsistSelectedColumnsInWebPartProperties.ts | 14 +++++- .../PortfolioWebParts/src/data/index.ts | 5 +- .../webparts/portfolioAggregation/index.tsx | 31 +++++++++++- .../src/models/ProjectContentColumn.ts | 22 ++++++++ common/config/rush/pnpm-lock.yaml | 7 ++- 11 files changed, 105 insertions(+), 59 deletions(-) diff --git a/SharePointFramework/PortfolioWebParts/package.json b/SharePointFramework/PortfolioWebParts/package.json index 068c1548d..d632ee4b8 100644 --- a/SharePointFramework/PortfolioWebParts/package.json +++ b/SharePointFramework/PortfolioWebParts/package.json @@ -28,6 +28,7 @@ "@microsoft/sp-page-context": "1.17.4", "@microsoft/sp-property-pane": "1.17.4", "@microsoft/sp-webpart-base": "1.17.4", + "@microsoft/sp-http": "1.17.4", "@pnp/logging": "3.17.0", "@pnp/sp": "3.17.0", "@pnp/sp-taxonomy": "1.3.8", diff --git a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/ColumnFormPanel/index.tsx b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/ColumnFormPanel/index.tsx index 0cb3a5b3d..7242490c3 100644 --- a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/ColumnFormPanel/index.tsx +++ b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/ColumnFormPanel/index.tsx @@ -98,13 +98,6 @@ export const ColumnFormPanel: FC = () => { min={column.get('minWidth') ?? 0} /> - - setColumn('isResizable', checked)} - /> - { const editedColumn = new ProjectContentColumn(columnItem) context.dispatch( - ADD_COLUMN({ - column: editedColumn - }) + ADD_COLUMN(editedColumn) ) }) - ) - } else { - await Promise.resolve( - context.props.dataAdapter.portalDataService + } else { + await context.props.dataAdapter.portalDataService .addItemToList('PROJECT_CONTENT_COLUMNS', _.omit(columnItem, ['Id'])) .then((properties) => { const newColumn = new ProjectContentColumn(properties) @@ -60,13 +56,13 @@ export function useColumnFormPanel() { .updateDataSourceItem(updateItem, context.state.currentView?.title) .then(() => { context.dispatch( - ADD_COLUMN({ - column: newColumn - }) + ADD_COLUMN(newColumn) ) }) }) - ) + } + } catch (error) { + console.error(error) } } diff --git a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/index.tsx b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/index.tsx index 9520d17cb..4699f2170 100644 --- a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/index.tsx +++ b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/index.tsx @@ -21,7 +21,6 @@ export const PortfolioAggregation: FC = (props) => { filterPanelProps, selection } = usePortfolioAggregation(props) - return (
diff --git a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/actions.ts b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/actions.ts index 44a6c5f61..7e7c335cb 100644 --- a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/actions.ts +++ b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/actions.ts @@ -42,7 +42,7 @@ export const TOGGLE_COMPACT = createAction('TOGGLE_COMPACT') /** * `ADD_COLUMN`: Add column. */ -export const ADD_COLUMN = createAction<{ column: ProjectContentColumn }>('ADD_COLUMN') +export const ADD_COLUMN = createAction('ADD_COLUMN') /** * `DELETE_COLUMN`: Delete column. diff --git a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/createPortfolioAggregationReducer.ts b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/createPortfolioAggregationReducer.ts index b4b177025..37b9c6436 100644 --- a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/createPortfolioAggregationReducer.ts +++ b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/createPortfolioAggregationReducer.ts @@ -5,10 +5,10 @@ import * as strings from 'PortfolioWebPartsStrings' import sortArray from 'array-sort' import _ from 'lodash' import { IFilterItemProps } from 'pp365-shared-library/lib/components/FilterPanel' -import { arrayMove } from 'pp365-shared-library/lib/util/arrayMove' -import { getObjectValue as get } from 'pp365-shared-library/lib/util/getObjectValue' import { DataSource } from 'pp365-shared-library/lib/models/DataSource' import { parseUrlHash, setUrlHash } from 'pp365-shared-library/lib/util' +import { arrayMove } from 'pp365-shared-library/lib/util/arrayMove' +import { getObjectValue as get } from 'pp365-shared-library/lib/util/getObjectValue' import { IPortfolioAggregationHashState, IPortfolioAggregationProps, @@ -17,7 +17,6 @@ import { } from '../types' import { ADD_COLUMN, - TOGGLE_COLUMN_CONTEXT_MENU, DATA_FETCHED, DATA_FETCH_ERROR, DELETE_COLUMN, @@ -25,6 +24,7 @@ import { GET_FILTERS, MOVE_COLUMN, ON_FILTER_CHANGE, + SELECTION_CHANGED, SET_ALL_COLLAPSED, SET_COLLAPSED, SET_COLUMNS, @@ -32,14 +32,14 @@ import { SET_DATA_SOURCE, SET_GROUP_BY, SET_SORT, + SET_VIEW_FORM_PANEL, SHOW_HIDE_COLUMNS, START_FETCH, + TOGGLE_COLUMN_CONTEXT_MENU, TOGGLE_COLUMN_FORM_PANEL, TOGGLE_COMPACT, TOGGLE_EDIT_VIEW_COLUMNS_PANEL, - TOGGLE_FILTER_PANEL, - SET_VIEW_FORM_PANEL, - SELECTION_CHANGED + TOGGLE_FILTER_PANEL } from './actions' import { persistSelectedColumnsInWebPartProperties } from './persistSelectedColumnsInWebPartProperties' @@ -62,7 +62,7 @@ export const createPortfolioAggregationReducer = ( }) if (payload.projects) { items = items.filter((item) => - _.some(payload.projects, (project) => project.GtSiteId === item.SiteId) + _.some(payload.projects, ({ GtSiteId }) => GtSiteId === item.SiteId) ) } state.items = items @@ -73,7 +73,7 @@ export const createPortfolioAggregationReducer = ( state.columns = [] return } - const selectedColumns = !_.isEmpty(props.columns) + let selectedColumns = !_.isEmpty(props.columns) ? props.columns : payload.dataSource.columns ?? [] const allColumnsForCategory = payload.columns.map((c) => @@ -81,27 +81,17 @@ export const createPortfolioAggregationReducer = ( isSelected: _.some(selectedColumns, ({ key }) => key === c.key) || c.data.isLocked }) ) - const selectedColumnsMerged = selectedColumns + selectedColumns = selectedColumns .map((c) => { const col = _.find(allColumnsForCategory, ({ key }) => key === c.key) - return ( - col && - col.setData({ - ...c.data, - dataTypeProperties: { - ...col.data.dataTypeProperties, - ...c.data.dataTypeProperties - }, - renderAs: c.data.renderAs ?? col.dataType ?? 'text' - }) - ) + return col ? col.merge(c) : null }) .filter(Boolean) const availableColumns = payload.columns.filter( - (c) => !_.some(selectedColumnsMerged, ({ key }) => key === c.key) + (c) => !_.some(selectedColumns, ({ key }) => key === c.key) ) - state.columns = !_.isEmpty(selectedColumnsMerged) - ? [...selectedColumnsMerged, ...availableColumns] + state.columns = !_.isEmpty(selectedColumns) + ? [...selectedColumns, ...availableColumns] : sortArray(allColumnsForCategory, 'sortOrder') state.allColumnsForCategory = allColumnsForCategory state.loading = false @@ -126,7 +116,7 @@ export const createPortfolioAggregationReducer = ( }, [ADD_COLUMN.type]: (state, { payload }: ReturnType) => { const isEdit = !!state.columnForm?.column - const column = payload.column.setData({ isSelected: true }) + const column = payload.setData({ isSelected: true }) let columns = [...state.columns] let allColumnsForCategory = [...state.allColumnsForCategory] if (isEdit) { @@ -160,9 +150,9 @@ export const createPortfolioAggregationReducer = ( ) => { state.columnContextMenu = payload ? { - column: payload.column, - target: payload.target as any - } + column: payload.column, + target: payload.target as any + } : null }, [SET_ALL_COLLAPSED.type]: (state, { payload }: ReturnType) => { @@ -377,7 +367,7 @@ export const createPortfolioAggregationReducer = ( } } }, -[SELECTION_CHANGED.type]: (state, { payload }: ReturnType) => { - state.selectedItems = payload.getSelection() -} + [SELECTION_CHANGED.type]: (state, { payload }: ReturnType) => { + state.selectedItems = payload.getSelection() + } }) diff --git a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/persistSelectedColumnsInWebPartProperties.ts b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/persistSelectedColumnsInWebPartProperties.ts index 89dc13edf..885d69834 100644 --- a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/persistSelectedColumnsInWebPartProperties.ts +++ b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/reducer/persistSelectedColumnsInWebPartProperties.ts @@ -4,7 +4,18 @@ import { ProjectContentColumn } from 'pp365-shared-library' /** * Persist columns in web part properties for `` component - * using the `onUpdateProperty` callback and property key `columns`. + * using the `onUpdateProperty` callback and property key `columns`. + * + * By default the following properties for the columns are persisted: + * - `id` + * - `sortOrder` + * - `key` + * - `fieldName` + * - `internalName` + * - `name` + * - `minWidth` + * - `maxWidth` + * - `data` * * @param props Props for `` component * @param columns Columns to persist to property `columns` @@ -21,6 +32,7 @@ export function persistSelectedColumnsInWebPartProperties( 'internalName', 'name', 'minWidth', + 'maxWidth', 'data' ] ) { diff --git a/SharePointFramework/PortfolioWebParts/src/data/index.ts b/SharePointFramework/PortfolioWebParts/src/data/index.ts index 6a488204b..93bbb8336 100644 --- a/SharePointFramework/PortfolioWebParts/src/data/index.ts +++ b/SharePointFramework/PortfolioWebParts/src/data/index.ts @@ -788,7 +788,7 @@ export class DataAdapter implements IPortfolioWebPartsDataAdapter { public async updateProjectContentColumn( columnItem: SPProjectContentColumnItem, persistRenderAs = false - ): Promise { + ): Promise { try { const list = this._sp.web.lists.getByTitle(strings.ProjectContentColumnsListName) const properties: SPProjectContentColumnItem = _.pick( @@ -800,7 +800,8 @@ export class DataAdapter implements IPortfolioWebPartsDataAdapter { persistRenderAs && 'GtFieldDataType' ].filter(Boolean) ) - return await list.items.getById(columnItem.Id).update(properties) + const update = await list.items.getById(columnItem.Id).update(properties) + return update } catch (error) { throw new Error(error) } diff --git a/SharePointFramework/PortfolioWebParts/src/webparts/portfolioAggregation/index.tsx b/SharePointFramework/PortfolioWebParts/src/webparts/portfolioAggregation/index.tsx index fda64d97f..00a40ac9f 100644 --- a/SharePointFramework/PortfolioWebParts/src/webparts/portfolioAggregation/index.tsx +++ b/SharePointFramework/PortfolioWebParts/src/webparts/portfolioAggregation/index.tsx @@ -15,6 +15,8 @@ import { import _ from 'lodash' import React from 'react' import { BasePortfolioWebPart } from '../basePortfolioWebPart' +import { ISPHttpClientOptions, SPHttpClient } from '@microsoft/sp-http' +import { DisplayMode } from '@microsoft/sp-core-library' export default class PortfolioAggregationWebPart extends BasePortfolioWebPart { private _configuration: IPortfolioAggregationConfiguration @@ -39,9 +41,34 @@ export default class PortfolioAggregationWebPart extends BasePortfolioWebPart { diff --git a/SharePointFramework/shared-library/src/models/ProjectContentColumn.ts b/SharePointFramework/shared-library/src/models/ProjectContentColumn.ts index b20e8da18..a4b9677a2 100644 --- a/SharePointFramework/shared-library/src/models/ProjectContentColumn.ts +++ b/SharePointFramework/shared-library/src/models/ProjectContentColumn.ts @@ -83,4 +83,26 @@ export class ProjectContentColumn implements IProjectContentColumn { } return this } + + /** + * Merges the properties of the given `ProjectContentColumn` into this instance. + * If a property is not defined in the given column, the current value of the property is retained. + * + * @param column The `ProjectContentColumn` to merge into this instance. + * + * @returns This instance with the merged properties. + */ + public merge(column: ProjectContentColumn): ProjectContentColumn { + this.name = column.name ?? this.name + this.minWidth = column.minWidth ?? this.minWidth + this.maxWidth = column.maxWidth ?? this.maxWidth + return this.setData({ + ...column.data, + dataTypeProperties: { + ...this.data.dataTypeProperties, + ...column.data.dataTypeProperties + }, + renderAs: column.data.renderAs ?? this.dataType ?? 'text' + }) + } } diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 17b3e50bd..3acf82e9a 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -15,6 +15,7 @@ dependencies: '@microsoft/sp-build-web': 1.17.4 '@microsoft/sp-core-library': 1.17.4_9c907a7ccd27a2e2d0ee9de5366482d1 '@microsoft/sp-dialog': 1.17.4_5bb3879ba087c0ef402ac2f0f80f9922 + '@microsoft/sp-http': 1.17.4_9c907a7ccd27a2e2d0ee9de5366482d1 '@microsoft/sp-listview-extensibility': 1.17.4_9c907a7ccd27a2e2d0ee9de5366482d1 '@microsoft/sp-lodash-subset': 1.17.4 '@microsoft/sp-module-interfaces': 1.17.4 @@ -97,6 +98,7 @@ dependencies: typescript: 4.5.5 underscore: 1.13.6 use-image-color: 0.0.9_react@17.0.1 + usehooks-ts: 2.9.1_react-dom@17.0.1+react@17.0.1 valid-filename: 3.1.0 webpack: 5.74.0 xlsx: 0.16.9 @@ -22686,6 +22688,7 @@ packages: '@microsoft/rush-stack-compiler-4.5': 0.2.2 '@microsoft/sp-build-web': 1.17.4 '@microsoft/sp-core-library': 1.17.4_9c907a7ccd27a2e2d0ee9de5366482d1 + '@microsoft/sp-http': 1.17.4_9c907a7ccd27a2e2d0ee9de5366482d1 '@microsoft/sp-lodash-subset': 1.17.4 '@microsoft/sp-office-ui-fabric-core': 1.17.4 '@microsoft/sp-page-context': 1.17.4_9c907a7ccd27a2e2d0ee9de5366482d1 @@ -22749,7 +22752,7 @@ packages: dev: false name: '@rush-temp/pp365-portfoliowebparts' resolution: - integrity: sha512-xS2QZfYAFiBRX9d84UltMv6ZX39+bMBfDFPDowrQ1KXNGjP9hrjwPNhgVGt51CqSR9RMgD3fPwSN8p7w6tDcfg== + integrity: sha512-/lYDOz9JwtNxGGxg5GJYS8/320hbiUFsl/zSuar9MXTDNT8ASJzZ43bDxfD+V45QelBhKaXvgndu7Gjc5aYs7g== tarball: file:projects/pp365-portfoliowebparts.tgz version: 0.0.0 file:projects/pp365-programwebparts.tgz: @@ -23090,6 +23093,7 @@ specifiers: '@microsoft/sp-build-web': 1.17.4 '@microsoft/sp-core-library': 1.17.4 '@microsoft/sp-dialog': 1.17.4 + '@microsoft/sp-http': 1.17.4 '@microsoft/sp-listview-extensibility': 1.17.4 '@microsoft/sp-lodash-subset': 1.17.4 '@microsoft/sp-module-interfaces': 1.17.4 @@ -23172,6 +23176,7 @@ specifiers: typescript: 4.5.5 underscore: ~1.13.6 use-image-color: ~0.0.9 + usehooks-ts: ~2.9.1 valid-filename: 3.1.0 webpack: 5.74.0 xlsx: ^0.16.9