ocket8888 commented on code in PR #7074:
URL: https://github.com/apache/trafficcontrol/pull/7074#discussion_r983945604
##########
traffic_portal/app/src/common/modules/table/agGrid/CommonGridController.js:
##########
@@ -301,6 +301,34 @@ let CommonGridController = function ($scope, $document,
$state, userModel, dateU
this.columns[i].tooltipValueGetter =
dateCellFormatterUTC;
this.columns[i].valueFormatter =
dateCellFormatterUTC;
}
+ } else if (this.columns[i].filter ===
'arrayTextColumnFilter') {
+ this.columns[i].filter = 'agTextColumnFilter'
+ this.columns[i].filterParams = {
+ textCustomComparator: (filter, value,
filterText) => {
+ const filterTextLowerCase =
filterText.toLowerCase();
+ const valueLowerCase =
value.toString().toLowerCase();
+ const profileNameValue =
valueLowerCase.split(",");
+ switch (filter) {
+ case 'contains':
+ return
valueLowerCase.indexOf(filterTextLowerCase) >= 0;
+ case 'notContains':
+ return
valueLowerCase.indexOf(filterTextLowerCase) === -1;
+ case 'equals':
+ return
profileNameValue.includes(filterTextLowerCase);
+ case 'notEqual':
+ return
!profileNameValue.includes(filterTextLowerCase);
+ case 'startsWith':
+ return
valueLowerCase.indexOf(filterTextLowerCase) === 0;
+ case 'endsWith':
+ var index =
valueLowerCase.lastIndexOf(filterTextLowerCase);
+ return index >=
0 && index === (valueLowerCase.length - filterTextLowerCase.length);
Review Comment:
Nit but this is built into Javascript as
[`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith),
so you don't need to mess with numeric indexes and such.
Also though, please don't use `var`
##########
traffic_portal/app/src/common/modules/table/agGrid/CommonGridController.js:
##########
@@ -301,6 +301,34 @@ let CommonGridController = function ($scope, $document,
$state, userModel, dateU
this.columns[i].tooltipValueGetter =
dateCellFormatterUTC;
this.columns[i].valueFormatter =
dateCellFormatterUTC;
}
+ } else if (this.columns[i].filter ===
'arrayTextColumnFilter') {
+ this.columns[i].filter = 'agTextColumnFilter'
+ this.columns[i].filterParams = {
+ textCustomComparator: (filter, value,
filterText) => {
+ const filterTextLowerCase =
filterText.toLowerCase();
+ const valueLowerCase =
value.toString().toLowerCase();
+ const profileNameValue =
valueLowerCase.split(",");
+ switch (filter) {
+ case 'contains':
+ return
valueLowerCase.indexOf(filterTextLowerCase) >= 0;
+ case 'notContains':
+ return
valueLowerCase.indexOf(filterTextLowerCase) === -1;
Review Comment:
FWIW, there's a
[`String.prototype.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
just like there is for arrays, so you could do this same way you did 'equals'
and 'notEqual'.
##########
traffic_portal/app/src/common/modules/table/agGrid/CommonGridController.js:
##########
@@ -301,6 +301,34 @@ let CommonGridController = function ($scope, $document,
$state, userModel, dateU
this.columns[i].tooltipValueGetter =
dateCellFormatterUTC;
this.columns[i].valueFormatter =
dateCellFormatterUTC;
}
+ } else if (this.columns[i].filter ===
'arrayTextColumnFilter') {
+ this.columns[i].filter = 'agTextColumnFilter'
+ this.columns[i].filterParams = {
+ textCustomComparator: (filter, value,
filterText) => {
+ const filterTextLowerCase =
filterText.toLowerCase();
+ const valueLowerCase =
value.toString().toLowerCase();
+ const profileNameValue =
valueLowerCase.split(",");
+ switch (filter) {
+ case 'contains':
+ return
valueLowerCase.indexOf(filterTextLowerCase) >= 0;
+ case 'notContains':
+ return
valueLowerCase.indexOf(filterTextLowerCase) === -1;
+ case 'equals':
+ return
profileNameValue.includes(filterTextLowerCase);
+ case 'notEqual':
+ return
!profileNameValue.includes(filterTextLowerCase);
+ case 'startsWith':
+ return
valueLowerCase.indexOf(filterTextLowerCase) === 0;
Review Comment:
This is also built into Javascript, as
[`String.prototype.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]