Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
026fdf37
Commit
026fdf37
authored
Dec 10, 2019
by
Martin Wortschack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set initial data when app is created
- Sets the startDate and endDate on the store
parent
d2fcec7d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
47 deletions
+110
-47
ee/app/assets/javascripts/analytics/productivity_analytics/components/app.vue
...ripts/analytics/productivity_analytics/components/app.vue
+0
-6
ee/app/assets/javascripts/analytics/productivity_analytics/index.js
...ets/javascripts/analytics/productivity_analytics/index.js
+18
-10
ee/app/assets/javascripts/analytics/productivity_analytics/store/modules/filters/actions.js
...s/productivity_analytics/store/modules/filters/actions.js
+13
-3
ee/app/assets/javascripts/analytics/productivity_analytics/store/modules/filters/mutation_types.js
...ctivity_analytics/store/modules/filters/mutation_types.js
+1
-0
ee/app/assets/javascripts/analytics/productivity_analytics/store/modules/filters/mutations.js
...productivity_analytics/store/modules/filters/mutations.js
+4
-0
ee/spec/frontend/analytics/productivity_analytics/components/app_spec.js
...d/analytics/productivity_analytics/components/app_spec.js
+7
-4
ee/spec/frontend/analytics/productivity_analytics/store/modules/filters/actions_spec.js
...ductivity_analytics/store/modules/filters/actions_spec.js
+46
-16
ee/spec/frontend/analytics/productivity_analytics/store/modules/filters/mutations_spec.js
...ctivity_analytics/store/modules/filters/mutations_spec.js
+21
-8
No files found.
ee/app/assets/javascripts/analytics/productivity_analytics/components/app.vue
View file @
026fdf37
...
@@ -34,10 +34,6 @@ export default {
...
@@ -34,10 +34,6 @@ export default {
},
},
mixins
:
[
featureFlagsMixin
()],
mixins
:
[
featureFlagsMixin
()],
props
:
{
props
:
{
endpoint
:
{
type
:
String
,
required
:
true
,
},
emptyStateSvgPath
:
{
emptyStateSvgPath
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
...
@@ -92,14 +88,12 @@ export default {
...
@@ -92,14 +88,12 @@ export default {
},
},
},
},
mounted
()
{
mounted
()
{
this
.
setEndpoint
(
this
.
endpoint
);
this
.
setChartEnabled
({
this
.
setChartEnabled
({
chartKey
:
chartKeys
.
scatterplot
,
chartKey
:
chartKeys
.
scatterplot
,
isEnabled
:
this
.
isScatterplotFeatureEnabled
(),
isEnabled
:
this
.
isScatterplotFeatureEnabled
(),
});
});
},
},
methods
:
{
methods
:
{
...
mapActions
([
'
setEndpoint
'
]),
...
mapActions
(
'
charts
'
,
[
...
mapActions
(
'
charts
'
,
[
'
fetchChartData
'
,
'
fetchChartData
'
,
'
setMetricType
'
,
'
setMetricType
'
,
...
...
ee/app/assets/javascripts/analytics/productivity_analytics/index.js
View file @
026fdf37
...
@@ -22,8 +22,13 @@ export default () => {
...
@@ -22,8 +22,13 @@ export default () => {
const
{
startDate
:
computedStartDate
}
=
timeframeContainer
.
dataset
;
const
{
startDate
:
computedStartDate
}
=
timeframeContainer
.
dataset
;
const
minDate
=
computedStartDate
?
new
Date
(
computedStartDate
)
:
null
;
const
minDate
=
computedStartDate
?
new
Date
(
computedStartDate
)
:
null
;
const
defaultStartDate
=
getDefaultStartDate
(
minDate
,
defaultDaysInPast
);
const
mergedAtAfter
=
getDefaultStartDate
(
minDate
,
defaultDaysInPast
);
const
defaultEndDate
=
new
Date
(
Date
.
now
());
const
mergedAtBefore
=
new
Date
(
Date
.
now
());
const
initialData
=
{
mergedAtAfter
,
mergedAtBefore
,
};
let
filterManager
;
let
filterManager
;
...
@@ -31,7 +36,16 @@ export default () => {
...
@@ -31,7 +36,16 @@ export default () => {
new
Vue
({
new
Vue
({
el
:
groupProjectSelectContainer
,
el
:
groupProjectSelectContainer
,
store
,
store
,
created
()
{
this
.
setEndpoint
(
endpoint
);
// let's not fetch data since we might not have a groupNamespace selected yet
// this just populates the store with the initial data and waits for a groupNamespace to be set
this
.
setInitialData
({
skipFetch
:
true
,
data
:
initialData
});
},
methods
:
{
methods
:
{
...
mapActions
([
'
setEndpoint
'
]),
...
mapActions
(
'
filters
'
,
[
'
setInitialData
'
]),
onGroupSelected
({
groupNamespace
,
groupId
})
{
onGroupSelected
({
groupNamespace
,
groupId
})
{
this
.
initFilteredSearch
({
groupNamespace
,
groupId
});
this
.
initFilteredSearch
({
groupNamespace
,
groupId
});
},
},
...
@@ -80,11 +94,6 @@ export default () => {
...
@@ -80,11 +94,6 @@ export default () => {
computed
:
{
computed
:
{
...
mapState
(
'
filters
'
,
[
'
groupNamespace
'
,
'
startDate
'
,
'
endDate
'
]),
...
mapState
(
'
filters
'
,
[
'
groupNamespace
'
,
'
startDate
'
,
'
endDate
'
]),
},
},
mounted
()
{
// let's not fetch data since we might not have a groupNamespace selected yet
// this just populates the store with the initial data and waits for a groupNamespace to be set
this
.
setDateRange
({
startDate
:
defaultStartDate
,
endDate
:
defaultEndDate
,
skipFetch
:
true
});
},
methods
:
{
methods
:
{
...
mapActions
(
'
filters
'
,
[
'
setDateRange
'
]),
...
mapActions
(
'
filters
'
,
[
'
setDateRange
'
]),
onDateRangeChange
({
startDate
,
endDate
})
{
onDateRangeChange
({
startDate
,
endDate
})
{
...
@@ -95,8 +104,8 @@ export default () => {
...
@@ -95,8 +104,8 @@ export default () => {
return
h
(
DateRange
,
{
return
h
(
DateRange
,
{
props
:
{
props
:
{
show
:
this
.
groupNamespace
!==
null
,
show
:
this
.
groupNamespace
!==
null
,
startDate
:
defaultStartDate
,
startDate
:
mergedAtAfter
,
endDate
:
defaultEndDat
e
,
endDate
:
mergedAtBefor
e
,
minDate
,
minDate
,
},
},
on
:
{
on
:
{
...
@@ -113,7 +122,6 @@ export default () => {
...
@@ -113,7 +122,6 @@ export default () => {
render
(
h
)
{
render
(
h
)
{
return
h
(
ProductivityAnalyticsApp
,
{
return
h
(
ProductivityAnalyticsApp
,
{
props
:
{
props
:
{
endpoint
,
emptyStateSvgPath
,
emptyStateSvgPath
,
noAccessSvgPath
,
noAccessSvgPath
,
},
},
...
...
ee/app/assets/javascripts/analytics/productivity_analytics/store/modules/filters/actions.js
View file @
026fdf37
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
{
chartKeys
}
from
'
../../../constants
'
;
import
{
chartKeys
}
from
'
../../../constants
'
;
export
const
setInitialData
=
({
commit
,
dispatch
},
{
skipFetch
=
false
,
data
})
=>
{
commit
(
types
.
SET_INITIAL_DATA
,
data
);
if
(
skipFetch
)
return
Promise
.
resolve
();
return
dispatch
(
'
charts/fetchChartData
'
,
chartKeys
.
main
,
{
root
:
true
}).
then
(()
=>
{
dispatch
(
'
charts/fetchSecondaryChartData
'
,
null
,
{
root
:
true
});
// let's reset the page on the MR table and fetch data
dispatch
(
'
table/setPage
'
,
0
,
{
root
:
true
});
});
};
export
const
setGroupNamespace
=
({
commit
,
dispatch
},
groupNamespace
)
=>
{
export
const
setGroupNamespace
=
({
commit
,
dispatch
},
groupNamespace
)
=>
{
commit
(
types
.
SET_GROUP_NAMESPACE
,
groupNamespace
);
commit
(
types
.
SET_GROUP_NAMESPACE
,
groupNamespace
);
...
@@ -48,11 +60,9 @@ export const setFilters = (
...
@@ -48,11 +60,9 @@ export const setFilters = (
});
});
};
};
export
const
setDateRange
=
({
commit
,
dispatch
},
{
s
kipFetch
=
false
,
s
tartDate
,
endDate
})
=>
{
export
const
setDateRange
=
({
commit
,
dispatch
},
{
startDate
,
endDate
})
=>
{
commit
(
types
.
SET_DATE_RANGE
,
{
startDate
,
endDate
});
commit
(
types
.
SET_DATE_RANGE
,
{
startDate
,
endDate
});
if
(
skipFetch
)
return
false
;
dispatch
(
'
charts/resetMainChartSelection
'
,
true
,
{
root
:
true
});
dispatch
(
'
charts/resetMainChartSelection
'
,
true
,
{
root
:
true
});
return
dispatch
(
'
charts/fetchChartData
'
,
chartKeys
.
main
,
{
root
:
true
}).
then
(()
=>
{
return
dispatch
(
'
charts/fetchChartData
'
,
chartKeys
.
main
,
{
root
:
true
}).
then
(()
=>
{
...
...
ee/app/assets/javascripts/analytics/productivity_analytics/store/modules/filters/mutation_types.js
View file @
026fdf37
export
const
SET_INITIAL_DATA
=
'
SET_INITIAL_DATA
'
;
export
const
SET_GROUP_NAMESPACE
=
'
SET_GROUP_NAMESPACE
'
;
export
const
SET_GROUP_NAMESPACE
=
'
SET_GROUP_NAMESPACE
'
;
export
const
SET_PROJECT_PATH
=
'
SET_PROJECT_PATH
'
;
export
const
SET_PROJECT_PATH
=
'
SET_PROJECT_PATH
'
;
export
const
SET_FILTERS
=
'
SET_FILTERS
'
;
export
const
SET_FILTERS
=
'
SET_FILTERS
'
;
...
...
ee/app/assets/javascripts/analytics/productivity_analytics/store/modules/filters/mutations.js
View file @
026fdf37
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
types
from
'
./mutation_types
'
;
export
default
{
export
default
{
[
types
.
SET_INITIAL_DATA
](
state
,
{
mergedAtAfter
,
mergedAtBefore
})
{
state
.
startDate
=
mergedAtAfter
;
state
.
endDate
=
mergedAtBefore
;
},
[
types
.
SET_GROUP_NAMESPACE
](
state
,
groupNamespace
)
{
[
types
.
SET_GROUP_NAMESPACE
](
state
,
groupNamespace
)
{
state
.
groupNamespace
=
groupNamespace
;
state
.
groupNamespace
=
groupNamespace
;
state
.
projectPath
=
null
;
state
.
projectPath
=
null
;
...
...
ee/spec/frontend/analytics/productivity_analytics/components/app_spec.js
View file @
026fdf37
...
@@ -19,7 +19,6 @@ describe('ProductivityApp component', () => {
...
@@ -19,7 +19,6 @@ describe('ProductivityApp component', () => {
let
mock
;
let
mock
;
const
propsData
=
{
const
propsData
=
{
endpoint
:
TEST_HOST
,
emptyStateSvgPath
:
TEST_HOST
,
emptyStateSvgPath
:
TEST_HOST
,
noAccessSvgPath
:
TEST_HOST
,
noAccessSvgPath
:
TEST_HOST
,
};
};
...
@@ -47,6 +46,8 @@ describe('ProductivityApp component', () => {
...
@@ -47,6 +46,8 @@ describe('ProductivityApp component', () => {
glFeatures
:
{
productivityAnalyticsScatterplotEnabled
:
scatterplotEnabled
},
glFeatures
:
{
productivityAnalyticsScatterplotEnabled
:
scatterplotEnabled
},
},
},
});
});
wrapper
.
vm
.
$store
.
dispatch
(
'
setEndpoint
'
,
TEST_HOST
);
};
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
...
@@ -83,10 +84,12 @@ describe('ProductivityApp component', () => {
...
@@ -83,10 +84,12 @@ describe('ProductivityApp component', () => {
describe
(
'
with a group being selected
'
,
()
=>
{
describe
(
'
with a group being selected
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
wrapper
.
vm
.
$store
.
dispatch
(
'
filters/set
DateRange
'
,
{
wrapper
.
vm
.
$store
.
dispatch
(
'
filters/set
InitialData
'
,
{
skipFetch
:
true
,
skipFetch
:
true
,
startDate
:
new
Date
(
'
2019-09-01
'
),
data
:
{
endDate
:
new
Date
(
'
2019-09-02
'
),
mergedAtAfter
:
new
Date
(
'
2019-09-01
'
),
mergedAtBefore
:
new
Date
(
'
2019-09-02
'
),
},
});
});
wrapper
.
vm
.
$store
.
dispatch
(
'
filters/setGroupNamespace
'
,
'
gitlab-org
'
);
wrapper
.
vm
.
$store
.
dispatch
(
'
filters/setGroupNamespace
'
,
'
gitlab-org
'
);
mock
.
onGet
(
wrapper
.
vm
.
$store
.
state
.
endpoint
).
replyOnce
(
200
);
mock
.
onGet
(
wrapper
.
vm
.
$store
.
state
.
endpoint
).
replyOnce
(
200
);
...
...
ee/spec/frontend/analytics/productivity_analytics/store/modules/filters/actions_spec.js
View file @
026fdf37
...
@@ -11,6 +11,10 @@ describe('Productivity analytics filter actions', () => {
...
@@ -11,6 +11,10 @@ describe('Productivity analytics filter actions', () => {
const
endDate
=
new
Date
(
currentYear
,
8
,
7
);
const
endDate
=
new
Date
(
currentYear
,
8
,
7
);
const
groupNamespace
=
'
gitlab-org
'
;
const
groupNamespace
=
'
gitlab-org
'
;
const
projectPath
=
'
gitlab-org/gitlab-test
'
;
const
projectPath
=
'
gitlab-org/gitlab-test
'
;
const
initialData
=
{
mergedAtAfter
:
new
Date
(
'
2019-11-01
'
),
mergedAtBefore
:
new
Date
(
'
2019-12-09
'
),
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
store
=
{
store
=
{
...
@@ -19,6 +23,47 @@ describe('Productivity analytics filter actions', () => {
...
@@ -19,6 +23,47 @@ describe('Productivity analytics filter actions', () => {
};
};
});
});
describe
(
'
setInitialData
'
,
()
=>
{
it
(
'
commits the SET_INITIAL_DATA mutation and fetches data by default
'
,
done
=>
{
actions
.
setInitialData
(
store
,
{
data
:
initialData
})
.
then
(()
=>
{
expect
(
store
.
commit
).
toHaveBeenCalledWith
(
types
.
SET_INITIAL_DATA
,
initialData
);
expect
(
store
.
dispatch
.
mock
.
calls
[
0
]).
toEqual
([
'
charts/fetchChartData
'
,
chartKeys
.
main
,
{
root
:
true
},
]);
expect
(
store
.
dispatch
.
mock
.
calls
[
1
]).
toEqual
([
'
charts/fetchSecondaryChartData
'
,
null
,
{
root
:
true
},
]);
expect
(
store
.
dispatch
.
mock
.
calls
[
2
]).
toEqual
([
'
table/setPage
'
,
0
,
{
root
:
true
}]);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
"
commits the SET_INITIAL_DATA mutation and doesn't fetch data when skipFetch=true
"
,
done
=>
testAction
(
actions
.
setInitialData
,
{
skipFetch
:
true
,
data
:
initialData
},
getInitialState
(),
[
{
type
:
types
.
SET_INITIAL_DATA
,
payload
:
initialData
,
},
],
[],
done
,
));
});
describe
(
'
setGroupNamespace
'
,
()
=>
{
describe
(
'
setGroupNamespace
'
,
()
=>
{
it
(
'
commits the SET_GROUP_NAMESPACE mutation
'
,
done
=>
{
it
(
'
commits the SET_GROUP_NAMESPACE mutation
'
,
done
=>
{
actions
actions
...
@@ -116,7 +161,7 @@ describe('Productivity analytics filter actions', () => {
...
@@ -116,7 +161,7 @@ describe('Productivity analytics filter actions', () => {
});
});
describe
(
'
setDateRange
'
,
()
=>
{
describe
(
'
setDateRange
'
,
()
=>
{
it
(
'
commits the SET_DATE_RANGE mutation
and fetches data by default
'
,
done
=>
{
it
(
'
commits the SET_DATE_RANGE mutation
'
,
done
=>
{
actions
actions
.
setDateRange
(
store
,
{
startDate
,
endDate
})
.
setDateRange
(
store
,
{
startDate
,
endDate
})
.
then
(()
=>
{
.
then
(()
=>
{
...
@@ -145,20 +190,5 @@ describe('Productivity analytics filter actions', () => {
...
@@ -145,20 +190,5 @@ describe('Productivity analytics filter actions', () => {
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
});
});
it
(
"
commits the SET_DATE_RANGE mutation and doesn't fetch data when skipFetch=true
"
,
done
=>
testAction
(
actions
.
setDateRange
,
{
skipFetch
:
true
,
startDate
,
endDate
},
getInitialState
(),
[
{
type
:
types
.
SET_DATE_RANGE
,
payload
:
{
startDate
,
endDate
},
},
],
[],
done
,
));
});
});
});
});
ee/spec/frontend/analytics/productivity_analytics/store/modules/filters/mutations_spec.js
View file @
026fdf37
...
@@ -4,14 +4,34 @@ import getInitialState from 'ee/analytics/productivity_analytics/store/modules/f
...
@@ -4,14 +4,34 @@ import getInitialState from 'ee/analytics/productivity_analytics/store/modules/f
describe
(
'
Productivity analytics filter mutations
'
,
()
=>
{
describe
(
'
Productivity analytics filter mutations
'
,
()
=>
{
let
state
;
let
state
;
const
groupNamespace
=
'
gitlab-org
'
;
const
projectPath
=
'
gitlab-org/gitlab-test
'
;
const
authorUsername
=
'
root
'
;
const
labelName
=
[
'
my label
'
,
'
yet another label
'
];
const
milestoneTitle
=
'
my milestone
'
;
const
currentYear
=
new
Date
().
getFullYear
();
const
startDate
=
new
Date
(
currentYear
,
8
,
1
);
const
endDate
=
new
Date
(
currentYear
,
8
,
7
);
beforeEach
(()
=>
{
beforeEach
(()
=>
{
state
=
getInitialState
();
state
=
getInitialState
();
});
});
describe
(
types
.
SET_INITIAL_DATA
,
()
=>
{
it
(
'
sets the initial data
'
,
()
=>
{
const
initialData
=
{
mergedAtAfter
:
startDate
,
mergedAtBefore
:
endDate
,
};
mutations
[
types
.
SET_INITIAL_DATA
](
state
,
initialData
);
expect
(
state
.
startDate
).
toBe
(
startDate
);
expect
(
state
.
endDate
).
toBe
(
endDate
);
});
});
describe
(
types
.
SET_GROUP_NAMESPACE
,
()
=>
{
describe
(
types
.
SET_GROUP_NAMESPACE
,
()
=>
{
it
(
'
sets the groupNamespace
'
,
()
=>
{
it
(
'
sets the groupNamespace
'
,
()
=>
{
const
groupNamespace
=
'
gitlab-org
'
;
mutations
[
types
.
SET_GROUP_NAMESPACE
](
state
,
groupNamespace
);
mutations
[
types
.
SET_GROUP_NAMESPACE
](
state
,
groupNamespace
);
expect
(
state
.
groupNamespace
).
toBe
(
groupNamespace
);
expect
(
state
.
groupNamespace
).
toBe
(
groupNamespace
);
...
@@ -20,7 +40,6 @@ describe('Productivity analytics filter mutations', () => {
...
@@ -20,7 +40,6 @@ describe('Productivity analytics filter mutations', () => {
describe
(
types
.
SET_PROJECT_PATH
,
()
=>
{
describe
(
types
.
SET_PROJECT_PATH
,
()
=>
{
it
(
'
sets the projectPath
'
,
()
=>
{
it
(
'
sets the projectPath
'
,
()
=>
{
const
projectPath
=
'
gitlab-org/gitlab-test
'
;
mutations
[
types
.
SET_PROJECT_PATH
](
state
,
projectPath
);
mutations
[
types
.
SET_PROJECT_PATH
](
state
,
projectPath
);
expect
(
state
.
projectPath
).
toBe
(
projectPath
);
expect
(
state
.
projectPath
).
toBe
(
projectPath
);
...
@@ -29,9 +48,6 @@ describe('Productivity analytics filter mutations', () => {
...
@@ -29,9 +48,6 @@ describe('Productivity analytics filter mutations', () => {
describe
(
types
.
SET_FILTERS
,
()
=>
{
describe
(
types
.
SET_FILTERS
,
()
=>
{
it
(
'
sets the authorUsername, milestoneTitle and labelName
'
,
()
=>
{
it
(
'
sets the authorUsername, milestoneTitle and labelName
'
,
()
=>
{
const
authorUsername
=
'
root
'
;
const
labelName
=
[
'
my label
'
,
'
yet another label
'
];
const
milestoneTitle
=
'
my milestone
'
;
mutations
[
types
.
SET_FILTERS
](
state
,
{
authorUsername
,
labelName
,
milestoneTitle
});
mutations
[
types
.
SET_FILTERS
](
state
,
{
authorUsername
,
labelName
,
milestoneTitle
});
expect
(
state
.
authorUsername
).
toBe
(
authorUsername
);
expect
(
state
.
authorUsername
).
toBe
(
authorUsername
);
...
@@ -42,9 +58,6 @@ describe('Productivity analytics filter mutations', () => {
...
@@ -42,9 +58,6 @@ describe('Productivity analytics filter mutations', () => {
describe
(
types
.
SET_DATE_RANGE
,
()
=>
{
describe
(
types
.
SET_DATE_RANGE
,
()
=>
{
it
(
'
sets the startDate and endDate
'
,
()
=>
{
it
(
'
sets the startDate and endDate
'
,
()
=>
{
const
currentYear
=
new
Date
().
getFullYear
();
const
startDate
=
new
Date
(
currentYear
,
8
,
1
);
const
endDate
=
new
Date
(
currentYear
,
8
,
7
);
mutations
[
types
.
SET_DATE_RANGE
](
state
,
{
startDate
,
endDate
});
mutations
[
types
.
SET_DATE_RANGE
](
state
,
{
startDate
,
endDate
});
expect
(
state
.
startDate
).
toBe
(
startDate
);
expect
(
state
.
startDate
).
toBe
(
startDate
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment