@zeedhi/teknisa-components-common 1.69.0 → 1.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/clover.xml +327 -314
- package/coverage/coverage-final.json +7 -7
- package/coverage/lcov-report/index.html +11 -11
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +1 -1
- package/coverage/lcov.info +578 -558
- package/dist/tek-components-common.esm.js +32 -7
- package/dist/tek-components-common.umd.js +32 -7
- package/package.json +2 -2
- package/tests/unit/components/tek-grid/grid.spec.ts +41 -1
- package/types/components/tek-grid/interfaces.d.ts +1 -0
|
@@ -887,7 +887,10 @@ class GridBase {
|
|
|
887
887
|
this.grid.callEvent('afterDelete', { component: this.grid });
|
|
888
888
|
}
|
|
889
889
|
}
|
|
890
|
-
reloadGrid() {
|
|
890
|
+
reloadGrid({ event }) {
|
|
891
|
+
this.grid.callEvent('beforeReload', { component: this.grid, event });
|
|
892
|
+
if (event && event.defaultPrevented)
|
|
893
|
+
return;
|
|
891
894
|
this.grid.reload();
|
|
892
895
|
}
|
|
893
896
|
saveChanges({ event }) {
|
|
@@ -1026,6 +1029,9 @@ class GridBase {
|
|
|
1026
1029
|
};
|
|
1027
1030
|
this.filterModal = ModalService.create(filterModalDef);
|
|
1028
1031
|
}
|
|
1032
|
+
else {
|
|
1033
|
+
this.loadFilterValues({ component: Metadata.getInstance(`${this.grid.name}-filter-form`) });
|
|
1034
|
+
}
|
|
1029
1035
|
this.filterModal.show();
|
|
1030
1036
|
}
|
|
1031
1037
|
hideFilterModal() {
|
|
@@ -1083,6 +1089,7 @@ class GridBase {
|
|
|
1083
1089
|
}
|
|
1084
1090
|
}
|
|
1085
1091
|
loadFilterValues({ component }) {
|
|
1092
|
+
const changedCompNames = [];
|
|
1086
1093
|
const { datasource } = this.grid;
|
|
1087
1094
|
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
1088
1095
|
const { dynamicFilter } = datasource;
|
|
@@ -1092,6 +1099,7 @@ class GridBase {
|
|
|
1092
1099
|
const relation = filterItem.relation || 'AND';
|
|
1093
1100
|
const operation = filterItem.operation || 'CONTAINS';
|
|
1094
1101
|
const compName = `${this.grid.name}-filter-${relation}-${operation}-${column}-${index}`;
|
|
1102
|
+
changedCompNames.push(compName);
|
|
1095
1103
|
component.value[compName] = filterItem.value;
|
|
1096
1104
|
let helperValue = '';
|
|
1097
1105
|
const columnObj = this.grid.getColumn(column);
|
|
@@ -1120,10 +1128,17 @@ class GridBase {
|
|
|
1120
1128
|
const { filter } = datasource;
|
|
1121
1129
|
Object.keys(filter).forEach((item) => {
|
|
1122
1130
|
if (filter[item]) {
|
|
1123
|
-
|
|
1131
|
+
const compName = `${this.grid.name}-filter-AND-CONTAINS-${item}-0`;
|
|
1132
|
+
changedCompNames.push(compName);
|
|
1133
|
+
component.value[compName] = filter[item];
|
|
1124
1134
|
}
|
|
1125
1135
|
});
|
|
1126
1136
|
}
|
|
1137
|
+
Object.keys(component.value).forEach((compName) => {
|
|
1138
|
+
if (changedCompNames.indexOf(compName) === -1) {
|
|
1139
|
+
component.value[compName] = null;
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1127
1142
|
}
|
|
1128
1143
|
applyFilter({ event }) {
|
|
1129
1144
|
const filterForm = Metadata.getInstance(`${this.grid.name}-filter-form`);
|
|
@@ -2916,7 +2931,9 @@ class TekGridLayoutOptions extends ComponentRender {
|
|
|
2916
2931
|
}
|
|
2917
2932
|
getParentGrid() {
|
|
2918
2933
|
let { parent } = this;
|
|
2919
|
-
while (parent
|
|
2934
|
+
while (parent
|
|
2935
|
+
&& !(parent.constructor === Grid
|
|
2936
|
+
|| parent.constructor.prototype instanceof Grid)) {
|
|
2920
2937
|
parent = parent.parent;
|
|
2921
2938
|
}
|
|
2922
2939
|
return parent;
|
|
@@ -2938,6 +2955,7 @@ class TekGridLayoutOptions extends ComponentRender {
|
|
|
2938
2955
|
isVisible: column.isVisible,
|
|
2939
2956
|
minWidth: column.minWidth,
|
|
2940
2957
|
maxWidth: column.maxWidth,
|
|
2958
|
+
width: column.width,
|
|
2941
2959
|
fixed: column.fixed,
|
|
2942
2960
|
grouped: column.grouped,
|
|
2943
2961
|
groupOpened: column.groupOpened,
|
|
@@ -2953,7 +2971,9 @@ class TekGridLayoutOptions extends ComponentRender {
|
|
|
2953
2971
|
const route = Config.loadGridLayoutsEndPoint;
|
|
2954
2972
|
const response = yield Http.get(`${route}?id=${this.grid.name}`);
|
|
2955
2973
|
const responseData = response.data.data;
|
|
2956
|
-
layoutsInfo = responseData.length && responseData[0]
|
|
2974
|
+
layoutsInfo = responseData.length && responseData[0]
|
|
2975
|
+
? responseData[0].layouts
|
|
2976
|
+
: responseData.layouts || {};
|
|
2957
2977
|
}
|
|
2958
2978
|
else {
|
|
2959
2979
|
layoutsInfo = JSON.parse(localStorage.getItem(this.grid.name) || '{}');
|
|
@@ -2989,8 +3009,9 @@ class TekGridLayoutOptions extends ComponentRender {
|
|
|
2989
3009
|
}
|
|
2990
3010
|
applyLayout(name, save = true) {
|
|
2991
3011
|
this.currentLayoutName = name;
|
|
3012
|
+
const layoutSelected = this.layouts[name];
|
|
2992
3013
|
if (this.viewApplyLayout) {
|
|
2993
|
-
this.viewApplyLayout(
|
|
3014
|
+
this.viewApplyLayout(layoutSelected);
|
|
2994
3015
|
}
|
|
2995
3016
|
if (save) {
|
|
2996
3017
|
this.saveLayouts();
|
|
@@ -3039,7 +3060,9 @@ class TekGridLayoutOptions extends ComponentRender {
|
|
|
3039
3060
|
if (layout.columns) {
|
|
3040
3061
|
this.originalColumnProps = layout.columns.map((column) => {
|
|
3041
3062
|
const originalColumnIdx = this.originalColumnProps.findIndex((item) => item.name === column.name);
|
|
3042
|
-
const originalColumn = originalColumnIdx !== -1
|
|
3063
|
+
const originalColumn = originalColumnIdx !== -1
|
|
3064
|
+
? this.originalColumnProps[originalColumnIdx]
|
|
3065
|
+
: {};
|
|
3043
3066
|
return Object.assign(Object.assign({}, originalColumn), column);
|
|
3044
3067
|
});
|
|
3045
3068
|
}
|
|
@@ -3052,12 +3075,14 @@ class TekGridLayoutOptions extends ComponentRender {
|
|
|
3052
3075
|
layout.columns = layout.columns || [];
|
|
3053
3076
|
const layoutColumnNames = layout.columns.map((layoutColumn) => layoutColumn.name);
|
|
3054
3077
|
this.grid.columns.forEach((gridColumn) => {
|
|
3055
|
-
if (!hasLayoutColumns
|
|
3078
|
+
if (!hasLayoutColumns
|
|
3079
|
+
|| layoutColumnNames.indexOf(gridColumn.name) === -1) {
|
|
3056
3080
|
layout.columns.push({
|
|
3057
3081
|
name: gridColumn.name,
|
|
3058
3082
|
label: gridColumn.label,
|
|
3059
3083
|
align: gridColumn.align,
|
|
3060
3084
|
isVisible: !hasLayoutColumns && gridColumn.isVisible,
|
|
3085
|
+
width: gridColumn.width,
|
|
3061
3086
|
minWidth: gridColumn.minWidth,
|
|
3062
3087
|
maxWidth: gridColumn.maxWidth,
|
|
3063
3088
|
fixed: gridColumn.fixed,
|
|
@@ -892,7 +892,10 @@
|
|
|
892
892
|
this.grid.callEvent('afterDelete', { component: this.grid });
|
|
893
893
|
}
|
|
894
894
|
}
|
|
895
|
-
reloadGrid() {
|
|
895
|
+
reloadGrid({ event }) {
|
|
896
|
+
this.grid.callEvent('beforeReload', { component: this.grid, event });
|
|
897
|
+
if (event && event.defaultPrevented)
|
|
898
|
+
return;
|
|
896
899
|
this.grid.reload();
|
|
897
900
|
}
|
|
898
901
|
saveChanges({ event }) {
|
|
@@ -1031,6 +1034,9 @@
|
|
|
1031
1034
|
};
|
|
1032
1035
|
this.filterModal = common.ModalService.create(filterModalDef);
|
|
1033
1036
|
}
|
|
1037
|
+
else {
|
|
1038
|
+
this.loadFilterValues({ component: core.Metadata.getInstance(`${this.grid.name}-filter-form`) });
|
|
1039
|
+
}
|
|
1034
1040
|
this.filterModal.show();
|
|
1035
1041
|
}
|
|
1036
1042
|
hideFilterModal() {
|
|
@@ -1088,6 +1094,7 @@
|
|
|
1088
1094
|
}
|
|
1089
1095
|
}
|
|
1090
1096
|
loadFilterValues({ component }) {
|
|
1097
|
+
const changedCompNames = [];
|
|
1091
1098
|
const { datasource } = this.grid;
|
|
1092
1099
|
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
1093
1100
|
const { dynamicFilter } = datasource;
|
|
@@ -1097,6 +1104,7 @@
|
|
|
1097
1104
|
const relation = filterItem.relation || 'AND';
|
|
1098
1105
|
const operation = filterItem.operation || 'CONTAINS';
|
|
1099
1106
|
const compName = `${this.grid.name}-filter-${relation}-${operation}-${column}-${index}`;
|
|
1107
|
+
changedCompNames.push(compName);
|
|
1100
1108
|
component.value[compName] = filterItem.value;
|
|
1101
1109
|
let helperValue = '';
|
|
1102
1110
|
const columnObj = this.grid.getColumn(column);
|
|
@@ -1125,10 +1133,17 @@
|
|
|
1125
1133
|
const { filter } = datasource;
|
|
1126
1134
|
Object.keys(filter).forEach((item) => {
|
|
1127
1135
|
if (filter[item]) {
|
|
1128
|
-
|
|
1136
|
+
const compName = `${this.grid.name}-filter-AND-CONTAINS-${item}-0`;
|
|
1137
|
+
changedCompNames.push(compName);
|
|
1138
|
+
component.value[compName] = filter[item];
|
|
1129
1139
|
}
|
|
1130
1140
|
});
|
|
1131
1141
|
}
|
|
1142
|
+
Object.keys(component.value).forEach((compName) => {
|
|
1143
|
+
if (changedCompNames.indexOf(compName) === -1) {
|
|
1144
|
+
component.value[compName] = null;
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1132
1147
|
}
|
|
1133
1148
|
applyFilter({ event }) {
|
|
1134
1149
|
const filterForm = core.Metadata.getInstance(`${this.grid.name}-filter-form`);
|
|
@@ -2921,7 +2936,9 @@
|
|
|
2921
2936
|
}
|
|
2922
2937
|
getParentGrid() {
|
|
2923
2938
|
let { parent } = this;
|
|
2924
|
-
while (parent
|
|
2939
|
+
while (parent
|
|
2940
|
+
&& !(parent.constructor === common.Grid
|
|
2941
|
+
|| parent.constructor.prototype instanceof common.Grid)) {
|
|
2925
2942
|
parent = parent.parent;
|
|
2926
2943
|
}
|
|
2927
2944
|
return parent;
|
|
@@ -2943,6 +2960,7 @@
|
|
|
2943
2960
|
isVisible: column.isVisible,
|
|
2944
2961
|
minWidth: column.minWidth,
|
|
2945
2962
|
maxWidth: column.maxWidth,
|
|
2963
|
+
width: column.width,
|
|
2946
2964
|
fixed: column.fixed,
|
|
2947
2965
|
grouped: column.grouped,
|
|
2948
2966
|
groupOpened: column.groupOpened,
|
|
@@ -2958,7 +2976,9 @@
|
|
|
2958
2976
|
const route = core.Config.loadGridLayoutsEndPoint;
|
|
2959
2977
|
const response = yield core.Http.get(`${route}?id=${this.grid.name}`);
|
|
2960
2978
|
const responseData = response.data.data;
|
|
2961
|
-
layoutsInfo = responseData.length && responseData[0]
|
|
2979
|
+
layoutsInfo = responseData.length && responseData[0]
|
|
2980
|
+
? responseData[0].layouts
|
|
2981
|
+
: responseData.layouts || {};
|
|
2962
2982
|
}
|
|
2963
2983
|
else {
|
|
2964
2984
|
layoutsInfo = JSON.parse(localStorage.getItem(this.grid.name) || '{}');
|
|
@@ -2994,8 +3014,9 @@
|
|
|
2994
3014
|
}
|
|
2995
3015
|
applyLayout(name, save = true) {
|
|
2996
3016
|
this.currentLayoutName = name;
|
|
3017
|
+
const layoutSelected = this.layouts[name];
|
|
2997
3018
|
if (this.viewApplyLayout) {
|
|
2998
|
-
this.viewApplyLayout(
|
|
3019
|
+
this.viewApplyLayout(layoutSelected);
|
|
2999
3020
|
}
|
|
3000
3021
|
if (save) {
|
|
3001
3022
|
this.saveLayouts();
|
|
@@ -3044,7 +3065,9 @@
|
|
|
3044
3065
|
if (layout.columns) {
|
|
3045
3066
|
this.originalColumnProps = layout.columns.map((column) => {
|
|
3046
3067
|
const originalColumnIdx = this.originalColumnProps.findIndex((item) => item.name === column.name);
|
|
3047
|
-
const originalColumn = originalColumnIdx !== -1
|
|
3068
|
+
const originalColumn = originalColumnIdx !== -1
|
|
3069
|
+
? this.originalColumnProps[originalColumnIdx]
|
|
3070
|
+
: {};
|
|
3048
3071
|
return Object.assign(Object.assign({}, originalColumn), column);
|
|
3049
3072
|
});
|
|
3050
3073
|
}
|
|
@@ -3057,12 +3080,14 @@
|
|
|
3057
3080
|
layout.columns = layout.columns || [];
|
|
3058
3081
|
const layoutColumnNames = layout.columns.map((layoutColumn) => layoutColumn.name);
|
|
3059
3082
|
this.grid.columns.forEach((gridColumn) => {
|
|
3060
|
-
if (!hasLayoutColumns
|
|
3083
|
+
if (!hasLayoutColumns
|
|
3084
|
+
|| layoutColumnNames.indexOf(gridColumn.name) === -1) {
|
|
3061
3085
|
layout.columns.push({
|
|
3062
3086
|
name: gridColumn.name,
|
|
3063
3087
|
label: gridColumn.label,
|
|
3064
3088
|
align: gridColumn.align,
|
|
3065
3089
|
isVisible: !hasLayoutColumns && gridColumn.isVisible,
|
|
3090
|
+
width: gridColumn.width,
|
|
3066
3091
|
minWidth: gridColumn.minWidth,
|
|
3067
3092
|
maxWidth: gridColumn.maxWidth,
|
|
3068
3093
|
fixed: gridColumn.fixed,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeedhi/teknisa-components-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.71.0",
|
|
4
4
|
"description": "Teknisa Components Common",
|
|
5
5
|
"author": "Zeedhi <zeedhi@teknisa.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@zeedhi/core": "*"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "5d07dd32186fce8f874881da6b7fb8327c7b462e"
|
|
35
35
|
}
|
|
@@ -976,6 +976,32 @@ describe('TekGrid', () => {
|
|
|
976
976
|
}
|
|
977
977
|
spy.mockReset();
|
|
978
978
|
});
|
|
979
|
+
|
|
980
|
+
it('should call beforeReload event', () => {
|
|
981
|
+
const beforeSpy = jest.fn();
|
|
982
|
+
const instance = new TekGrid({
|
|
983
|
+
name: 'grid_reloadClick2',
|
|
984
|
+
component: 'TekGrid',
|
|
985
|
+
events: {
|
|
986
|
+
beforeReload: beforeSpy,
|
|
987
|
+
},
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
const spy = jest.spyOn(instance, 'reload');
|
|
991
|
+
instance.onCreated();
|
|
992
|
+
const notEditingSpan = instance.toolbarSlot[2];
|
|
993
|
+
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 3) {
|
|
994
|
+
const reloadTooltip = notEditingSpan.children[3];
|
|
995
|
+
if (reloadTooltip && reloadTooltip.children && reloadTooltip.children.length > 0) {
|
|
996
|
+
const reloadButton = reloadTooltip.children[0];
|
|
997
|
+
const button = new Button(reloadButton);
|
|
998
|
+
setClick(button, { defaultPrevented: true });
|
|
999
|
+
expect(beforeSpy).toBeCalled();
|
|
1000
|
+
expect(spy).not.toBeCalled();
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
spy.mockReset();
|
|
1004
|
+
});
|
|
979
1005
|
});
|
|
980
1006
|
|
|
981
1007
|
describe('grouping', () => {
|
|
@@ -1642,7 +1668,13 @@ describe('TekGrid', () => {
|
|
|
1642
1668
|
component: 'TekGrid',
|
|
1643
1669
|
});
|
|
1644
1670
|
|
|
1671
|
+
const formInstance = new Form({
|
|
1672
|
+
name: 'form',
|
|
1673
|
+
component: 'ZdForm',
|
|
1674
|
+
});
|
|
1675
|
+
|
|
1645
1676
|
const spy = jest.spyOn(ModalService, 'create');
|
|
1677
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formInstance);
|
|
1646
1678
|
instance.onCreated();
|
|
1647
1679
|
|
|
1648
1680
|
const button = clickOnFilterButton(instance);
|
|
@@ -1651,7 +1683,9 @@ describe('TekGrid', () => {
|
|
|
1651
1683
|
expect(spy).toBeCalledTimes(1);
|
|
1652
1684
|
expect(button.isVisible).toBeFalsy();
|
|
1653
1685
|
(instance as any).gridBase.hideFilterModal();
|
|
1686
|
+
|
|
1654
1687
|
spy.mockReset();
|
|
1688
|
+
spyMetadata.mockReset();
|
|
1655
1689
|
});
|
|
1656
1690
|
|
|
1657
1691
|
it('should call events', () => {
|
|
@@ -1981,7 +2015,6 @@ describe('TekGrid', () => {
|
|
|
1981
2015
|
type: 'tek-rest',
|
|
1982
2016
|
lazyLoad: true,
|
|
1983
2017
|
dynamicFilter: {
|
|
1984
|
-
id: [],
|
|
1985
2018
|
name: [
|
|
1986
2019
|
{
|
|
1987
2020
|
operation: 'NOT_EQUALS',
|
|
@@ -2039,10 +2072,17 @@ describe('TekGrid', () => {
|
|
|
2039
2072
|
|
|
2040
2073
|
expect(form.name).toBe('grid_filterClick9-filter-form');
|
|
2041
2074
|
const formObject = new Form(form);
|
|
2075
|
+
formObject.value = {
|
|
2076
|
+
'grid_filterClick9-filter-AND_CONTAINS-id-0': null,
|
|
2077
|
+
'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': null,
|
|
2078
|
+
'grid_filterClick9-filter-AND-CONTAINS-phone-0': null,
|
|
2079
|
+
'grid_filterClick9-filter-OR-IN-date-0': null,
|
|
2080
|
+
};
|
|
2042
2081
|
const dateObject = new Date({ name: 'date', component: 'ZdDate' });
|
|
2043
2082
|
const spyMetadata = jest.spyOn(Metadata, 'getInstances').mockImplementation(() => [dateObject]);
|
|
2044
2083
|
formObject.onMounted({} as HTMLElement);
|
|
2045
2084
|
expect(formObject.value).toEqual({
|
|
2085
|
+
'grid_filterClick9-filter-AND_CONTAINS-id-0': null,
|
|
2046
2086
|
'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
2047
2087
|
'grid_filterClick9-filter-AND-CONTAINS-phone-0': '9',
|
|
2048
2088
|
'grid_filterClick9-filter-OR-IN-date-0': ['2021-11-12', '2021-12-12'],
|
|
@@ -21,6 +21,7 @@ export interface ITekGridEvents<T = IEventParam<any> | ITekGridLayoutEventParams
|
|
|
21
21
|
groupSelect?: EventDef<T>;
|
|
22
22
|
groupUnselect?: EventDef<T>;
|
|
23
23
|
beforeOpenReport?: EventDef<T, IBeforeReportEvent>;
|
|
24
|
+
beforeReload?: EventDef<T>;
|
|
24
25
|
[key: string]: any;
|
|
25
26
|
}
|
|
26
27
|
export declare type ITekGridLayoutOptionsEvent<T> = (event: T) => Promise<any>;
|