-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/domain autocomplete getters #368
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
42b321f
domain autocomplete container skeleton
just-at-uber cd4e340
Added domain autocomplete getters
just-at-uber e7c1223
Merge branch 'master' into feature/domain-search-getters
just-at-uber a82c5f8
added test for combineDomainList
just-at-uber 006e628
adding test for filterTopDomainList
just-at-uber 735660f
test for filterVisitedDomainList
just-at-uber 8380cb6
adding tests for formatDomainLabel
just-at-uber 987aba0
adding test for sortDomainList
just-at-uber ea70308
Merge branch 'master' into feature/domain-search-getters
just-at-uber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how big do these lists get? are they prior to the 15-limit or after?
if it's prior to that limit, probably worth switching this to be a map lookup - 100s might be visibly slow to do repeated lookups on a list like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now there is no cap on visitedDomainList so this can grow infinitely. I will change the action in the next PR (#369) to cap out to a max of 15.