|
|
@@ -7,13 +7,14 @@ import {
|
|
|
DataService,
|
|
|
GetOrderList,
|
|
|
LocalStorageService,
|
|
|
+ LogicalOperator,
|
|
|
OrderListOptions,
|
|
|
ServerConfigService,
|
|
|
SortOrder,
|
|
|
} from '@vendure/admin-ui/core';
|
|
|
import { Order } from '@vendure/common/lib/generated-types';
|
|
|
import { merge, Observable } from 'rxjs';
|
|
|
-import { debounceTime, distinctUntilChanged, filter, map, skip, takeUntil, tap } from 'rxjs/operators';
|
|
|
+import { debounceTime, distinctUntilChanged, filter, map, takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
interface OrderFilterConfig {
|
|
|
active?: boolean;
|
|
|
@@ -34,7 +35,9 @@ interface FilterPreset {
|
|
|
})
|
|
|
export class OrderListComponent
|
|
|
extends BaseListComponent<GetOrderList.Query, GetOrderList.Items>
|
|
|
- implements OnInit {
|
|
|
+ implements OnInit
|
|
|
+{
|
|
|
+ searchControl = new FormControl('');
|
|
|
searchOrderCodeControl = new FormControl('');
|
|
|
searchLastNameControl = new FormControl('');
|
|
|
customFilterForm: FormGroup;
|
|
|
@@ -93,8 +96,7 @@ export class OrderListComponent
|
|
|
this.createQueryOptions(
|
|
|
skip,
|
|
|
take,
|
|
|
- this.searchOrderCodeControl.value,
|
|
|
- this.searchLastNameControl.value,
|
|
|
+ this.searchControl.value,
|
|
|
this.route.snapshot.queryParamMap.get('filter') || 'open',
|
|
|
),
|
|
|
);
|
|
|
@@ -110,10 +112,7 @@ export class OrderListComponent
|
|
|
map(qpm => qpm.get('filter') || 'open'),
|
|
|
distinctUntilChanged(),
|
|
|
);
|
|
|
- const searchTerms$ = merge(
|
|
|
- this.searchOrderCodeControl.valueChanges,
|
|
|
- this.searchLastNameControl.valueChanges,
|
|
|
- ).pipe(
|
|
|
+ const searchTerms$ = merge(this.searchControl.valueChanges).pipe(
|
|
|
filter(value => 2 < value.length || value.length === 0),
|
|
|
debounceTime(250),
|
|
|
);
|
|
|
@@ -164,13 +163,13 @@ export class OrderListComponent
|
|
|
// tslint:disable-next-line:no-shadowed-variable
|
|
|
skip: number,
|
|
|
take: number,
|
|
|
- orderCodeSearchTerm: string,
|
|
|
- customerNameSearchTerm: string,
|
|
|
+ searchTerm: string,
|
|
|
activeFilterPreset?: string,
|
|
|
): { options: OrderListOptions } {
|
|
|
const filterConfig = this.filterPresets.find(p => p.name === activeFilterPreset);
|
|
|
// tslint:disable-next-line:no-shadowed-variable
|
|
|
- const filter: any = {};
|
|
|
+ let filter: any = {};
|
|
|
+ let filterOperator: LogicalOperator = LogicalOperator.AND;
|
|
|
if (filterConfig) {
|
|
|
if (filterConfig.config.active != null) {
|
|
|
filter.active = {
|
|
|
@@ -209,15 +208,19 @@ export class OrderListComponent
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
- if (customerNameSearchTerm) {
|
|
|
- filter.customerLastName = {
|
|
|
- contains: customerNameSearchTerm,
|
|
|
- };
|
|
|
- }
|
|
|
- if (orderCodeSearchTerm) {
|
|
|
- filter.code = {
|
|
|
- contains: orderCodeSearchTerm,
|
|
|
+ if (searchTerm) {
|
|
|
+ filter = {
|
|
|
+ customerLastName: {
|
|
|
+ contains: searchTerm,
|
|
|
+ },
|
|
|
+ transactionId: {
|
|
|
+ contains: searchTerm,
|
|
|
+ },
|
|
|
+ code: {
|
|
|
+ contains: searchTerm,
|
|
|
+ },
|
|
|
};
|
|
|
+ filterOperator = LogicalOperator.OR;
|
|
|
}
|
|
|
return {
|
|
|
options: {
|
|
|
@@ -229,6 +232,7 @@ export class OrderListComponent
|
|
|
sort: {
|
|
|
updatedAt: SortOrder.DESC,
|
|
|
},
|
|
|
+ filterOperator,
|
|
|
},
|
|
|
};
|
|
|
}
|