diff options
Diffstat (limited to 'app/assets/javascripts')
6 files changed, 49 insertions, 18 deletions
diff --git a/app/assets/javascripts/boards/components/sidebar/board_sidebar_time_tracker.vue b/app/assets/javascripts/boards/components/sidebar/board_sidebar_time_tracker.vue index 5d61f7b2887..a35b3f14be4 100644 --- a/app/assets/javascripts/boards/components/sidebar/board_sidebar_time_tracker.vue +++ b/app/assets/javascripts/boards/components/sidebar/board_sidebar_time_tracker.vue @@ -29,6 +29,7 @@ export default { <template> <issuable-time-tracker + :issuable-id="activeBoardItem.id.toString()" :issuable-iid="activeBoardItem.iid.toString()" :limit-to-hours="timeTrackingLimitToHours" :initial-time-tracking="initialTimeTracking" diff --git a/app/assets/javascripts/frequent_items/utils.js b/app/assets/javascripts/frequent_items/utils.js index 88519d934cb..27ef47df8c8 100644 --- a/app/assets/javascripts/frequent_items/utils.js +++ b/app/assets/javascripts/frequent_items/utils.js @@ -35,13 +35,15 @@ export const getTopFrequentItems = (items) => { }; export const updateExistingFrequentItem = (frequentItem, item) => { - const accessedOverHourAgo = - Math.abs(item.lastAccessedOn - frequentItem.lastAccessedOn) / HOUR_IN_MS > 1; + // `frequentItem` comes from localStorage and it's possible it doesn't have a `lastAccessedOn` + const neverAccessed = !frequentItem.lastAccessedOn; + const shouldUpdate = + neverAccessed || Math.abs(item.lastAccessedOn - frequentItem.lastAccessedOn) / HOUR_IN_MS > 1; return { ...item, - frequency: accessedOverHourAgo ? frequentItem.frequency + 1 : frequentItem.frequency, - lastAccessedOn: accessedOverHourAgo ? Date.now() : frequentItem.lastAccessedOn, + frequency: shouldUpdate ? frequentItem.frequency + 1 : frequentItem.frequency, + lastAccessedOn: shouldUpdate ? Date.now() : frequentItem.lastAccessedOn, }; }; diff --git a/app/assets/javascripts/nav/components/top_nav_container_view.vue b/app/assets/javascripts/nav/components/top_nav_container_view.vue index 6f98f85ff90..36e4a278da9 100644 --- a/app/assets/javascripts/nav/components/top_nav_container_view.vue +++ b/app/assets/javascripts/nav/components/top_nav_container_view.vue @@ -20,6 +20,10 @@ export default { type: String, required: true, }, + currentItem: { + type: Object, + required: true, + }, containerClass: { type: String, required: false, @@ -43,6 +47,12 @@ export default { { id: 'secondary', menuItems: this.linksSecondary }, ].filter((x) => x.menuItems?.length); }, + currentItemTimestamped() { + return { + ...this.currentItem, + lastAccessedOn: Date.now(), + }; + }, }, mounted() { // For historic reasons, the frequent-items-app component requires this too start up. @@ -62,7 +72,7 @@ export default { > <div class="frequent-items-dropdown-content gl-w-full! gl-pt-0!"> <vuex-module-provider :vuex-module="frequentItemsVuexModule"> - <frequent-items-app v-bind="$attrs" /> + <frequent-items-app :current-item="currentItemTimestamped" v-bind="$attrs" /> </vuex-module-provider> </div> </div> diff --git a/app/assets/javascripts/sidebar/components/time_tracking/sidebar_time_tracking.vue b/app/assets/javascripts/sidebar/components/time_tracking/sidebar_time_tracking.vue index 58167b3934a..d472b67d976 100644 --- a/app/assets/javascripts/sidebar/components/time_tracking/sidebar_time_tracking.vue +++ b/app/assets/javascripts/sidebar/components/time_tracking/sidebar_time_tracking.vue @@ -17,6 +17,10 @@ export default { required: false, default: '', }, + issuableId: { + type: String, + required: true, + }, issuableIid: { type: String, required: true, @@ -60,6 +64,7 @@ export default { <div class="block"> <issuable-time-tracker :full-path="fullPath" + :issuable-id="issuableId" :issuable-iid="issuableIid" :limit-to-hours="limitToHours" /> diff --git a/app/assets/javascripts/sidebar/components/time_tracking/time_tracker.vue b/app/assets/javascripts/sidebar/components/time_tracking/time_tracker.vue index 3feff8639a1..87ddbbf256a 100644 --- a/app/assets/javascripts/sidebar/components/time_tracking/time_tracker.vue +++ b/app/assets/javascripts/sidebar/components/time_tracking/time_tracker.vue @@ -31,7 +31,11 @@ export default { directives: { GlModal: GlModalDirective, }, - inject: ['issuableType'], + inject: { + issuableType: { + default: null, + }, + }, props: { limitToHours: { type: Boolean, @@ -43,6 +47,11 @@ export default { required: false, default: '', }, + issuableId: { + type: String, + required: false, + default: '', + }, issuableIid: { type: String, required: false, @@ -83,15 +92,18 @@ export default { return timeTrackingQueries[this.issuableType].query; }, skip() { - // We don't fetch info via GraphQL in following cases - // 1. Time tracking info was provided via prop - // 2. issuableIid and fullPath are not provided. - if (!this.initialTimeTracking) { - return false; - } else if (this.issuableIid && this.fullPath) { - return false; + // Skip the query if either of the conditions are true + // 1. issuableType is not provided + // 2. Time tracking info was provided via prop + // 3. issuableIid and fullPath are not provided + if (!this.issuableType || !timeTrackingQueries[this.issuableType]) { + return true; + } else if (this.initialTimeTracking) { + return true; + } else if (!this.issuableIid || !this.fullPath) { + return true; } - return true; + return false; }, variables() { return { @@ -108,7 +120,7 @@ export default { }, computed: { isTimeTrackingInfoLoading() { - return this.$apollo?.queries.issuableTimeTracking.loading ?? false; + return this.$apollo?.queries.issuableTimeTracking?.loading ?? false; }, timeEstimate() { return this.timeTracking?.timeEstimate || 0; @@ -146,7 +158,7 @@ export default { isTimeReportSupported() { return ( [IssuableType.Issue, IssuableType.MergeRequest].includes(this.issuableType) && - this.issuableIid + this.issuableId ); }, }, @@ -240,7 +252,7 @@ export default { :title="__('Time tracking report')" :hide-footer="true" > - <time-tracking-report :limit-to-hours="limitToHours" :issuable-iid="issuableIid" /> + <time-tracking-report :limit-to-hours="limitToHours" :issuable-id="issuableId" /> </gl-modal> </template> <transition name="help-state-toggle"> diff --git a/app/assets/javascripts/sidebar/mount_sidebar.js b/app/assets/javascripts/sidebar/mount_sidebar.js index f53760eab93..67c72b17f1f 100644 --- a/app/assets/javascripts/sidebar/mount_sidebar.js +++ b/app/assets/javascripts/sidebar/mount_sidebar.js @@ -391,7 +391,7 @@ function mountSubscriptionsComponent() { function mountTimeTrackingComponent() { const el = document.getElementById('issuable-time-tracker'); - const { iid, fullPath, issuableType, timeTrackingLimitToHours } = getSidebarOptions(); + const { id, iid, fullPath, issuableType, timeTrackingLimitToHours } = getSidebarOptions(); if (!el) return; @@ -404,6 +404,7 @@ function mountTimeTrackingComponent() { createElement(SidebarTimeTracking, { props: { fullPath, + issuableId: id.toString(), issuableIid: iid.toString(), limitToHours: timeTrackingLimitToHours, }, |