Commit d69d0f9c authored by Kushal Pandya's avatar Kushal Pandya

Fix broken Time Tracking Reports on Issuables

Fixes a bug where Report component for Time Tracking
in Issuables sidebar didn't get `id` value for Issuable
which led to GraphQL query failing to load detailed
time tracking report.

Changelog: fixed
parent 7e126601
...@@ -29,6 +29,7 @@ export default { ...@@ -29,6 +29,7 @@ export default {
<template> <template>
<issuable-time-tracker <issuable-time-tracker
:issuable-id="activeBoardItem.id.toString()"
:issuable-iid="activeBoardItem.iid.toString()" :issuable-iid="activeBoardItem.iid.toString()"
:limit-to-hours="timeTrackingLimitToHours" :limit-to-hours="timeTrackingLimitToHours"
:initial-time-tracking="initialTimeTracking" :initial-time-tracking="initialTimeTracking"
......
...@@ -17,6 +17,10 @@ export default { ...@@ -17,6 +17,10 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
issuableId: {
type: String,
required: true,
},
issuableIid: { issuableIid: {
type: String, type: String,
required: true, required: true,
...@@ -60,6 +64,7 @@ export default { ...@@ -60,6 +64,7 @@ export default {
<div class="block"> <div class="block">
<issuable-time-tracker <issuable-time-tracker
:full-path="fullPath" :full-path="fullPath"
:issuable-id="issuableId"
:issuable-iid="issuableIid" :issuable-iid="issuableIid"
:limit-to-hours="limitToHours" :limit-to-hours="limitToHours"
/> />
......
...@@ -31,7 +31,11 @@ export default { ...@@ -31,7 +31,11 @@ export default {
directives: { directives: {
GlModal: GlModalDirective, GlModal: GlModalDirective,
}, },
inject: ['issuableType'], inject: {
issuableType: {
default: null,
},
},
props: { props: {
limitToHours: { limitToHours: {
type: Boolean, type: Boolean,
...@@ -43,6 +47,11 @@ export default { ...@@ -43,6 +47,11 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
issuableId: {
type: String,
required: false,
default: '',
},
issuableIid: { issuableIid: {
type: String, type: String,
required: false, required: false,
...@@ -83,15 +92,18 @@ export default { ...@@ -83,15 +92,18 @@ export default {
return timeTrackingQueries[this.issuableType].query; return timeTrackingQueries[this.issuableType].query;
}, },
skip() { skip() {
// We don't fetch info via GraphQL in following cases // Skip the query if either of the conditions are true
// 1. Time tracking info was provided via prop // 1. issuableType is not provided
// 2. issuableIid and fullPath are not provided. // 2. Time tracking info was provided via prop
if (!this.initialTimeTracking) { // 3. issuableIid and fullPath are not provided
return false; if (!this.issuableType || !timeTrackingQueries[this.issuableType]) {
} else if (this.issuableIid && this.fullPath) { return true;
return false; } else if (this.initialTimeTracking) {
return true;
} else if (!this.issuableIid || !this.fullPath) {
return true;
} }
return true; return false;
}, },
variables() { variables() {
return { return {
...@@ -146,7 +158,7 @@ export default { ...@@ -146,7 +158,7 @@ export default {
isTimeReportSupported() { isTimeReportSupported() {
return ( return (
[IssuableType.Issue, IssuableType.MergeRequest].includes(this.issuableType) && [IssuableType.Issue, IssuableType.MergeRequest].includes(this.issuableType) &&
this.issuableIid this.issuableId
); );
}, },
}, },
...@@ -240,7 +252,7 @@ export default { ...@@ -240,7 +252,7 @@ export default {
:title="__('Time tracking report')" :title="__('Time tracking report')"
:hide-footer="true" :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> </gl-modal>
</template> </template>
<transition name="help-state-toggle"> <transition name="help-state-toggle">
......
...@@ -391,7 +391,7 @@ function mountSubscriptionsComponent() { ...@@ -391,7 +391,7 @@ function mountSubscriptionsComponent() {
function mountTimeTrackingComponent() { function mountTimeTrackingComponent() {
const el = document.getElementById('issuable-time-tracker'); const el = document.getElementById('issuable-time-tracker');
const { iid, fullPath, issuableType, timeTrackingLimitToHours } = getSidebarOptions(); const { id, iid, fullPath, issuableType, timeTrackingLimitToHours } = getSidebarOptions();
if (!el) return; if (!el) return;
...@@ -404,6 +404,7 @@ function mountTimeTrackingComponent() { ...@@ -404,6 +404,7 @@ function mountTimeTrackingComponent() {
createElement(SidebarTimeTracking, { createElement(SidebarTimeTracking, {
props: { props: {
fullPath, fullPath,
issuableId: id.toString(),
issuableIid: iid.toString(), issuableIid: iid.toString(),
limitToHours: timeTrackingLimitToHours, limitToHours: timeTrackingLimitToHours,
}, },
......
.block.time-tracking .block.time-tracking
%time-tracker{ ":limit-to-hours" => "timeTrackingLimitToHours", %time-tracker{ ":limit-to-hours" => "timeTrackingLimitToHours",
":issuable-id" => "issue.id ? issue.id.toString() : ''",
":issuable-iid" => "issue.iid ? issue.iid.toString() : ''", ":issuable-iid" => "issue.iid ? issue.iid.toString() : ''",
":full-path" => "issue.project ? issue.project.fullPath : ''", ":full-path" => "issue.project ? issue.project.fullPath : ''",
"root-path" => "#{root_url}" } "root-path" => "#{root_url}" }
...@@ -26,6 +26,7 @@ describe('BoardSidebarTimeTracker', () => { ...@@ -26,6 +26,7 @@ describe('BoardSidebarTimeTracker', () => {
store = createStore(); store = createStore();
store.state.boardItems = { store.state.boardItems = {
1: { 1: {
id: 1,
iid: 1, iid: 1,
timeEstimate: 3600, timeEstimate: 3600,
totalTimeSpent: 1800, totalTimeSpent: 1800,
...@@ -49,6 +50,7 @@ describe('BoardSidebarTimeTracker', () => { ...@@ -49,6 +50,7 @@ describe('BoardSidebarTimeTracker', () => {
expect(wrapper.find(IssuableTimeTracker).props()).toEqual({ expect(wrapper.find(IssuableTimeTracker).props()).toEqual({
limitToHours: timeTrackingLimitToHours, limitToHours: timeTrackingLimitToHours,
showCollapsed: false, showCollapsed: false,
issuableId: '1',
issuableIid: '1', issuableIid: '1',
fullPath: '', fullPath: '',
initialTimeTracking: { initialTimeTracking: {
......
...@@ -19,6 +19,7 @@ describe('Issuable Time Tracker', () => { ...@@ -19,6 +19,7 @@ describe('Issuable Time Tracker', () => {
const defaultProps = { const defaultProps = {
limitToHours: false, limitToHours: false,
fullPath: 'gitlab-org/gitlab-test', fullPath: 'gitlab-org/gitlab-test',
issuableId: '1',
issuableIid: '1', issuableIid: '1',
initialTimeTracking: { initialTimeTracking: {
...issuableTimeTrackingResponse.data.workspace.issuable, ...issuableTimeTrackingResponse.data.workspace.issuable,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment