Skip to content

Commit

Permalink
fiks for #1519 🐛 (#1533)
Browse files Browse the repository at this point in the history
  • Loading branch information
olemp authored May 29, 2024
1 parent 5f8d158 commit abb1cbc
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 247 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ common/temp
**/package-lock.json
.vscode/launch.json*
SharePointFramework/**/.vscode/chrome-debug-user-data
SharePointFramework/ProjectExtensions/.gitmoji.json
SharePointFramework/**/.gitmoji.json
SharePointFramework/**/environments.json
.gitmoji.json
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Sjekk ut [release notes](./releasenotes/1.9.0.md) for høydepunkter og mer detal
### Feilrettinger

- Rettet et problem hvor planneroppgaver ikke ble provisjonert i riktig rekkefølge [#1530](https://github.com/Puzzlepart/prosjektportalen365/issues/1530)
- Rettet et problem med eksport til Excel for aggregerte oversikter [#1519](https://github.com/Puzzlepart/prosjektportalen365/issues/1519)

---

Expand Down
3 changes: 2 additions & 1 deletion SharePointFramework/.tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"devDependencies": {
"@types/lodash": "4.14.195",
"@types/colors": "1.2.1"
"@types/colors": "1.2.1",
"pzl-spfx-tasks": "~0.5.10-1"
}
}
3 changes: 2 additions & 1 deletion SharePointFramework/PortfolioExtensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"prettier": "2.7.1",
"typescript": "4.5.5",
"webpack": "5.74.0",
"@types/lodash": "~4.14.195"
"@types/lodash": "~4.14.195",
"pzl-spfx-tasks": "~0.5.10-1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "./node_modules/pzl-spfx-tasks/environments.schema.json",
"environments": []
}
27 changes: 23 additions & 4 deletions SharePointFramework/PortfolioWebParts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"license": "MIT",
"scripts": {
"watch": "concurrently \"npm run serve\" \"livereload './dist/*.js' -e 'js' -w 250\"",
"prewatch": "node node_modules/pzl-spfx-tasks --pre-watch --loglevel silent",
"postwatch": "node node_modules/pzl-spfx-tasks --post-watch --loglevel silent",
"serve": "concurrently \"gulp serve-deprecated --locale=nb-no --nobrowser\"",
"build": "gulp bundle --ship && gulp package-solution --ship",
"postversion": "tsc && npm publish",
"lint": "eslint --ext .ts,.tsx ./src --color --fix --config ../.eslintrc.yaml && npm run prettier",
"prettier": "prettier '**/*.ts*' --write --loglevel silent --config ../.prettierrc.yaml",
"prewatch": "node ../.tasks/pre-watch.js",
"postwatch": "node ../.tasks/post-watch.js"
"prettier": "prettier '**/*.ts*' --write --loglevel silent --config ../.prettierrc.yaml"
},
"dependencies": {
"@fluentui/react": "8.98.1",
Expand Down Expand Up @@ -97,6 +97,25 @@
"webpack": "5.74.0",
"@types/react-beautiful-dnd": "~13.1.4",
"@types/lodash": "~4.14.195",
"@types/react-window": "~1.8.8"
"@types/react-window": "~1.8.8",
"pzl-spfx-tasks": "~0.5.10-1"
},
"config": {
"pzl-spfx-tasks": {
"upgrade": {
"types": [
"rush"
],
"all": true
},
"modifyconfig": {
"backupFilePath": "./config/config.json.bak"
},
"createlaunchconfig": {
"userDataDir": "${workspaceFolder}/../.vscode/chrome-debug-user-data",
"preferredBrowser": "chrome",
"domainSpecificDataDir": true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
ContentView24Filled,
ContentView24Regular,
EditFilled,
EditRegular,
FormNewFilled,
FormNewRegular, bundleIcon
} from '@fluentui/react-icons'

/**
* Object containing icons used in the toolbar.
*/
export const Icons = {
ContentView: bundleIcon(ContentView24Filled, ContentView24Regular),
FormNew: bundleIcon(FormNewFilled, FormNewRegular),
Edit: bundleIcon(EditFilled, EditRegular)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback } from 'react'
import ExcelExportService from 'pp365-shared-library/lib/services/ExcelExportService'
import { IPortfolioAggregationContext } from '../context'
import _ from 'lodash'

/**
* Hook that provides functionality for exporting data to Excel.
Expand All @@ -21,37 +22,46 @@ export function useExcelExport(context: IPortfolioAggregationContext) {
if (!ExcelExportService.isConfigured) {
return
}
const { selectedItems, columns } = context.state

const items =
selectedItems?.length > 0
? selectedItems
!_.isEmpty(context.state.selectedItems)
? context.state.selectedItems
: context.state.items.filter((item) => {
if (Object.keys(context.state.activeFilters).length === 0) {
return true
}
return Object.keys(context.state.activeFilters).every((key) => {
const filterValues = context.state.activeFilters[key]
return filterValues.some((filterValue) => {
return item[key] === filterValue || item[key]?.includes(filterValue)
})
if (Object.keys(context.state.activeFilters).length === 0) {
return true
}
return Object.keys(context.state.activeFilters).every((key) => {
const filterValues = context.state.activeFilters[key]
return filterValues.some((filterValue) => {
return item[key] === filterValue || item[key]?.includes(filterValue)
})
})
})

const filteredItems = items.map((item) => {
const filteredItem = { ...item }
Object.keys(filteredItem).forEach((key) => {
const column = columns.find((c) => c.fieldName === key)
if (column && (column.dataType === 'currency' || column.dataType === 'number')) {
filteredItem[key] = Math.floor(filteredItem[key])
const column = context.columns.find((c) => c.fieldName === key)
switch (column?.dataType) {
case 'percentage':
filteredItem[key] = Math.floor(filteredItem[key] * 100) + '%'
break
case 'currency':
case 'number':
filteredItem[key] = Math.floor(filteredItem[key])
break
default:
break
}
})
return filteredItem
})

ExcelExportService.export(filteredItems, columns)
} catch (error) {}
}, [context.state])
ExcelExportService.export(filteredItems, context.columns)
} catch (error) {
console.log(error)
}
}, [context.state, context.columns])

return { exportToExcel }
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
AppsListRegular,
ContentView24Filled,
ContentView24Regular,
EditFilled,
EditRegular,
FormNewFilled,
FormNewRegular,
TextBulletListLtrRegular,
bundleIcon
} from '@fluentui/react-icons'
TextBulletListLtrRegular} from '@fluentui/react-icons'
import * as strings from 'PortfolioWebPartsStrings'
import { ListMenuItem, ListMenuItemDivider } from 'pp365-shared-library'
import { useMemo } from 'react'
Expand All @@ -20,15 +12,7 @@ import {
TOGGLE_FILTER_PANEL
} from '../reducer'
import { useExcelExport } from './useExcelExport'

/**
* Object containing icons used in the toolbar.
*/
const Icons = {
ContentView: bundleIcon(ContentView24Filled, ContentView24Regular),
FormNew: bundleIcon(FormNewFilled, FormNewRegular),
Edit: bundleIcon(EditFilled, EditRegular)
}
import { Icons } from './icons'

/**
* Returns an array of toolbar items for the PortfolioAggregation component.
Expand Down
4 changes: 4 additions & 0 deletions SharePointFramework/ProgramWebParts/environments.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "./node_modules/pzl-spfx-tasks/environments.schema.json",
"environments": []
}
27 changes: 23 additions & 4 deletions SharePointFramework/ProgramWebParts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
},
"scripts": {
"watch": "concurrently \"npm run serve\" \"livereload './dist/*.js' -e 'js' -w 250\"",
"prewatch": "node node_modules/pzl-spfx-tasks --pre-watch --loglevel silent",
"postwatch": "node node_modules/pzl-spfx-tasks --post-watch --loglevel silent",
"serve": "concurrently \"gulp serve-deprecated --locale=nb-no --nobrowser\"",
"build": "gulp bundle --ship && gulp package-solution --ship",
"postversion": "tsc && npm publish",
"lint": "eslint --ext .ts,.tsx ./src --color --fix --config ../.eslintrc.yaml && npm run prettier",
"prettier": "prettier '**/*.ts*' --write --loglevel silent --config ../.prettierrc.yaml",
"prewatch": "node ../.tasks/pre-watch.js",
"postwatch": "node ../.tasks/post-watch.js"
"prettier": "prettier '**/*.ts*' --write --loglevel silent --config ../.prettierrc.yaml"
},
"dependencies": {
"@fluentui/react": "8.98.1",
Expand Down Expand Up @@ -95,6 +95,25 @@
"typescript": "4.5.5",
"webpack": "5.74.0",
"yargs": "14.2.0",
"@types/lodash": "~4.14.195"
"@types/lodash": "~4.14.195",
"pzl-spfx-tasks": "~0.5.10-1"
},
"config": {
"pzl-spfx-tasks": {
"upgrade": {
"types": [
"rush"
],
"all": true
},
"modifyconfig": {
"backupFilePath": "./config/config.json.bak"
},
"createlaunchconfig": {
"userDataDir": "${workspaceFolder}/../.vscode/chrome-debug-user-data",
"preferredBrowser": "chrome",
"domainSpecificDataDir": true
}
}
}
}
3 changes: 2 additions & 1 deletion SharePointFramework/ProjectExtensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"prettier": "2.7.1",
"typescript": "4.5.5",
"webpack": "5.74.0",
"@types/lodash": "~4.14.195"
"@types/lodash": "~4.14.195",
"pzl-spfx-tasks": "~0.5.10-1"
}
}
3 changes: 2 additions & 1 deletion SharePointFramework/ProjectWebParts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"typescript": "4.5.5",
"webpack": "5.74.0",
"@types/lodash": "~4.14.195",
"@types/smoothscroll-polyfill": "~0.3.3"
"@types/smoothscroll-polyfill": "~0.3.3",
"pzl-spfx-tasks": "~0.5.10-1"
}
}
3 changes: 2 additions & 1 deletion SharePointFramework/shared-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"typescript": "4.5.5",
"@microsoft/sp-module-interfaces": "1.17.4",
"@types/lodash": "~4.14.195",
"@types/shade-blend-color": "~1.0.3"
"@types/shade-blend-color": "~1.0.3",
"pzl-spfx-tasks": "~0.5.10-1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class ExcelExportService {
* @param items Items
* @param columns Columns
* @param fileNamePart Optional file name part to add after the name and before the date
* @param sheetNamePrefix Optional prefix for the sheet name
*/
public export(items: Record<string, any>[], columns: IColumn[], fileNamePart?: string) {
public export(items: Record<string, any>[], columns: IColumn[], fileNamePart?: string, sheetNamePrefix: string = 'Sheet') {
const fileNameFormat = fileNamePart ? '{0}-{1}-{2}.xlsx' : '{0}-{1}.xlsx'
try {
const sheets = []
Expand All @@ -42,19 +43,22 @@ class ExcelExportService {
name: this.configuration.sheetName,
data: [
_columns.map((column) => column.name),
...items.map((item) =>
_columns.map((column) => {
return (column as any).dataType === 'date'
? getDateValue(item, column.fieldName)
: get<string>(item, column.fieldName, null)
})
)
...items.map((item) => _columns.map((column) => {
switch ((column as any).dataType) {
case 'date': {
return getDateValue(item, column.fieldName)
}
default: {
return get(item, column.fieldName, null)
}
}
}))
]
})
const workBook = XLSX.utils.book_new()
sheets.forEach((s, index) => {
const sheet = XLSX.utils.aoa_to_sheet(s.data)
XLSX.utils.book_append_sheet(workBook, sheet, s.name ?? `Sheet${index + 1}`)
XLSX.utils.book_append_sheet(workBook, sheet, s.name ?? `${sheetNamePrefix}${index + 1}`)
})
const wbout = XLSX.write(workBook, this.configuration.options)
const fileName = fileNamePart
Expand Down
16 changes: 14 additions & 2 deletions SharePointFramework/shared-library/src/util/getDateValue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
export function getDateValue(item: any, fieldName: string): string {
return isNaN(item[fieldName]) ? '' : item[fieldName]
/**
* Get date value from item.
*
* @param item Item/record to get date value from.
* @param fieldName The field name of the date value.
*/
export function getDateValue(item: Record<string, any>, fieldName: string): string {
const dateValue = item[fieldName]
if (!dateValue) return ''
if (typeof dateValue === 'string') {
return new Date(dateValue).toLocaleString()
} else if (dateValue instanceof Date) {
return dateValue.toLocaleString()
}
}
2 changes: 1 addition & 1 deletion Templates/JsonTemplates/_JsonTemplateParent.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
"title": "Ressursallokeringer for underområder",
"dataSource": "Alle ressursallokeringer for underområder",
"dataSourceCategory": "Ressursallokering",
"hiddenColumns": "Title",
"hiddenColumns": ["Title"],
"showCommandBar": true,
"showViewSelector": true,
"showSearchBox": true
Expand Down
2 changes: 1 addition & 1 deletion Templates/JsonTemplates/_JsonTemplateProgram.json
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@
"title": "Ressursallokeringer for underområder",
"dataSource": "Alle ressursallokeringer for underområder",
"dataSourceCategory": "Ressursallokering",
"hiddenColumns": "Title",
"hiddenColumns": ["Title"],
"showCommandBar": true,
"showViewSelector": true,
"showSearchBox": true
Expand Down
3 changes: 2 additions & 1 deletion Templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"devDependencies": {
"replace": "1.2.2",
"@types/lodash": "~4.14.195"
"@types/lodash": "~4.14.195",
"pzl-spfx-tasks": "~0.5.10-1"
}
}
Loading

0 comments on commit abb1cbc

Please sign in to comment.