diff --git a/package-lock.json b/package-lock.json index 3c655049..ce91e4f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5876,8 +5876,8 @@ "dev": true }, "damsel": { - "version": "git+ssh://git@github.com/rbkmoney/damsel.git#efbc1e16fb17bbb4f92314f0b3e8712a9e2b2c59", - "from": "git+ssh://git@github.com/rbkmoney/damsel.git#efbc1e16fb17bbb4f92314f0b3e8712a9e2b2c59" + "version": "git+ssh://git@github.com/rbkmoney/damsel.git#85e1cd96af9e0387c310cdb58364bb859a452a75", + "from": "git+ssh://git@github.com/rbkmoney/damsel.git#85e1cd96af9e0387c310cdb58364bb859a452a75" }, "dashdash": { "version": "1.14.1", diff --git a/package.json b/package.json index 7ad9bb90..1ce4faf2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "angular-file": "3.0.1", "angular2-prettyjson": "3.0.1", "ank-proto": "git+ssh://git@github.com:rbkmoney/ank-proto.git#21edf79b702e704ccc207bf7e03be1bbf830eed6", - "damsel": "git+ssh://git@github.com/rbkmoney/damsel.git#efbc1e16fb17bbb4f92314f0b3e8712a9e2b2c59", + "damsel": "git+ssh://git@github.com/rbkmoney/damsel.git#85e1cd96af9e0387c310cdb58364bb859a452a75", "file-storage-proto": "git+ssh://git@github.com:rbkmoney/file-storage-proto.git#281e1ca4cea9bf32229a6c389f0dcf5d49c05a0b", "fistful-proto": "git+ssh://git@github.com/rbkmoney/fistful-proto.git#c2113c853ed71a34bb6468b9a6cf9b468967af84", "humanize-duration": "~3.21.0", diff --git a/src/app/sections/claim-search-form/claim-search-form.component.html b/src/app/sections/claim-search-form/claim-search-form.component.html index 85dd7b67..2b84e74a 100644 --- a/src/app/sections/claim-search-form/claim-search-form.component.html +++ b/src/app/sections/claim-search-form/claim-search-form.component.html @@ -1,12 +1,21 @@
- + {{ status | ccClaimStatus }} - + + + + - + { this.router.navigate([location.pathname], { queryParams: v }); this.valueChanges.emit(formValueToSearchParams(v)); diff --git a/src/app/sections/claim-search-form/form-value-to-search-params.ts b/src/app/sections/claim-search-form/form-value-to-search-params.ts index ddf2860a..59332a1c 100644 --- a/src/app/sections/claim-search-form/form-value-to-search-params.ts +++ b/src/app/sections/claim-search-form/form-value-to-search-params.ts @@ -1,16 +1,11 @@ -export const formValueToSearchParams = (params: {}) => { - const result = {}; - for (const k in params) { - if (params.hasOwnProperty(k)) { - if (k === 'statuses') { - result[k] = (params[k] as string[]).reduce((acc, cv) => [...acc, { [cv]: {} }], []); - } else if (params[k]) { - if (params[k] === '') { - break; - } - result[k] = params[k]; - } - } - } - return result; -}; +import pick from 'lodash-es/pick'; +import pickBy from 'lodash-es/pickBy'; + +import { isNumeric, mapValuesToNumber, mapValuesToThriftEnum } from '../../shared/utils'; +import { SearchFormValue } from './search-form-value'; + +export const formValueToSearchParams = (params: {}): SearchFormValue => ({ + ...params, + ...mapValuesToThriftEnum(pick(params, 'statuses')), + ...mapValuesToNumber(pickBy(params, isNumeric)), +}); diff --git a/src/app/sections/claim-search-form/query-params-to-form-value.ts b/src/app/sections/claim-search-form/query-params-to-form-value.ts index 1bcd7583..6b0eae95 100644 --- a/src/app/sections/claim-search-form/query-params-to-form-value.ts +++ b/src/app/sections/claim-search-form/query-params-to-form-value.ts @@ -1,15 +1,13 @@ import { Params } from '@angular/router'; +import pickBy from 'lodash-es/pickBy'; -export const queryParamsToFormValue = (params: Params) => { - const result = {}; - for (const k in params) { - if (params.hasOwnProperty(k)) { - if (k === 'statuses' && typeof params[k] === 'string') { - result[k] = [params[k]]; - } else { - result[k] = params[k]; - } - } - } - return result; -}; +import { wrapValuesToArray } from '../../shared/utils'; + +const statusesAndPrimitives = (v, k) => + k === 'statuses' && (typeof v === 'string' || typeof v === 'number'); + +export const queryParamsToFormValue = (params: Params) => ({ + ...params, + // Query param ?statuses=accepted will be present as { statuses: 'accepted' } in form. Selector value must be an array in multiple-selection mode. + ...wrapValuesToArray(pickBy(params, statusesAndPrimitives)), +}); diff --git a/src/app/sections/claim-search-form/search-form-value.ts b/src/app/sections/claim-search-form/search-form-value.ts index 75c04b0b..544d6680 100644 --- a/src/app/sections/claim-search-form/search-form-value.ts +++ b/src/app/sections/claim-search-form/search-form-value.ts @@ -3,6 +3,7 @@ import { ClaimID } from '../../thrift-services/damsel/gen-model/claim_management export interface SearchFormValue { claim_id?: ClaimID; + email?: string; party_id?: string; statuses?: ClaimStatus[]; } diff --git a/src/app/sections/search-claims/search-claims.service.ts b/src/app/sections/search-claims/search-claims.service.ts index f7d68fda..8c8ceeed 100644 --- a/src/app/sections/search-claims/search-claims.service.ts +++ b/src/app/sections/search-claims/search-claims.service.ts @@ -11,7 +11,7 @@ import { SearchFormValue } from '../claim-search-form'; export class SearchClaimsService extends PartialFetcher { private readonly searchLimit = 20; - claims$: Observable = this.searchResult$.pipe(); + claims$: Observable = this.searchResult$; constructor(private claimManagementService: ClaimManagementService) { super(); diff --git a/src/app/shared/utils/index.ts b/src/app/shared/utils/index.ts index 6db11bf9..75ebef04 100644 --- a/src/app/shared/utils/index.ts +++ b/src/app/shared/utils/index.ts @@ -2,3 +2,7 @@ export * from './sort-units'; export * from './to-optional'; export * from './get-union-key'; export * from './remove-empty-properties'; +export * from './map-values-to-thrift-enum'; +export * from './map-values-to-number'; +export * from './is-numeric'; +export * from './wrap-values-to-array'; diff --git a/src/app/shared/utils/is-numeric.ts b/src/app/shared/utils/is-numeric.ts new file mode 100644 index 00000000..39dadd54 --- /dev/null +++ b/src/app/shared/utils/is-numeric.ts @@ -0,0 +1,2 @@ +export const isNumeric = (x): boolean => + (typeof x === 'number' || typeof x === 'string') && !isNaN(Number(x)); diff --git a/src/app/shared/utils/map-values-to-number.ts b/src/app/shared/utils/map-values-to-number.ts new file mode 100644 index 00000000..6d33bdec --- /dev/null +++ b/src/app/shared/utils/map-values-to-number.ts @@ -0,0 +1,4 @@ +import toNumber from 'lodash-es/toNumber'; + +export const mapValuesToNumber = (obj: {}): {} => + Object.entries(obj).reduce((acc, [k, v]) => ({ ...acc, [k]: toNumber(v) }), {}); diff --git a/src/app/shared/utils/map-values-to-thrift-enum.ts b/src/app/shared/utils/map-values-to-thrift-enum.ts new file mode 100644 index 00000000..54f15b9b --- /dev/null +++ b/src/app/shared/utils/map-values-to-thrift-enum.ts @@ -0,0 +1,5 @@ +// Thrift enum ex: [{ enumVal: {} }, ...] +const toThriftEnum = (arr: string[]) => arr.reduce((acc, cv) => [...acc, { [cv]: {} }], []); + +export const mapValuesToThriftEnum = (obj: {}): {} => + Object.entries(obj).reduce((acc, [k, v]) => ({ ...acc, [k]: toThriftEnum(v as string[]) }), {}); diff --git a/src/app/shared/utils/remove-empty-properties.ts b/src/app/shared/utils/remove-empty-properties.ts index 9638e21c..88ead5b8 100644 --- a/src/app/shared/utils/remove-empty-properties.ts +++ b/src/app/shared/utils/remove-empty-properties.ts @@ -1,5 +1,4 @@ -export const removeEmptyProperties = (s: T) => - Object.keys(s).reduce( - (acc, cur) => (!!s[cur] && s[cur] !== '' ? { ...acc, [cur]: s[cur] } : acc), - {} as T - ); +import identity from 'lodash-es/identity'; +import pickBy from 'lodash-es/pickBy'; + +export const removeEmptyProperties = (s) => pickBy(s, identity); diff --git a/src/app/shared/utils/wrap-values-to-array.ts b/src/app/shared/utils/wrap-values-to-array.ts new file mode 100644 index 00000000..2c0bddc3 --- /dev/null +++ b/src/app/shared/utils/wrap-values-to-array.ts @@ -0,0 +1,2 @@ +export const wrapValuesToArray = (params: {}): {} => + Object.entries(params).reduce((acc, [k, v]) => ({ ...acc, [k]: [v] }), {});