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
3589b902
Commit
3589b902
authored
Sep 26, 2019
by
Winnie Hellmann
Committed by
Mike Greiling
Sep 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract isEpic getter in related items tree store
parent
a15e2bbc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
36 deletions
+42
-36
ee/app/assets/javascripts/related_items_tree/store/actions.js
...pp/assets/javascripts/related_items_tree/store/actions.js
+13
-22
ee/app/assets/javascripts/related_items_tree/store/getters.js
...pp/assets/javascripts/related_items_tree/store/getters.js
+5
-3
ee/spec/frontend/related_items_tree/store/getters_spec.js
ee/spec/frontend/related_items_tree/store/getters_spec.js
+15
-7
ee/spec/javascripts/related_items_tree/store/actions_spec.js
ee/spec/javascripts/related_items_tree/store/actions_spec.js
+9
-4
No files found.
ee/app/assets/javascripts/related_items_tree/store/actions.js
View file @
3589b902
...
...
@@ -256,18 +256,17 @@ export const removePendingReference = ({ commit }, data) =>
export
const
setItemInputValue
=
({
commit
},
data
)
=>
commit
(
types
.
SET_ITEM_INPUT_VALUE
,
data
);
export
const
requestAddItem
=
({
commit
})
=>
commit
(
types
.
REQUEST_ADD_ITEM
);
export
const
receiveAddItemSuccess
=
({
dispatch
,
commit
,
getters
},
{
actionType
,
rawItems
})
=>
{
const
isEpic
=
actionType
===
ActionType
.
Epic
;
export
const
receiveAddItemSuccess
=
({
dispatch
,
commit
,
getters
,
state
},
{
rawItems
})
=>
{
const
items
=
rawItems
.
map
(
item
=>
formatChildItem
({
...
convertObjectPropsToCamelCase
(
item
,
{
deep
:
!
isEpic
}),
type
:
isEpic
?
ChildType
.
Epic
:
ChildType
.
Issue
,
userPermissions
:
isEpic
?
{
adminEpic
:
item
.
can_admin
}
:
{},
...
convertObjectPropsToCamelCase
(
item
,
{
deep
:
!
getters
.
isEpic
}),
type
:
getters
.
isEpic
?
ChildType
.
Epic
:
ChildType
.
Issue
,
userPermissions
:
getters
.
isEpic
?
{
adminEpic
:
item
.
can_admin
}
:
{},
}),
);
commit
(
types
.
RECEIVE_ADD_ITEM_SUCCESS
,
{
insertAt
:
isEpic
?
0
:
getters
.
issuesBeginAtIndex
,
insertAt
:
getters
.
isEpic
?
0
:
getters
.
issuesBeginAtIndex
,
items
,
});
...
...
@@ -281,7 +280,7 @@ export const receiveAddItemSuccess = ({ dispatch, commit, getters }, { actionTyp
dispatch
(
'
setPendingReferences
'
,
[]);
dispatch
(
'
setItemInputValue
'
,
''
);
dispatch
(
'
toggleAddItemForm
'
,
{
actionType
,
actionType
:
state
.
actionType
,
toggleState
:
false
,
});
};
...
...
@@ -294,16 +293,15 @@ export const receiveAddItemFailure = ({ commit, state }, data = {}) => {
}
flash
(
errorMessage
);
};
export
const
addItem
=
({
state
,
dispatch
})
=>
{
export
const
addItem
=
({
state
,
dispatch
,
getters
})
=>
{
dispatch
(
'
requestAddItem
'
);
axios
.
post
(
state
.
actionType
===
ActionType
.
Epic
?
state
.
epicsEndpoint
:
state
.
issuesEndpoint
,
{
.
post
(
getters
.
is
Epic
?
state
.
epicsEndpoint
:
state
.
issuesEndpoint
,
{
issuable_references
:
state
.
pendingReferences
,
})
.
then
(({
data
})
=>
{
dispatch
(
'
receiveAddItemSuccess
'
,
{
actionType
:
state
.
actionType
,
// Newly added item is always first in the list
rawItems
:
data
.
issuables
.
slice
(
0
,
state
.
pendingReferences
.
length
),
});
...
...
@@ -314,14 +312,10 @@ export const addItem = ({ state, dispatch }) => {
};
export
const
requestCreateItem
=
({
commit
})
=>
commit
(
types
.
REQUEST_CREATE_ITEM
);
export
const
receiveCreateItemSuccess
=
(
{
state
,
commit
,
dispatch
,
getters
},
{
actionType
,
rawItem
},
)
=>
{
const
isEpic
=
actionType
===
ActionType
.
Epic
;
export
const
receiveCreateItemSuccess
=
({
state
,
commit
,
dispatch
,
getters
},
{
rawItem
})
=>
{
const
item
=
formatChildItem
({
...
convertObjectPropsToCamelCase
(
rawItem
,
{
deep
:
!
isEpic
}),
type
:
isEpic
?
ChildType
.
Epic
:
ChildType
.
Issue
,
...
convertObjectPropsToCamelCase
(
rawItem
,
{
deep
:
!
getters
.
isEpic
}),
type
:
getters
.
isEpic
?
ChildType
.
Epic
:
ChildType
.
Issue
,
// This is needed since Rails API to create Epic
// doesn't return global ID, we can remove this
// change once create epic action is moved to
...
...
@@ -343,7 +337,7 @@ export const receiveCreateItemSuccess = (
});
dispatch
(
'
toggleCreateEpicForm
'
,
{
actionType
,
actionType
:
state
.
actionType
,
toggleState
:
false
,
});
};
...
...
@@ -368,10 +362,7 @@ export const createItem = ({ state, dispatch }, { itemTitle }) => {
created_at
:
''
,
});
dispatch
(
'
receiveCreateItemSuccess
'
,
{
actionType
:
state
.
actionType
,
rawItem
:
data
,
});
dispatch
(
'
receiveCreateItemSuccess
'
,
{
rawItem
:
data
});
})
.
catch
(()
=>
{
dispatch
(
'
receiveCreateItemFailure
'
);
...
...
ee/app/assets/javascripts/related_items_tree/store/getters.js
View file @
3589b902
...
...
@@ -27,7 +27,7 @@ export const issuesBeginAtIndex = (state, getters) =>
getters
.
directChildren
.
findIndex
(
item
=>
item
.
type
===
ChildType
.
Issue
);
export
const
itemAutoCompleteSources
=
(
state
,
getters
)
=>
{
if
(
state
.
actionType
===
ActionType
.
Epic
)
{
if
(
getters
.
is
Epic
)
{
return
state
.
autoCompleteEpics
?
getters
.
autoCompleteSources
:
{};
}
return
state
.
autoCompleteIssues
?
getters
.
autoCompleteSources
:
{};
...
...
@@ -45,8 +45,10 @@ export const issuableType = state => {
return
null
;
};
export
const
itemPathIdSeparator
=
state
=>
state
.
actionType
===
ActionType
.
Epic
?
PathIdSeparator
.
Epic
:
PathIdSeparator
.
Issue
;
export
const
itemPathIdSeparator
=
(
state
,
getters
)
=>
getters
.
isEpic
?
PathIdSeparator
.
Epic
:
PathIdSeparator
.
Issue
;
export
const
isEpic
=
state
=>
state
.
actionType
===
ActionType
.
Epic
;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export
default
()
=>
{};
ee/spec/frontend/related_items_tree/store/getters_spec.js
View file @
3589b902
...
...
@@ -113,6 +113,7 @@ describe('RelatedItemsTree', () => {
it
(
'
returns autoCompleteSources value when `actionType` is set to `Epic` and `autoCompleteEpics` is true
'
,
()
=>
{
const
mockGetter
=
{
autoCompleteSources
:
'
foo
'
,
isEpic
:
true
,
};
state
.
actionType
=
ActionType
.
Epic
;
state
.
autoCompleteEpics
=
true
;
...
...
@@ -155,16 +156,23 @@ describe('RelatedItemsTree', () => {
});
describe
(
'
itemPathIdSeparator
'
,
()
=>
{
it
(
'
returns string containing pathIdSeparator for `Epic` when `state.actionType` is set to `Epic`
'
,
()
=>
{
state
.
actionType
=
ActionType
.
Epic
;
expect
(
getters
.
itemPathIdSeparator
(
state
)).
toBe
(
'
&
'
);
it
(
'
returns string containing pathIdSeparator for `Epic` when isEpic is truee
'
,
()
=>
{
expect
(
getters
.
itemPathIdSeparator
({},
{
isEpic
:
true
})).
toBe
(
'
&
'
);
});
it
(
'
returns string containing pathIdSeparator for `Issue` when `state.actionType` is set to `Issue`
'
,
()
=>
{
state
.
actionType
=
ActionType
.
Issue
;
it
(
'
returns string containing pathIdSeparator for `Issue` when isEpic is false
'
,
()
=>
{
expect
(
getters
.
itemPathIdSeparator
({},
{
isEpic
:
false
})).
toBe
(
'
#
'
);
});
});
expect
(
getters
.
itemPathIdSeparator
(
state
)).
toBe
(
'
#
'
);
describe
(
'
isEpic
'
,
()
=>
{
it
.
each
`
actionType | expectedValue
${
null
}
|
${
false
}
${
ActionType
.
Issue
}
|
${
false
}
${
ActionType
.
Epic
}
|
${
true
}
`
(
'
for actionType = $actionType is $expectedValue
'
,
({
actionType
,
expectedValue
})
=>
{
expect
(
getters
.
isEpic
({
actionType
})).
toBe
(
expectedValue
);
});
});
});
...
...
ee/spec/javascripts/related_items_tree/store/actions_spec.js
View file @
3589b902
...
...
@@ -806,6 +806,9 @@ describe('RelatedItemTree', () => {
describe
(
'
receiveAddItemSuccess
'
,
()
=>
{
it
(
'
should set `state.itemAddInProgress` to false and dispatches actions `setPendingReferences`, `setItemInputValue` and `toggleAddItemForm`
'
,
done
=>
{
state
.
epicsBeginAtIndex
=
0
;
state
.
actionType
=
ActionType
.
Epic
;
state
.
isEpic
=
true
;
const
mockEpicsWithoutPerm
=
mockEpics
.
map
(
item
=>
Object
.
assign
({},
item
,
{
pathIdSeparator
:
PathIdSeparator
.
Epic
,
...
...
@@ -815,7 +818,7 @@ describe('RelatedItemTree', () => {
testAction
(
actions
.
receiveAddItemSuccess
,
{
actionType
:
ActionType
.
Epic
,
rawItems
:
mockEpicsWithoutPerm
},
{
rawItems
:
mockEpicsWithoutPerm
},
state
,
[
{
...
...
@@ -906,6 +909,7 @@ describe('RelatedItemTree', () => {
state
.
actionType
=
ActionType
.
Epic
;
state
.
epicsEndpoint
=
'
/foo/bar
'
;
state
.
pendingReferences
=
[
'
foo
'
];
state
.
isEpic
=
true
;
mock
.
onPost
(
state
.
epicsEndpoint
).
replyOnce
(
200
,
{
issuables
:
[
mockEpic1
]
});
...
...
@@ -920,7 +924,7 @@ describe('RelatedItemTree', () => {
},
{
type
:
'
receiveAddItemSuccess
'
,
payload
:
{
actionType
:
ActionType
.
Epic
,
rawItems
:
[
mockEpic1
]
},
payload
:
{
rawItems
:
[
mockEpic1
]
},
},
],
done
,
...
...
@@ -976,10 +980,12 @@ describe('RelatedItemTree', () => {
state
.
parentItem
=
{
fullPath
:
createdEpic
.
group
.
fullPath
,
};
state
.
actionType
=
ActionType
.
Epic
;
state
.
isEpic
=
true
;
testAction
(
actions
.
receiveCreateItemSuccess
,
{
rawItem
:
mockEpic1
,
actionType
:
ActionType
.
Epic
},
{
rawItem
:
mockEpic1
},
state
,
[
{
...
...
@@ -1068,7 +1074,6 @@ describe('RelatedItemTree', () => {
{
type
:
'
receiveCreateItemSuccess
'
,
payload
:
{
actionType
:
ActionType
.
Epic
,
rawItem
:
Object
.
assign
({},
mockEpic1
,
{
path
:
''
,
state
:
ChildState
.
Open
,
...
...
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