Skip to content

Commit

Permalink
fix(graphql): a column type of number should use EQ in GraphQL query
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Mar 7, 2018
1 parent a25147d commit a7da882
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventAggregator } from 'aurelia-event-aggregator';
import { inject } from 'aurelia-framework';
import { I18N } from 'aurelia-i18n';
import { mapOperatorType, mapOperatorByFilterType } from './utilities';
import { mapOperatorType, mapOperatorByFilterType, mapOperatorByFieldType } from './utilities';
import {
BackendService,
Column,
Expand All @@ -10,6 +10,7 @@ import {
CurrentFilter,
CurrentPagination,
CurrentSorter,
FieldType,
FilterChangedArgs,
GraphqlCursorPaginationOption,
GraphqlDatasetFilter,
Expand Down Expand Up @@ -374,6 +375,11 @@ export class GraphqlService implements BackendService {
operator = mapOperatorByFilterType(columnDef.filter.type || '');
}

// if we still don't have an operator then go with the mapping
if (!operator) {
operator = mapOperatorByFieldType(columnDef.type || FieldType.string);
}

searchByArray.push({
field: fieldName,
operator: mapOperatorType(operator),
Expand Down
39 changes: 39 additions & 0 deletions aurelia-slickgrid/src/aurelia-slickgrid/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,45 @@ export function mapOperatorType(operator: string): OperatorType {
return map;
}

/**
* Mapper for query operator by a Field Type
* For example a String should use "Contains" but a number should use "EQ" operator
* @param operator
* @returns string map
*/
export function mapOperatorByFieldType(fieldType: FieldType | string): OperatorType {
let map: OperatorType;

switch (fieldType) {
case FieldType.string:
case FieldType.unknown:
map = OperatorType.contains;
break;
case FieldType.float:
case FieldType.number:
case FieldType.dateIso:
case FieldType.date:
case FieldType.dateUtc:
case FieldType.dateTime:
case FieldType.dateTimeIso:
case FieldType.dateTimeIsoAmPm:
case FieldType.dateTimeIsoAM_PM:
case FieldType.dateUs:
case FieldType.dateUsShort:
case FieldType.dateTimeUs:
case FieldType.dateTimeUsAmPm:
case FieldType.dateTimeUsAM_PM:
case FieldType.dateTimeUsShort:
case FieldType.dateTimeUsShortAmPm:
case FieldType.dateTimeUsShortAM_PM:
default:
map = OperatorType.equal;
break;
}

return map;
}

/**
* Mapper for query operator by a Filter Type
* For example a multiple-select typically uses 'IN' operator
Expand Down
2 changes: 1 addition & 1 deletion aurelia-slickgrid/src/examples/slickgrid/example6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Example6 {
}
},
{ id: 'billing.address.street', name: 'Billing Address Street', field: 'billing.address.street', headerKey: 'BILLING.ADDRESS.STREET', filterable: true, sortable: true },
{ id: 'billing.address.zip', name: 'Billing Address Zip', field: 'billing.address.zip', headerKey: 'BILLING.ADDRESS.ZIP', filterable: true, sortable: true },
{ id: 'billing.address.zip', name: 'Billing Address Zip', field: 'billing.address.zip', headerKey: 'BILLING.ADDRESS.ZIP', filterable: true, sortable: true, type: FieldType.number },
];

this.gridOptions = {
Expand Down
2 changes: 1 addition & 1 deletion client-cli/src/examples/slickgrid/example6.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Example6 {
}
},
{ id: 'billing.address.street', name: 'Billing Address Street', field: 'billing.address.street', headerKey: 'BILLING.ADDRESS.STREET', filterable: true, sortable: true },
{ id: 'billing.address.zip', name: 'Billing Address Zip', field: 'billing.address.zip', headerKey: 'BILLING.ADDRESS.ZIP', filterable: true, sortable: true }
{ id: 'billing.address.zip', name: 'Billing Address Zip', field: 'billing.address.zip', headerKey: 'BILLING.ADDRESS.ZIP', filterable: true, sortable: true, type: FieldType.number }
];

this.gridOptions = {
Expand Down
2 changes: 1 addition & 1 deletion doc/github-demo/src/examples/slickgrid/example6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Example6 {
}
},
{ id: 'billing.address.street', name: 'Billing Address Street', field: 'billing.address.street', headerKey: 'BILLING.ADDRESS.STREET', filterable: true, sortable: true },
{ id: 'billing.address.zip', name: 'Billing Address Zip', field: 'billing.address.zip', headerKey: 'BILLING.ADDRESS.ZIP', filterable: true, sortable: true },
{ id: 'billing.address.zip', name: 'Billing Address Zip', field: 'billing.address.zip', headerKey: 'BILLING.ADDRESS.ZIP', filterable: true, sortable: true, type: FieldType.number },
];

this.gridOptions = {
Expand Down

0 comments on commit a7da882

Please sign in to comment.