-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [AAE-15815] Create Data Table widget * [AAE-15815] Add check for corectness of column schema * fix mock name typo * improve method name * fix testing module config
- Loading branch information
Showing
11 changed files
with
592 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...rvices-cloud/src/lib/form/components/widgets/data-table/data-table-adapter.widget.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*! | ||
* @license | ||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { WidgetDataTableAdapter } from './data-table-adapter.widget'; | ||
import { | ||
mockCountriesData, | ||
mockCountriesIncorrectData, | ||
mockInvalidSchemaDefinition, | ||
mockSchemaDefinition, | ||
mockSchemaDefinitionWithDifferentTypes | ||
} from '../../../mocks/data-table-widget.mock'; | ||
import { ObjectDataRow } from '@alfresco/adf-core'; | ||
|
||
describe('WidgetDataTableAdapter', () => { | ||
let widgetDataTableAdapter: WidgetDataTableAdapter; | ||
|
||
beforeEach(() => { | ||
widgetDataTableAdapter = new WidgetDataTableAdapter(mockCountriesData, mockSchemaDefinition); | ||
}); | ||
|
||
it('should set columns type to "text" during initialization', () => { | ||
widgetDataTableAdapter = new WidgetDataTableAdapter(mockCountriesData, mockSchemaDefinitionWithDifferentTypes); | ||
|
||
widgetDataTableAdapter.getColumns().forEach(column => | ||
expect(column.type).toBe('text') | ||
); | ||
}); | ||
|
||
it('should return rows if all columns are linked to data', () => { | ||
const rows = widgetDataTableAdapter.getRows(); | ||
|
||
expect(rows).toEqual([ | ||
new ObjectDataRow({ id: 'IT', name: 'Italy' }), | ||
new ObjectDataRow({ id: 'PL', name: 'Poland' }), | ||
new ObjectDataRow({ id: 'UK', name: 'United Kingdom' }) | ||
]); | ||
}); | ||
|
||
it('should return an empty array if not all columns are linked to data', () => { | ||
widgetDataTableAdapter = new WidgetDataTableAdapter(mockCountriesIncorrectData, mockSchemaDefinition); | ||
const rows = widgetDataTableAdapter.getRows(); | ||
const isDataSourceValid = widgetDataTableAdapter.isDataSourceValid(); | ||
|
||
expect(rows).toEqual([]); | ||
expect(isDataSourceValid).toBeFalse(); | ||
}); | ||
|
||
it('should return an empty array if columns have invalid structure', () => { | ||
widgetDataTableAdapter = new WidgetDataTableAdapter(mockCountriesData, mockInvalidSchemaDefinition); | ||
const rows = widgetDataTableAdapter.getRows(); | ||
const isDataSourceValid = widgetDataTableAdapter.isDataSourceValid(); | ||
|
||
expect(rows).toEqual([]); | ||
expect(isDataSourceValid).toBeFalse(); | ||
}); | ||
|
||
it('should return true for isDataSourceValid() if rows have data and valid columns schema', () => { | ||
const isValid = widgetDataTableAdapter.isDataSourceValid(); | ||
|
||
expect(isValid).toBeTrue(); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
...ss-services-cloud/src/lib/form/components/widgets/data-table/data-table-adapter.widget.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*! | ||
* @license | ||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
ObjectDataTableAdapter, | ||
DataColumn, | ||
DataRow | ||
} from '@alfresco/adf-core'; | ||
|
||
export class WidgetDataTableAdapter extends ObjectDataTableAdapter { | ||
|
||
private rows: DataRow[]; | ||
private columns: DataColumn[]; | ||
|
||
constructor(data?: any[], schema?: DataColumn[]) { | ||
super(data, schema); | ||
this.rows = super.getRows(); | ||
this.columns = super.getColumns(); | ||
|
||
this.setColumnsTypeToText(); | ||
} | ||
|
||
getRows(): DataRow[] { | ||
if (this.isDataSourceValid()) { | ||
return this.rows; | ||
} | ||
|
||
return []; | ||
} | ||
|
||
isDataSourceValid(): boolean { | ||
return this.hasAllColumnsLinkedToData() && this.hasAllMandatoryColumnPropertiesHaveValues(); | ||
} | ||
|
||
private hasAllMandatoryColumnPropertiesHaveValues(): boolean { | ||
return this.columns.every(column => !!column.key); | ||
} | ||
|
||
private hasAllColumnsLinkedToData(): boolean { | ||
const availableColumnKeys: string[] = this.columns.map(column => column.key); | ||
|
||
return availableColumnKeys.every(columnKey => this.rows.some(row => Object.keys(row.obj).includes(columnKey))); | ||
} | ||
|
||
private setColumnsTypeToText(): void { | ||
super.setColumns(this.columns.map(column => ({ ...column, type: 'text' }))); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="adf-data-table-widget-container"> | ||
<div class="adf-data-table-widget-label"> | ||
<label | ||
class="adf-label" | ||
[class.adf-left-label]="field.leftLabels" | ||
[attr.for]="field.id"> | ||
{{field.name | translate }} | ||
</label> | ||
</div> | ||
|
||
<ng-container *ngIf="!previewState; else previewTemplate"> | ||
<adf-datatable data-automation-id="adf-data-table-widget" [data]="dataSource"></adf-datatable> | ||
|
||
<error-widget *ngIf="dataTableLoadFailed" | ||
class="adf-data-table-widget-failed-message" | ||
required="{{ 'FORM.FIELD.DATA_TABLE_LOAD_FAILED' | translate }}"></error-widget> | ||
</ng-container> | ||
|
||
<ng-template #previewTemplate> | ||
<adf-datatable data-automation-id="adf-data-table-widget-preview"></adf-datatable> | ||
</ng-template> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.adf-data-table-widget-failed-message { | ||
margin: 10px; | ||
} |
Oops, something went wrong.