-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: load and format lend menu data #314
Open
christian14b
wants to merge
14
commits into
www-header
Choose a base branch
from
wwwHeader-lend-menu-data
base: www-header
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
754a84d
feat: load and format lend menu data
a3a27c7
refactor: array groupBy and sortBy methods
c98852b
test: add event to let know parent to call onLoad method and get lend…
c7bb125
feat: add borrower/trustee state and small fix in balance
03f71c5
feat: add tracking events
17b3f90
fix: menu drawer was not visible
6d4366d
refactor: use async loading for menu wrapper components
4f1e065
Merge pull request #317 from kiva/wwwHeader-track-events
christian14b 53b2230
fix: using numeral to format balance
6d5059a
Merge pull request #316 from kiva/wwwHeader-borrower-trustee-states
christian14b a4bd534
Merge branch 'wwwHeader-lend-menu-data' into wwwHeader-integration-test
christian14b 22e3490
fix: extra space in variable declaration
4cd08df
Merge pull request #318 from kiva/wwwHeader-integration-test
christian14b c4b2508
refactor: unnecessary userId variable
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Groups an array of objects by a specified key. | ||
* @param {Array} array - The array of objects to be grouped. | ||
* @param {string} groupByKey - The key based on which the grouping should be done. | ||
* @returns {Object} - An object where keys are unique values of the specified key, | ||
* and values are arrays of objects that share the same key value. | ||
*/ | ||
|
||
const groupBy = (array, groupByKey) => { | ||
return array.reduce((groups, currentItem) => { | ||
const keyValue = currentItem[groupByKey]; | ||
if (!groups[keyValue]) { | ||
// eslint-disable-next-line no-param-reassign | ||
groups[keyValue] = []; | ||
} | ||
groups[keyValue].push(currentItem); | ||
return groups; | ||
}, {}); | ||
}; | ||
|
||
/** | ||
* Returns a comparator function for sorting an array of objects by a specified key. | ||
* @param {string} key - The key based on which the sorting should be done. | ||
* @returns {Function} - A comparator function that can be used with the Array.sort() method. | ||
*/ | ||
const sortBy = (key) => { | ||
// eslint-disable-next-line no-nested-ternary | ||
return (a, b) => ((a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0)); | ||
}; | ||
|
||
export { groupBy, sortBy }; |
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
</transition> | ||
<!-- logo --> | ||
<a | ||
v-kv-track-event="['TopNav', 'click-Logo']" | ||
href="/" | ||
class=" | ||
tw-px-1 tw-py-2 | ||
|
@@ -82,7 +83,7 @@ | |
v-show="menuOpen || searchOpen" | ||
class=" | ||
tw-absolute tw-z-modal | ||
tw-top-7.5 tw-inset-x-0 tw-bottom-0 | ||
tw-top-7.5 tw-inset-x-0 | ||
tw-bg-eco-green-4 | ||
tw-bg-opacity-[50%] | ||
" | ||
|
@@ -96,8 +97,14 @@ | |
<div class="header-margins tw-px-2.5"> | ||
<component | ||
:is="menuComponent" | ||
ref="menuComponentInstance" | ||
:logged-in="loggedIn" | ||
:login-url="loginUrl" | ||
:user-id="userId" | ||
:balance="balance" | ||
:is-borrower="isBorrower" | ||
:is-trustee="isTrustee" | ||
@load-lend-menu-data="emitLendMenuEvent" | ||
/> | ||
</div> | ||
</div> | ||
|
@@ -108,14 +115,13 @@ | |
|
||
<script> | ||
import { | ||
ref, | ||
ref, shallowRef, | ||
} from 'vue-demi'; | ||
import { | ||
ecoForestTheme, | ||
} from '@kiva/kv-tokens/configs/kivaColors.cjs'; | ||
import KvHeaderLinkBar from './KvWwwHeader/KvHeaderLinkBar.vue'; | ||
import KvHeaderLogo from './KvWwwHeader/KvHeaderLogo.vue'; | ||
import KvHeaderMobileMenu from './KvWwwHeader/KvHeaderMobileMenu.vue'; | ||
import KvHeaderSearchBar from './KvWwwHeader/KvHeaderSearchBar.vue'; | ||
import KvThemeProvider from './KvThemeProvider.vue'; | ||
import KvHeaderSearchSuggestions from './KvWwwHeader/KvHeaderSearchSuggestions.vue'; | ||
|
@@ -124,7 +130,6 @@ export default { | |
components: { | ||
KvHeaderLinkBar, | ||
KvHeaderLogo, | ||
KvHeaderMobileMenu, | ||
KvHeaderSearchBar, | ||
KvThemeProvider, | ||
KvHeaderSearchSuggestions, | ||
|
@@ -142,14 +147,31 @@ export default { | |
type: String, | ||
default: '/ui-login', | ||
}, | ||
balance: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
isBorrower: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
isTrustee: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
setup() { | ||
emits: [ | ||
'load-lend-menu-data', | ||
], | ||
setup(props, { emit }) { | ||
const linksVisible = ref(true); | ||
const searchBar = ref(null); | ||
const searchOpen = ref(false); | ||
const activeHeaderItem = ref(null); | ||
const menuOpen = ref(false); | ||
const menuComponent = ref(null); | ||
const menuComponent = shallowRef(null); | ||
const menuComponentInstance = ref(null); | ||
const userId = ref(props.userId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. userId should be declared as a prop, and then it will be available in the template and won't need to be declared here. |
||
|
||
let menuCloseTimeout; | ||
|
||
|
@@ -196,12 +218,23 @@ export default { | |
searchBar.value?.getSuggestions(apollo); | ||
}; | ||
|
||
const loadMenuData = (apollo) => { | ||
menuComponentInstance.value?.onLoad(apollo); | ||
}; | ||
|
||
// This event will be used as a signal to call loadMenuData | ||
const emitLendMenuEvent = () => { | ||
emit('load-lend-menu-data'); | ||
}; | ||
|
||
return { | ||
ecoForestTheme, | ||
userId, | ||
|
||
afterLinksNotVisible, | ||
afterSearchClosed, | ||
afterSearchOpen, | ||
emitLendMenuEvent, | ||
|
||
linksVisible, | ||
searchOpen, | ||
|
@@ -211,10 +244,12 @@ export default { | |
openSearch, | ||
closeSearch, | ||
getSuggestions, | ||
loadMenuData, | ||
|
||
activeHeaderItem, | ||
searchBar, | ||
menuComponent, | ||
menuComponentInstance, | ||
}; | ||
}, | ||
}; | ||
|
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
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
Oops, something went wrong.
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.
Thanks for adding this!