Skip to content

Commit

Permalink
AAE-21967 use column id to retrieve variable column types (#9629)
Browse files Browse the repository at this point in the history
* AAE-21967 use column id to retrieve variable column types

* AAE-21967 fix variable mapper units
  • Loading branch information
wojd0 authored Apr 30, 2024
1 parent f401b8c commit 74d558c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ProcessListDatatableAdapter', () => {
const viewModel: ProcessInstanceCloudListViewModel = {
id: '1',
variablesMap: {
columnDisplayName1: getProcessInstanceVariableMock({ type: 'number' })
columnId1: getProcessInstanceVariableMock({ type: 'number' })
}
};

Expand All @@ -38,7 +38,7 @@ describe('ProcessListDatatableAdapter', () => {
};

const column: DataColumn<ProcessListDataColumnCustomData> = getDataColumnMock({
title: 'columnDisplayName1',
id: 'columnId1',
customData: {
assignedVariableDefinitionIds: ['1'],
variableDefinitionsPayload: ['processKey/variableName'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ import { ProcessListDataColumnCustomData, PROCESS_LIST_CUSTOM_VARIABLE_COLUMN }
import { ProcessInstanceCloudListViewModel } from '../models/perocess-instance-cloud-view.model';

export class ProcessListDatatableAdapter extends ObjectDataTableAdapter {
constructor(
data: ProcessInstanceCloudListViewModel[],
schema: DataColumn<ProcessListDataColumnCustomData>[]
) {
constructor(data: ProcessInstanceCloudListViewModel[], schema: DataColumn<ProcessListDataColumnCustomData>[]) {
super(data, schema);
}

getColumnType(row: DataRow, col: DataColumn<ProcessListDataColumnCustomData>): string {
if (col.customData?.columnType === PROCESS_LIST_CUSTOM_VARIABLE_COLUMN) {
const variableDisplayName = col.title;
const columnType = row.obj.variablesMap?.[variableDisplayName]?.type;
const columnType = row.obj.variablesMap?.[col.id]?.type;
return columnType ?? 'text';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('VariableMapperService', () => {

const viewModel = service.mapVariablesByColumnTitle([objectWithVariables], [column]);

expect(viewModel[0].variablesMap[column.title].type).toEqual(expectedColumnType);
expect(viewModel[0].variablesMap[column.id].type).toEqual(expectedColumnType);
};

beforeEach(() => {
Expand All @@ -58,11 +58,11 @@ describe('VariableMapperService', () => {
};
});

it('should map variables by column title', () => {
it('should map variables by column id', () => {
const expectedObjectWithVariableMap = {
...objectWithVariables,
variablesMap: {
[column.title]: variable
[column.id]: variable
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { DataColumnType } from '@alfresco/adf-extensions';

@Injectable({ providedIn: 'root' })
export class VariableMapperService {
mapVariablesByColumnTitle <T extends { variables?: ProcessInstanceVariable[] }>(
mapVariablesByColumnTitle<T extends { variables?: ProcessInstanceVariable[] }>(
instancesList: T[] = [],
columnsSchema: DataColumn<ProcessListDataColumnCustomData>[] = []
): Array<WithVariablesMap<T>> {
Expand All @@ -34,19 +34,22 @@ export class VariableMapperService {
return instance;
}

const variablesMap = (instance.variables ?? []).reduce<{[columnTitle: string]: ProcessInstanceVariable}>((variableAccumulator, variable) => {
const processVariableDefinitionPayload = `${variable.processDefinitionKey}/${variable.name}`;
const variablesMap = (instance.variables ?? []).reduce<{ [columnTitle: string]: ProcessInstanceVariable }>(
(variableAccumulator, variable) => {
const processVariableDefinitionPayload = `${variable.processDefinitionKey}/${variable.name}`;

const column = columnsByVariables[processVariableDefinitionPayload];
if (column) {
variableAccumulator[column] = {
...variable,
type: this.mapProcessVariableTypes(variable.type)
};
}
const column = columnsByVariables[processVariableDefinitionPayload];
if (column) {
variableAccumulator[column] = {
...variable,
type: this.mapProcessVariableTypes(variable.type)
};
}

return variableAccumulator;
}, {});
return variableAccumulator;
},
{}
);

return {
...instance,
Expand All @@ -57,20 +60,16 @@ export class VariableMapperService {
return rowsViewModel;
}

private mapColumnKeysByVariable(
columnsSchema: DataColumn<ProcessListDataColumnCustomData>[]
): { [key: string]: string } {
private mapColumnKeysByVariable(columnsSchema: DataColumn<ProcessListDataColumnCustomData>[]): { [key: string]: string } {
const columnsByVariables = columnsSchema
.filter(column => !!column.customData)
.filter((column) => !!column.customData)
.reduce<{ [key: string]: string }>((columnsByVariable, column) => {
const columnTitle = column.title;
const variables = column.customData.variableDefinitionsPayload;

variables.forEach((key) => {
columnsByVariable[key] = columnTitle;
columnsByVariable[key] = column.id;
});
return columnsByVariable;

}, {});

return columnsByVariables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('TasksListDatatableAdapter', () => {
const viewModel: TaskInstanceCloudListViewModel = {
...cloudModel,
variablesMap: {
columnDisplayName1: processVariable
columnId1: processVariable
}
};

Expand All @@ -48,7 +48,7 @@ describe('TasksListDatatableAdapter', () => {
};

const column: DataColumn<ProcessListDataColumnCustomData> = getDataColumnMock({
title: 'columnDisplayName1',
id: 'columnId1',
customData: {
assignedVariableDefinitionIds: ['variableDefinitionId'],
variableDefinitionsPayload: ['processKey/variableName'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ import { ProcessListDataColumnCustomData, PROCESS_LIST_CUSTOM_VARIABLE_COLUMN }
import { TaskInstanceCloudListViewModel } from '../models/task-cloud-view.model';

export class TasksListDatatableAdapter extends ObjectDataTableAdapter {
constructor(
data: TaskInstanceCloudListViewModel[],
schema: DataColumn<ProcessListDataColumnCustomData>[]
) {
constructor(data: TaskInstanceCloudListViewModel[], schema: DataColumn<ProcessListDataColumnCustomData>[]) {
super(data, schema);
}

getColumnType(row: DataRow, col: DataColumn<ProcessListDataColumnCustomData>): string {
if (col.customData?.columnType === PROCESS_LIST_CUSTOM_VARIABLE_COLUMN) {
const variableDisplayName = col.title;
const columnType = row.obj.variablesMap?.[variableDisplayName]?.type;
const columnType = row.obj.variablesMap?.[col.id]?.type;
return columnType ?? 'text';
}

Expand Down

0 comments on commit 74d558c

Please sign in to comment.