Skip to content

Commit 019b5bb

Browse files
committed
2 parents 0b681c7 + 9d13151 commit 019b5bb

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/modules/documentExecution/dashboard/Dashboard.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ export interface IDashboardDriver {
799799
value: string
800800
urlName: string
801801
driverLabel: string
802+
description?: string
802803
}
803804

804805
export interface IGalleryItem {

src/modules/documentExecution/dashboard/widget/interactionsHelpers/InteractionsParserHelper.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import { IDashboardDriver, IVariable } from '../../Dashboard'
22
import { columnFieldRegex, parameterTextCompatibilityRegex, variableTextCompatibilityRegex } from '../../helpers/common/DashboardRegexHelper'
33

4+
const driverDescriptionSuffix = '_description'
5+
6+
const getDriverValueByPlaceholder = (drivers: IDashboardDriver[], parameterName: string, key: 'urlName' | 'name') => {
7+
if (!drivers?.length) return ''
8+
9+
const exactMatchDriver = drivers.find((driver: IDashboardDriver) => driver[key] === parameterName)
10+
if (exactMatchDriver) return exactMatchDriver.value ?? ''
11+
12+
if (!parameterName.endsWith(driverDescriptionSuffix)) return ''
13+
14+
const driverName = parameterName.substring(0, parameterName.length - driverDescriptionSuffix.length)
15+
const descriptionMatchDriver = drivers.find((driver: IDashboardDriver) => driver[key] === driverName)
16+
return descriptionMatchDriver?.description ?? ''
17+
}
18+
419
export const replaceVariablesPlaceholdersByVariableName = (originalValue: string | number, variables: IVariable[]) => {
520
if (!originalValue) return originalValue
621

@@ -35,11 +50,7 @@ export const replaceDriversPlaceholdersByDriverUrlName = (originalString: string
3550
if (!originalString) return originalString
3651

3752
originalString = originalString.replace(parameterTextCompatibilityRegex, (match: string, parameterName: string) => {
38-
if (drivers && drivers.length > 0) {
39-
const dashboardVariable = drivers.find((driver: IDashboardDriver) => driver.urlName === parameterName)
40-
if (dashboardVariable) return dashboardVariable.value ?? ''
41-
}
42-
return ''
53+
return getDriverValueByPlaceholder(drivers, parameterName, 'urlName')
4354
})
4455
return originalString
4556
}
@@ -48,11 +59,7 @@ export const replaceDriversPlaceholdersByDriverName = (originalString: string, d
4859
if (!originalString) return originalString
4960

5061
originalString = originalString.replace(parameterTextCompatibilityRegex, (match: string, parameterName: string) => {
51-
if (drivers && drivers.length > 0) {
52-
const dashboardVariable = drivers.find((driver: IDashboardDriver) => driver.name === parameterName)
53-
if (dashboardVariable) return dashboardVariable.value ?? ''
54-
}
55-
return ''
62+
return getDriverValueByPlaceholder(drivers, parameterName, 'name')
5663
})
5764
return originalString
5865
}

src/modules/documentExecution/dashboard/widget/interactionsHelpers/__tests__/InteractionsParserHelper.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,26 @@ describe('replaceVariablesPlaceholdersByVariableName', () => {
2121
})
2222

2323
describe('replaceDriversPlaceholdersByDriverUrlName', () => {
24-
const drivers = [{ name: 'Country', urlName: 'country', value: 'Italy', type: 'STRING', multivalue: false, visible: true, driverLabel: 'COUNTRY' }] as any[]
24+
const drivers = [{ name: 'Country', urlName: 'country', value: 'IT', description: 'Italy', type: 'STRING', multivalue: false, visible: true, driverLabel: 'COUNTRY' }] as any[]
2525

2626
it('replaces a driver placeholder using the urlName', () => {
27-
expect(replaceDriversPlaceholdersByDriverUrlName('Country: $P{country}', drivers)).toBe('Country: Italy')
27+
expect(replaceDriversPlaceholdersByDriverUrlName('Country: $P{country}', drivers)).toBe('Country: IT')
28+
})
29+
30+
it('replaces a driver description placeholder using the urlName', () => {
31+
expect(replaceDriversPlaceholdersByDriverUrlName('Country: $P{country_description}', drivers)).toBe('Country: Italy')
2832
})
2933
})
3034

3135
describe('replaceVariablesAndDriversPlaceholders', () => {
3236
const variables = [{ name: 'Year', value: '2024', type: 'static' }] as any[]
33-
const drivers = [{ name: 'Country', urlName: 'country', value: 'Italy', type: 'STRING', multivalue: false, visible: true, driverLabel: 'COUNTRY' }] as any[]
37+
const drivers = [{ name: 'Country', urlName: 'country', value: 'IT', description: 'Italy', type: 'STRING', multivalue: false, visible: true, driverLabel: 'COUNTRY' }] as any[]
3438

3539
it('resolves mixed static text, variables and document parameters in the same title', () => {
36-
expect(replaceVariablesAndDriversPlaceholders('Sales $V{Year} - $P{country}', variables, drivers)).toBe('Sales 2024 - Italy')
40+
expect(replaceVariablesAndDriversPlaceholders('Sales $V{Year} - $P{country}', variables, drivers)).toBe('Sales 2024 - IT')
41+
})
42+
43+
it('resolves parameter description placeholders in widget titles', () => {
44+
expect(replaceVariablesAndDriversPlaceholders('Sales $V{Year} - $P{country_description}', variables, drivers)).toBe('Sales 2024 - Italy')
3745
})
3846
})

0 commit comments

Comments
 (0)