@zeedhi/teknisa-components-common 1.77.1 → 1.78.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 +329 -299
- package/coverage/coverage-final.json +6 -5
- package/coverage/lcov-report/index.html +27 -12
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +1 -1
- 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 +611 -555
- package/dist/tek-components-common.esm.js +52 -7
- package/dist/tek-components-common.umd.js +52 -7
- package/package.json +2 -2
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +1 -0
- package/tests/unit/components/tek-grid/grid.spec.ts +50 -0
- package/types/error/delete-rows-error.d.ts +6 -0
|
@@ -675,6 +675,18 @@ class ReportFilter {
|
|
|
675
675
|
}
|
|
676
676
|
}
|
|
677
677
|
|
|
678
|
+
/**
|
|
679
|
+
* Delete rows error
|
|
680
|
+
*/
|
|
681
|
+
class TekGridDeleteRowsError extends Error {
|
|
682
|
+
constructor() {
|
|
683
|
+
super('TekGrid can\'t automatically delete rows when selectAllPages property is true.'
|
|
684
|
+
+ ' You should delete them manually using the beforeDelete event and preventing'
|
|
685
|
+
+ ' the default execution');
|
|
686
|
+
this.name = 'TekGridDeleteRowsError';
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
678
690
|
class GridBase {
|
|
679
691
|
constructor(grid) {
|
|
680
692
|
this.exportConfigButtons = [];
|
|
@@ -925,6 +937,9 @@ class GridBase {
|
|
|
925
937
|
deleteButtonClick({ event }) {
|
|
926
938
|
this.grid.callEvent('beforeDelete', { component: this.grid, event });
|
|
927
939
|
if (!event.defaultPrevented) {
|
|
940
|
+
if (this.grid.selectAllPages) {
|
|
941
|
+
throw new TekGridDeleteRowsError();
|
|
942
|
+
}
|
|
928
943
|
this.grid.deleteRows();
|
|
929
944
|
this.grid.callEvent('afterDelete', { component: this.grid });
|
|
930
945
|
}
|
|
@@ -1598,10 +1613,18 @@ class GridController {
|
|
|
1598
1613
|
return !this.isEditing;
|
|
1599
1614
|
}
|
|
1600
1615
|
get disableDeleteButton() {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
&&
|
|
1616
|
+
if (this.grid.deleteButton === 'selection') {
|
|
1617
|
+
if (this.grid.selectAllPages) {
|
|
1618
|
+
const { allSelected, except } = this.grid.selectionState;
|
|
1619
|
+
return (allSelected && except.length === this.grid.datasource.total)
|
|
1620
|
+
|| (!allSelected && except.length === 0);
|
|
1621
|
+
}
|
|
1622
|
+
return this.grid.selectedRows.length === 0;
|
|
1623
|
+
}
|
|
1624
|
+
if (this.grid.deleteButton === 'currentRow') {
|
|
1625
|
+
return !this.grid.datasource.currentRow[this.grid.datasource.uniqueKey];
|
|
1626
|
+
}
|
|
1627
|
+
return false;
|
|
1605
1628
|
}
|
|
1606
1629
|
}
|
|
1607
1630
|
|
|
@@ -1967,13 +1990,35 @@ class TekMemoryDatasource extends MemoryDatasource {
|
|
|
1967
1990
|
* Updates filtered data
|
|
1968
1991
|
*/
|
|
1969
1992
|
updateFilteredData() {
|
|
1970
|
-
|
|
1993
|
+
// first apply filters (simple and dynamic)
|
|
1994
|
+
this.filteredData = Object.keys(this.filter).length
|
|
1995
|
+
? this.allData.filter((row) => this.getRowByFilter(row))
|
|
1996
|
+
: Array.from(this.allData);
|
|
1971
1997
|
if (this.dynamicFilter && Object.keys(this.dynamicFilter).length) {
|
|
1972
1998
|
this.filteredData = this.filteredData.filter((row) => this.getRowByDynamicFilter(row));
|
|
1973
1999
|
}
|
|
2000
|
+
const searchWithoutSearchJoin = (row) => {
|
|
2001
|
+
const searchRow = Object.assign({}, row);
|
|
2002
|
+
if (this.searchJoin) {
|
|
2003
|
+
// do not search on columns with searchJoin
|
|
2004
|
+
Object.keys(this.searchJoin).forEach((key) => delete searchRow[key]);
|
|
2005
|
+
}
|
|
2006
|
+
return this.getRowBySearch(searchRow);
|
|
2007
|
+
};
|
|
2008
|
+
// only after do the search
|
|
2009
|
+
const searchData = this.search
|
|
2010
|
+
? this.filteredData.filter(searchWithoutSearchJoin)
|
|
2011
|
+
: this.filteredData;
|
|
2012
|
+
let searchIds = searchData.map((row) => row[this.uniqueKey]);
|
|
1974
2013
|
if (this.searchJoin && Object.keys(this.searchJoin).length) {
|
|
1975
|
-
|
|
1976
|
-
|
|
2014
|
+
const searchJoinData = this.filteredData.filter((row) => this.getRowBySearchJoin(row));
|
|
2015
|
+
// get the ids from search and searchJoin
|
|
2016
|
+
searchIds = searchIds
|
|
2017
|
+
.concat(searchJoinData.map((row) => row[this.uniqueKey]))
|
|
2018
|
+
.sort();
|
|
2019
|
+
}
|
|
2020
|
+
// filter filteredData using searchIds
|
|
2021
|
+
this.filteredData = this.allData.filter((row) => searchIds.indexOf(row[this.uniqueKey]) !== -1);
|
|
1977
2022
|
}
|
|
1978
2023
|
getRowByDynamicFilter(row) {
|
|
1979
2024
|
let filtered;
|
|
@@ -680,6 +680,18 @@
|
|
|
680
680
|
}
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
+
/**
|
|
684
|
+
* Delete rows error
|
|
685
|
+
*/
|
|
686
|
+
class TekGridDeleteRowsError extends Error {
|
|
687
|
+
constructor() {
|
|
688
|
+
super('TekGrid can\'t automatically delete rows when selectAllPages property is true.'
|
|
689
|
+
+ ' You should delete them manually using the beforeDelete event and preventing'
|
|
690
|
+
+ ' the default execution');
|
|
691
|
+
this.name = 'TekGridDeleteRowsError';
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
683
695
|
class GridBase {
|
|
684
696
|
constructor(grid) {
|
|
685
697
|
this.exportConfigButtons = [];
|
|
@@ -930,6 +942,9 @@
|
|
|
930
942
|
deleteButtonClick({ event }) {
|
|
931
943
|
this.grid.callEvent('beforeDelete', { component: this.grid, event });
|
|
932
944
|
if (!event.defaultPrevented) {
|
|
945
|
+
if (this.grid.selectAllPages) {
|
|
946
|
+
throw new TekGridDeleteRowsError();
|
|
947
|
+
}
|
|
933
948
|
this.grid.deleteRows();
|
|
934
949
|
this.grid.callEvent('afterDelete', { component: this.grid });
|
|
935
950
|
}
|
|
@@ -1603,10 +1618,18 @@
|
|
|
1603
1618
|
return !this.isEditing;
|
|
1604
1619
|
}
|
|
1605
1620
|
get disableDeleteButton() {
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
&&
|
|
1621
|
+
if (this.grid.deleteButton === 'selection') {
|
|
1622
|
+
if (this.grid.selectAllPages) {
|
|
1623
|
+
const { allSelected, except } = this.grid.selectionState;
|
|
1624
|
+
return (allSelected && except.length === this.grid.datasource.total)
|
|
1625
|
+
|| (!allSelected && except.length === 0);
|
|
1626
|
+
}
|
|
1627
|
+
return this.grid.selectedRows.length === 0;
|
|
1628
|
+
}
|
|
1629
|
+
if (this.grid.deleteButton === 'currentRow') {
|
|
1630
|
+
return !this.grid.datasource.currentRow[this.grid.datasource.uniqueKey];
|
|
1631
|
+
}
|
|
1632
|
+
return false;
|
|
1610
1633
|
}
|
|
1611
1634
|
}
|
|
1612
1635
|
|
|
@@ -1972,13 +1995,35 @@
|
|
|
1972
1995
|
* Updates filtered data
|
|
1973
1996
|
*/
|
|
1974
1997
|
updateFilteredData() {
|
|
1975
|
-
|
|
1998
|
+
// first apply filters (simple and dynamic)
|
|
1999
|
+
this.filteredData = Object.keys(this.filter).length
|
|
2000
|
+
? this.allData.filter((row) => this.getRowByFilter(row))
|
|
2001
|
+
: Array.from(this.allData);
|
|
1976
2002
|
if (this.dynamicFilter && Object.keys(this.dynamicFilter).length) {
|
|
1977
2003
|
this.filteredData = this.filteredData.filter((row) => this.getRowByDynamicFilter(row));
|
|
1978
2004
|
}
|
|
2005
|
+
const searchWithoutSearchJoin = (row) => {
|
|
2006
|
+
const searchRow = Object.assign({}, row);
|
|
2007
|
+
if (this.searchJoin) {
|
|
2008
|
+
// do not search on columns with searchJoin
|
|
2009
|
+
Object.keys(this.searchJoin).forEach((key) => delete searchRow[key]);
|
|
2010
|
+
}
|
|
2011
|
+
return this.getRowBySearch(searchRow);
|
|
2012
|
+
};
|
|
2013
|
+
// only after do the search
|
|
2014
|
+
const searchData = this.search
|
|
2015
|
+
? this.filteredData.filter(searchWithoutSearchJoin)
|
|
2016
|
+
: this.filteredData;
|
|
2017
|
+
let searchIds = searchData.map((row) => row[this.uniqueKey]);
|
|
1979
2018
|
if (this.searchJoin && Object.keys(this.searchJoin).length) {
|
|
1980
|
-
|
|
1981
|
-
|
|
2019
|
+
const searchJoinData = this.filteredData.filter((row) => this.getRowBySearchJoin(row));
|
|
2020
|
+
// get the ids from search and searchJoin
|
|
2021
|
+
searchIds = searchIds
|
|
2022
|
+
.concat(searchJoinData.map((row) => row[this.uniqueKey]))
|
|
2023
|
+
.sort();
|
|
2024
|
+
}
|
|
2025
|
+
// filter filteredData using searchIds
|
|
2026
|
+
this.filteredData = this.allData.filter((row) => searchIds.indexOf(row[this.uniqueKey]) !== -1);
|
|
1982
2027
|
}
|
|
1983
2028
|
getRowByDynamicFilter(row) {
|
|
1984
2029
|
let filtered;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeedhi/teknisa-components-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.78.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": "84ea35b74e9d917e6ea29e012a01bc8a525f7e4f"
|
|
35
35
|
}
|
|
@@ -660,6 +660,56 @@ describe('TekGrid', () => {
|
|
|
660
660
|
}
|
|
661
661
|
spy.mockReset();
|
|
662
662
|
});
|
|
663
|
+
|
|
664
|
+
it('when deleteButton is clicked with selectAllPages, should throw', () => {
|
|
665
|
+
const instance = new TekGrid({
|
|
666
|
+
name: 'grid_deleteButtonClick1',
|
|
667
|
+
component: 'TekGrid',
|
|
668
|
+
deleteButton: 'selection',
|
|
669
|
+
selectAllPages: true,
|
|
670
|
+
datasource: {
|
|
671
|
+
data: [{ id: '1' }],
|
|
672
|
+
},
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
instance.onCreated();
|
|
676
|
+
const notEditingSpan = instance.toolbarSlot[2];
|
|
677
|
+
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 1) {
|
|
678
|
+
const deleteTooltip = notEditingSpan.children[1];
|
|
679
|
+
if (deleteTooltip && deleteTooltip.children && deleteTooltip.children.length > 0) {
|
|
680
|
+
const deleteButton = deleteTooltip.children[0];
|
|
681
|
+
const button = new Button(deleteButton);
|
|
682
|
+
const event = new Event('click');
|
|
683
|
+
expect(button.isVisible).toBeTruthy();
|
|
684
|
+
expect(button.disabled).toBeTruthy();
|
|
685
|
+
instance.selectAll(true);
|
|
686
|
+
expect(button.disabled).toBeFalsy();
|
|
687
|
+
expect(() => button.click(event, {} as HTMLElement)).toThrow();
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
describe('disableDeleteButton', () => {
|
|
694
|
+
it('should not disable deleteButton when deleteButton equals none', () => {
|
|
695
|
+
const instance = new TekGrid({
|
|
696
|
+
name: 'grid_deleteButtonClick1',
|
|
697
|
+
component: 'TekGrid',
|
|
698
|
+
deleteButton: 'none',
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
instance.onCreated();
|
|
702
|
+
const notEditingSpan = instance.toolbarSlot[2];
|
|
703
|
+
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 1) {
|
|
704
|
+
const deleteTooltip = notEditingSpan.children[1];
|
|
705
|
+
if (deleteTooltip && deleteTooltip.children && deleteTooltip.children.length > 0) {
|
|
706
|
+
const deleteButton = deleteTooltip.children[0];
|
|
707
|
+
const button = new Button(deleteButton);
|
|
708
|
+
expect(button.isVisible).toBeFalsy();
|
|
709
|
+
expect(button.disabled).toBeFalsy();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
});
|
|
663
713
|
});
|
|
664
714
|
|
|
665
715
|
describe('navigation', () => {
|