Skip to content

Commit 22f6d80

Browse files
committed
Merge branch 'master' into feature/KNOWAGE-9909
2 parents 3a54d43 + b4033e6 commit 22f6d80

5 files changed

Lines changed: 31 additions & 11 deletions

File tree

src/modules/documentExecution/dashboard/helpers/DashboardExportHelper.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import deepcopy from 'deepcopy'
2-
import { IDashboard, IDashboardDatasetDriver, IDashboardDriver, ISelection, IVariable, IWidget } from '../Dashboard'
2+
import { IDashboard, IDashboardDataset, IDashboardDatasetDriver, IDashboardDriver, ISelection, IVariable, IWidget, IWidgetSearch } from '../Dashboard'
3+
import { getTableWidgetLikeSelections } from './tableWidget/TableWidgetSearchHelper'
34

45
type IDashboardExportState = Pick<IDashboard, 'configuration'> & {
56
currentView?: unknown
@@ -15,6 +16,7 @@ type IWidgetExportBody = IWidget & {
1516
creationUser: string | undefined
1617
locale: string
1718
datasetDrivers?: IDashboardDatasetDriver[]
19+
likeSelections?: Record<string, Record<string, string>>
1820
xlsxStyleEnabled?: boolean
1921
}
2022

@@ -37,7 +39,9 @@ export const createDashboardSpreadsheetExportBody = (dashboard: IDashboardExport
3739
return body
3840
}
3941

40-
export const createWidgetExportBody = (type: string, widget: IWidget, dashboard: IDashboardExportState, creationUser: string | undefined, locale: string) => {
42+
const getDashboardDatasetLabel = (dataset: IDashboardDataset | undefined) => dataset?.dsLabel ?? dataset?.label
43+
44+
export const createWidgetExportBody = (type: string, widget: IWidget, dashboard: IDashboardExportState, creationUser: string | undefined, locale: string, widgetSearch?: IWidgetSearch) => {
4145
const dataset = dashboard.configuration.datasets.find((dashboardDataset) => dashboardDataset.id === widget.dataset)
4246
const body = {
4347
...deepcopy(widget),
@@ -51,6 +55,14 @@ export const createWidgetExportBody = (type: string, widget: IWidget, dashboard:
5155

5256
if (dataset?.drivers) body.datasetDrivers = dataset.drivers
5357
if (type === 'spreadsheet') body.xlsxStyleEnabled = getDashboardXlsxStyleEnabled(dashboard)
58+
const likeSelections =
59+
widget.type === 'table'
60+
? getTableWidgetLikeSelections(
61+
widgetSearch ?? (widget.search as IWidgetSearch | undefined),
62+
getDashboardDatasetLabel(dataset)
63+
)
64+
: null
65+
if (likeSelections) body.likeSelections = likeSelections
5466

5567
return body
5668
}

src/modules/documentExecution/dashboard/helpers/__tests__/DashboardExportHelper.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ describe('createWidgetExportBody', () => {
8787
expect(body.xlsxStyleEnabled).toBe(true)
8888
})
8989

90+
it('adds likeSelections when the widget export includes an active search', () => {
91+
const body = createWidgetExportBody('pdf', createWidget(), createDashboard(), 'bi-user', 'en-US', { searchText: 'it', searchColumns: ['COUNTRY', 'REGION'] })
92+
93+
expect(body.likeSelections).toEqual({ Sales: { 'COUNTRY,REGION': 'it' } })
94+
})
95+
9096
it('does not add xlsxStyleEnabled to non-spreadsheet exports', () => {
9197
const body = createWidgetExportBody('pdf', createWidget(), createDashboard(), 'bi-user', 'en-US')
9298

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { IWidgetSearch } from '../../Dashboard'
2+
3+
export const getTableWidgetLikeSelections = (searchParams: IWidgetSearch | undefined, datasetLabel?: string) => {
4+
if (!datasetLabel || !searchParams || searchParams.searchText === '' || !searchParams.searchColumns?.length) return null
5+
6+
const formattedLikeSelections = searchParams.searchColumns.toString()
7+
return { [datasetLabel]: { [formattedLikeSelections]: searchParams.searchText } }
8+
}

src/modules/documentExecution/dashboard/widget/TableWidget/TableWidgetDataProxy.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { indexedDB } from '@/idb'
55
import { md5 } from 'js-md5'
66
import deepcopy from 'deepcopy'
77
import dashboardStore from '@/modules/documentExecution/dashboard/Dashboard.store'
8+
import { getTableWidgetLikeSelections } from '../../helpers/tableWidget/TableWidgetSearchHelper'
89

910
export const getTableWidgetData = async (dashboardId: any, dashboardConfig: IDashboardConfiguration, widget: IWidget, datasets: IDashboardDataset[], $http: any, initialCall: boolean, selections: ISelection[], searchParams: IWidgetSearch, associativeResponseSelections?: any, resetPagination?: boolean) => {
1011
const dashStore = dashboardStore()
@@ -21,7 +22,7 @@ export const getTableWidgetData = async (dashboardId: any, dashboardConfig: IDas
2122
else url = `/restful-services/2.0/datasets/${selectedDataset.dsLabel}/data?offset=-1&size=-1&nearRealtime=${!selectedDataset.cache}`
2223

2324
const postData = formatTableWidgetModelForService(dashboardId, dashboardConfig, widget, selectedDataset, initialCall, selections, associativeResponseSelections)
24-
const formattedSelections = getLikeSelections(searchParams, datasetLabel)
25+
const formattedSelections = getTableWidgetLikeSelections(searchParams, datasetLabel)
2526
if (formattedSelections != null) postData.likeSelections = formattedSelections
2627
let tempResponse = null as any
2728

@@ -155,10 +156,3 @@ const getSummaryRow = (widget: IWidget, dashboardConfig: IDashboardConfiguration
155156

156157
return summaryArray
157158
}
158-
159-
const getLikeSelections = (searchParams: IWidgetSearch, datasetLabel: string) => {
160-
if (searchParams && searchParams?.searchText != '' && searchParams?.searchColumns?.length > 0) {
161-
const formattedLikeSelections = searchParams.searchColumns.toString()
162-
return { [datasetLabel]: { [formattedLikeSelections]: searchParams.searchText } }
163-
} else return null
164-
}

src/modules/documentExecution/dashboard/widget/WidgetController.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export default defineComponent({
355355
async widgetExport(type: string) {
356356
this.setLoading(true)
357357
const widgetToExport = this.widgetModel.type === 'static-pivot-table' ? enrichPivotWidgetWithSortState(this.widgetModel) : this.widgetModel
358-
const body = createWidgetExportBody(type, widgetToExport, this.dashStore.$state.dashboards[this.dashboardId], this.document?.creationUser, this.locale)
358+
const body = createWidgetExportBody(type, widgetToExport, this.dashStore.$state.dashboards[this.dashboardId], this.document?.creationUser, this.locale, this.search)
359359
await this.$http
360360
.post(import.meta.env.VITE_KNOWAGE_CONTEXT + `/restful-services/1.0/dashboardExport/${type}`, body, {
361361
responseType: 'blob',

0 commit comments

Comments
 (0)