-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/domain autocomplete getters (#368)
* domain autocomplete container skeleton * Added domain autocomplete getters * added test for combineDomainList * adding test for filterTopDomainList * test for filterVisitedDomainList * adding tests for formatDomainLabel * adding test for sortDomainList
- Loading branch information
1 parent
43fb31e
commit 9e1cc44
Showing
21 changed files
with
715 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import { typePrefix } from './helpers'; | ||
|
||
export const DOMAIN_AUTOCOMPLETE_COMBINED_DOMAIN_LIST = typePrefix( | ||
'COMBINED_DOMAIN_LIST' | ||
); | ||
export const DOMAIN_AUTOCOMPLETE_DOMAIN_LIST = typePrefix('DOMAIN_LIST'); | ||
export const DOMAIN_AUTOCOMPLETE_FILTERED_VISITED_DOMAIN_LIST = typePrefix( | ||
'FILTERED_VISITED_DOMAIN_LIST' | ||
); | ||
export const DOMAIN_AUTOCOMPLETE_IS_LOADING = typePrefix('IS_LOADING'); | ||
export const DOMAIN_AUTOCOMPLETE_NAVIGATE_TO_DOMAIN_URL = typePrefix( | ||
'NAVIGATE_TO_DOMAIN_URL' | ||
); | ||
export const DOMAIN_AUTOCOMPLETE_SEARCH = typePrefix('SEARCH'); | ||
export const DOMAIN_AUTOCOMPLETE_SEARCH_URL = typePrefix('SEARCH_URL'); | ||
export const DOMAIN_AUTOCOMPLETE_VISITED_DOMAIN_LIST = typePrefix( | ||
'VISITED_DOMAIN_LIST' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import { get } from 'lodash-es'; | ||
import { | ||
DOMAIN_AUTOCOMPLETE_COMBINED_DOMAIN_LIST, | ||
DOMAIN_AUTOCOMPLETE_DOMAIN_LIST, | ||
DOMAIN_AUTOCOMPLETE_FILTERED_VISITED_DOMAIN_LIST, | ||
DOMAIN_AUTOCOMPLETE_IS_LOADING, | ||
DOMAIN_AUTOCOMPLETE_NAVIGATE_TO_DOMAIN_URL, | ||
DOMAIN_AUTOCOMPLETE_SEARCH, | ||
DOMAIN_AUTOCOMPLETE_SEARCH_URL, | ||
DOMAIN_AUTOCOMPLETE_VISITED_DOMAIN_LIST, | ||
} from './getter-types'; | ||
import { | ||
combineDomainList, | ||
filterVisitedDomainList, | ||
filterTopDomainList, | ||
formatDomainList, | ||
sortDomainList, | ||
statePrefix, | ||
} from './helpers'; | ||
import { combine } from '~helpers'; | ||
|
||
const getters = { | ||
[DOMAIN_AUTOCOMPLETE_COMBINED_DOMAIN_LIST]: (_, getters) => { | ||
const visitedDomainList = | ||
getters[DOMAIN_AUTOCOMPLETE_FILTERED_VISITED_DOMAIN_LIST]; | ||
const domainList = getters[DOMAIN_AUTOCOMPLETE_DOMAIN_LIST]; | ||
const combinedDomainList = combineDomainList({ | ||
visitedDomainList, | ||
domainList, | ||
}); | ||
|
||
return combine(combinedDomainList)( | ||
sortDomainList, | ||
filterTopDomainList, | ||
formatDomainList | ||
); | ||
}, | ||
[DOMAIN_AUTOCOMPLETE_DOMAIN_LIST]: state => | ||
sortDomainList(get(state, statePrefix('domainList')) || []), | ||
[DOMAIN_AUTOCOMPLETE_FILTERED_VISITED_DOMAIN_LIST]: (_, getters) => | ||
filterVisitedDomainList({ | ||
visitedDomainList: getters[DOMAIN_AUTOCOMPLETE_VISITED_DOMAIN_LIST], | ||
search: getters[DOMAIN_AUTOCOMPLETE_SEARCH], | ||
}), | ||
[DOMAIN_AUTOCOMPLETE_IS_LOADING]: state => | ||
get(state, statePrefix('isLoading')) || false, | ||
[DOMAIN_AUTOCOMPLETE_NAVIGATE_TO_DOMAIN_URL]: (_, getters) => { | ||
const search = getters[DOMAIN_AUTOCOMPLETE_SEARCH]; | ||
|
||
if (!search) { | ||
return ''; | ||
} | ||
|
||
return `/domains/${search}`; | ||
}, | ||
[DOMAIN_AUTOCOMPLETE_SEARCH]: state => | ||
get(state, statePrefix('search')) || '', | ||
[DOMAIN_AUTOCOMPLETE_SEARCH_URL]: (_, getters) => | ||
`/api/domains?querystring=${getters[DOMAIN_AUTOCOMPLETE_SEARCH]}`, | ||
[DOMAIN_AUTOCOMPLETE_VISITED_DOMAIN_LIST]: state => | ||
sortDomainList(get(state, statePrefix('visitedDomainList')) || []), | ||
}; | ||
|
||
export default getters; |
36 changes: 36 additions & 0 deletions
36
client/containers/domain-autocomplete/helpers/combine-domain-list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const combineDomainList = ({ domainList, visitedDomainList }) => { | ||
const domainListUuidList = domainList.map(domain => domain.domainInfo.uuid); | ||
const domainNameList = domainList.map(domain => domain.domainInfo.name); | ||
|
||
return [ | ||
...domainList, | ||
...visitedDomainList.filter(domain => | ||
typeof domain === 'string' | ||
? domainNameList.indexOf(domain) === -1 | ||
: domainListUuidList.indexOf(domain.domainInfo.uuid) === -1 | ||
), | ||
]; | ||
}; | ||
|
||
export default combineDomainList; |
96 changes: 96 additions & 0 deletions
96
client/containers/domain-autocomplete/helpers/combine-domain-list.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import combineDomainList from './combine-domain-list'; | ||
|
||
describe('combineDomainList', () => { | ||
describe('when passed domainList & visitedDomainList', () => { | ||
const visitedDomainList = [ | ||
'domain1', | ||
{ | ||
domainInfo: { | ||
name: 'domain2', | ||
uuid: 2, | ||
}, | ||
}, | ||
'domain3', | ||
{ | ||
domainInfo: { | ||
name: 'domain4', | ||
uuid: 4, | ||
}, | ||
}, | ||
]; | ||
|
||
const domainList = [ | ||
{ | ||
domainInfo: { | ||
name: 'domain0', | ||
uuid: 0, | ||
}, | ||
}, | ||
{ | ||
domainInfo: { | ||
name: 'domain1', | ||
uuid: 1, | ||
}, | ||
}, | ||
{ | ||
domainInfo: { | ||
name: 'domain2', | ||
uuid: 2, | ||
}, | ||
}, | ||
]; | ||
|
||
it('should combine the two lists into a single list by removing any duplicates from the visitedDomainList.', () => { | ||
const output = combineDomainList({ domainList, visitedDomainList }); | ||
|
||
expect(output).toEqual([ | ||
{ | ||
domainInfo: { | ||
name: 'domain0', | ||
uuid: 0, | ||
}, | ||
}, | ||
{ | ||
domainInfo: { | ||
name: 'domain1', | ||
uuid: 1, | ||
}, | ||
}, | ||
{ | ||
domainInfo: { | ||
name: 'domain2', | ||
uuid: 2, | ||
}, | ||
}, | ||
'domain3', | ||
{ | ||
domainInfo: { | ||
name: 'domain4', | ||
uuid: 4, | ||
}, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
client/containers/domain-autocomplete/helpers/filter-top-domain-list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import { TOP_DOMAIN_LIST_LIMIT } from '../constants'; | ||
|
||
const filterTopDomainList = domainList => | ||
domainList.slice(0, TOP_DOMAIN_LIST_LIMIT); | ||
|
||
export default filterTopDomainList; |
53 changes: 53 additions & 0 deletions
53
client/containers/domain-autocomplete/helpers/filter-top-domain-list.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import { TOP_DOMAIN_LIST_LIMIT } from '../constants'; | ||
import filterTopDomainList from './filter-top-domain-list'; | ||
|
||
describe('filterTopDomainList', () => { | ||
const createDomainList = size => { | ||
const newDomainList = []; | ||
|
||
for (let i = 1; i < size + 1; i++) { | ||
newDomainList.push(`domain${i}`); | ||
} | ||
|
||
return newDomainList; | ||
}; | ||
|
||
describe('when domainList is greater than TOP_DOMAIN_LIST_LIMIT', () => { | ||
let domainList; | ||
|
||
beforeEach(() => { | ||
domainList = createDomainList(TOP_DOMAIN_LIST_LIMIT * 2); | ||
}); | ||
|
||
it('should return only the first domains of size = TOP_DOMAIN_LIST_LIMIT', () => { | ||
const output = filterTopDomainList(domainList); | ||
|
||
expect(output.length).toEqual(TOP_DOMAIN_LIST_LIMIT); | ||
expect(output[0]).toEqual('domain1'); | ||
expect(output[output.length - 1]).toEqual( | ||
`domain${TOP_DOMAIN_LIST_LIMIT}` | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.