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
76945154
Commit
76945154
authored
Aug 13, 2021
by
Coung Ngo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do minor refactor of filtered tokens
Do some identifier renamings etc to increase readability
parent
61975014
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
63 deletions
+41
-63
app/assets/javascripts/runner/components/search_tokens/tag_token.vue
...javascripts/runner/components/search_tokens/tag_token.vue
+0
-6
app/assets/javascripts/vue_shared/components/filtered_search_bar/tokens/author_token.vue
...ed/components/filtered_search_bar/tokens/author_token.vue
+14
-8
app/assets/javascripts/vue_shared/components/filtered_search_bar/tokens/base_token.vue
...ared/components/filtered_search_bar/tokens/base_token.vue
+3
-17
app/assets/javascripts/vue_shared/components/filtered_search_bar/tokens/label_token.vue
...red/components/filtered_search_bar/tokens/label_token.vue
+10
-6
spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js
...omponents/filtered_search_bar/tokens/author_token_spec.js
+2
-2
spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js
.../components/filtered_search_bar/tokens/base_token_spec.js
+6
-18
spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js
...components/filtered_search_bar/tokens/label_token_spec.js
+6
-6
No files found.
app/assets/javascripts/runner/components/search_tokens/tag_token.vue
View file @
76945154
...
...
@@ -28,11 +28,6 @@ export default {
};
},
methods
:
{
fnCurrentTokenValue
(
data
)
{
// By default, values are transformed with `toLowerCase`
// however, runner tags are case sensitive.
return
data
;
},
getTagsOptions
(
search
)
{
// TODO This should be implemented via a GraphQL API
// The API should
...
...
@@ -72,7 +67,6 @@ export default {
:config=
"config"
:suggestions-loading=
"loading"
:suggestions=
"tags"
:fn-current-token-value=
"fnCurrentTokenValue"
:recent-suggestions-storage-key=
"config.recentTokenValuesStorageKey"
@
fetch-suggestions=
"fetchTags"
v-on=
"$listeners"
...
...
app/assets/javascripts/vue_shared/components/filtered_search_bar/tokens/author_token.vue
View file @
76945154
...
...
@@ -31,19 +31,25 @@ export default {
data
()
{
return
{
authors
:
this
.
config
.
initialAuthors
||
[],
defaultAuthors
:
this
.
config
.
defaultAuthors
||
[
DEFAULT_LABEL_ANY
],
preloadedAuthors
:
this
.
config
.
preloadedAuthors
||
[],
loading
:
false
,
};
},
computed
:
{
defaultAuthors
()
{
return
this
.
config
.
defaultAuthors
||
[
DEFAULT_LABEL_ANY
];
},
preloadedAuthors
()
{
return
this
.
config
.
preloadedAuthors
||
[];
},
},
methods
:
{
getActiveAuthor
(
authors
,
currentValue
)
{
return
authors
.
find
((
author
)
=>
author
.
username
.
toLowerCase
()
===
currentValue
);
getActiveAuthor
(
authors
,
data
)
{
return
authors
.
find
((
author
)
=>
author
.
username
.
toLowerCase
()
===
data
.
toLowerCase
()
);
},
getAvatarUrl
(
author
)
{
return
author
.
avatarUrl
||
author
.
avatar_url
;
},
fetchAuthor
BySearchTerm
(
searchTerm
)
{
fetchAuthor
s
(
searchTerm
)
{
this
.
loading
=
true
;
const
fetchPromise
=
this
.
config
.
fetchPath
?
this
.
config
.
fetchAuthors
(
this
.
config
.
fetchPath
,
searchTerm
)
...
...
@@ -76,11 +82,11 @@ export default {
:active=
"active"
:suggestions-loading=
"loading"
:suggestions=
"authors"
:
fn
-active-token-value=
"getActiveAuthor"
:
get
-active-token-value=
"getActiveAuthor"
:default-suggestions=
"defaultAuthors"
:preloaded-suggestions=
"preloadedAuthors"
:recent-suggestions-storage-key=
"config.recentSuggestionsStorageKey"
@
fetch-suggestions=
"fetchAuthor
BySearchTerm
"
@
fetch-suggestions=
"fetchAuthor
s
"
v-on=
"$listeners"
>
<template
#view
="
{ viewTokenProps: { inputValue, activeTokenValue } }">
...
...
@@ -91,7 +97,7 @@ export default {
shape=
"circle"
class=
"gl-mr-2"
/>
<span>
{{
activeTokenValue
?
activeTokenValue
.
name
:
inputValue
}}
</span>
{{
activeTokenValue
?
activeTokenValue
.
name
:
inputValue
}}
</
template
>
<
template
#suggestions-list=
"{ suggestions }"
>
<gl-filtered-search-suggestion
...
...
app/assets/javascripts/vue_shared/components/filtered_search_bar/tokens/base_token.vue
View file @
76945154
...
...
@@ -42,12 +42,10 @@ export default {
required
:
false
,
default
:
()
=>
[],
},
fn
ActiveTokenValue
:
{
get
ActiveTokenValue
:
{
type
:
Function
,
required
:
false
,
default
:
(
suggestions
,
currentTokenValue
)
=>
{
return
suggestions
.
find
(({
value
})
=>
value
===
currentTokenValue
);
},
default
:
(
suggestions
,
data
)
=>
suggestions
.
find
(({
value
})
=>
value
===
data
),
},
defaultSuggestions
:
{
type
:
Array
,
...
...
@@ -69,11 +67,6 @@ export default {
required
:
false
,
default
:
'
id
'
,
},
fnCurrentTokenValue
:
{
type
:
Function
,
required
:
false
,
default
:
null
,
},
},
data
()
{
return
{
...
...
@@ -81,7 +74,6 @@ export default {
recentSuggestions
:
this
.
recentSuggestionsStorageKey
?
getRecentlyUsedSuggestions
(
this
.
recentSuggestionsStorageKey
)
:
[],
loading
:
false
,
};
},
computed
:
{
...
...
@@ -94,14 +86,8 @@ export default {
preloadedTokenIds
()
{
return
this
.
preloadedSuggestions
.
map
((
tokenValue
)
=>
tokenValue
[
this
.
valueIdentifier
]);
},
currentTokenValue
()
{
if
(
this
.
fnCurrentTokenValue
)
{
return
this
.
fnCurrentTokenValue
(
this
.
value
.
data
);
}
return
this
.
value
.
data
.
toLowerCase
();
},
activeTokenValue
()
{
return
this
.
fnActiveTokenValue
(
this
.
suggestions
,
this
.
currentTokenValue
);
return
this
.
getActiveTokenValue
(
this
.
suggestions
,
this
.
value
.
data
);
},
/**
* Return all the suggestions when searchKey is present
...
...
app/assets/javascripts/vue_shared/components/filtered_search_bar/tokens/label_token.vue
View file @
76945154
...
...
@@ -33,14 +33,18 @@ export default {
data
()
{
return
{
labels
:
this
.
config
.
initialLabels
||
[],
defaultLabels
:
this
.
config
.
defaultLabels
||
DEFAULT_LABELS
,
loading
:
false
,
};
},
computed
:
{
defaultLabels
()
{
return
this
.
config
.
defaultLabels
||
DEFAULT_LABELS
;
},
},
methods
:
{
getActiveLabel
(
labels
,
currentValue
)
{
getActiveLabel
(
labels
,
data
)
{
return
labels
.
find
(
(
label
)
=>
this
.
getLabelName
(
label
).
toLowerCase
()
===
stripQuotes
(
currentValue
),
(
label
)
=>
this
.
getLabelName
(
label
).
toLowerCase
()
===
stripQuotes
(
data
).
toLowerCase
(
),
);
},
/**
...
...
@@ -68,7 +72,7 @@ export default {
}
return
{};
},
fetchLabel
BySearchTerm
(
searchTerm
)
{
fetchLabel
s
(
searchTerm
)
{
this
.
loading
=
true
;
this
.
config
.
fetchLabels
(
searchTerm
)
...
...
@@ -98,10 +102,10 @@ export default {
:active=
"active"
:suggestions-loading=
"loading"
:suggestions=
"labels"
:
fn
-active-token-value=
"getActiveLabel"
:
get
-active-token-value=
"getActiveLabel"
:default-suggestions=
"defaultLabels"
:recent-suggestions-storage-key=
"config.recentSuggestionsStorageKey"
@
fetch-suggestions=
"fetchLabel
BySearchTerm
"
@
fetch-suggestions=
"fetchLabel
s
"
v-on=
"$listeners"
>
<template
...
...
spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js
View file @
76945154
...
...
@@ -86,7 +86,7 @@ describe('AuthorToken', () => {
});
describe
(
'
methods
'
,
()
=>
{
describe
(
'
fetchAuthor
BySearchTerm
'
,
()
=>
{
describe
(
'
fetchAuthor
s
'
,
()
=>
{
beforeEach
(()
=>
{
wrapper
=
createComponent
();
});
...
...
@@ -155,7 +155,7 @@ describe('AuthorToken', () => {
expect
(
baseTokenEl
.
exists
()).
toBe
(
true
);
expect
(
baseTokenEl
.
props
()).
toMatchObject
({
suggestions
:
mockAuthors
,
fn
ActiveTokenValue
:
wrapper
.
vm
.
getActiveAuthor
,
get
ActiveTokenValue
:
wrapper
.
vm
.
getActiveAuthor
,
});
});
...
...
spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js
View file @
76945154
...
...
@@ -53,7 +53,6 @@ const mockProps = {
suggestionsLoading
:
false
,
defaultSuggestions
:
DEFAULT_LABELS
,
recentSuggestionsStorageKey
:
mockStorageKey
,
fnCurrentTokenValue
:
jest
.
fn
(),
};
function
createComponent
({
...
...
@@ -99,31 +98,20 @@ describe('BaseToken', () => {
});
describe
(
'
computed
'
,
()
=>
{
describe
(
'
currentTokenValue
'
,
()
=>
{
it
(
'
calls `fnCurrentTokenValue` when it is provided
'
,
()
=>
{
// We're disabling lint to trigger computed prop execution for this test.
// eslint-disable-next-line no-unused-vars
const
{
currentTokenValue
}
=
wrapper
.
vm
;
expect
(
wrapper
.
vm
.
fnCurrentTokenValue
).
toHaveBeenCalledWith
(
`"
${
mockRegularLabel
.
title
}
"`
);
});
});
describe
(
'
activeTokenValue
'
,
()
=>
{
it
(
'
calls `
fn
ActiveTokenValue` when it is provided
'
,
async
()
=>
{
const
mock
Fn
ActiveTokenValue
=
jest
.
fn
();
it
(
'
calls `
get
ActiveTokenValue` when it is provided
'
,
async
()
=>
{
const
mock
Get
ActiveTokenValue
=
jest
.
fn
();
wrapper
.
setProps
({
fnActiveTokenValue
:
mockFnActiveTokenValue
,
fnCurrentTokenValue
:
undefined
,
getActiveTokenValue
:
mockGetActiveTokenValue
,
});
await
wrapper
.
vm
.
$nextTick
();
expect
(
mock
Fn
ActiveTokenValue
).
toHaveBeenCalledTimes
(
1
);
expect
(
mock
Fn
ActiveTokenValue
).
toHaveBeenCalledWith
(
expect
(
mock
Get
ActiveTokenValue
).
toHaveBeenCalledTimes
(
1
);
expect
(
mock
Get
ActiveTokenValue
).
toHaveBeenCalledWith
(
mockLabels
,
`"
${
mockRegularLabel
.
title
.
toLowerCase
()
}
"`
,
`"
${
mockRegularLabel
.
title
}
"`
,
);
});
});
...
...
spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js
View file @
76945154
...
...
@@ -98,11 +98,11 @@ describe('LabelToken', () => {
});
});
describe
(
'
fetchLabel
BySearchTerm
'
,
()
=>
{
describe
(
'
fetchLabel
s
'
,
()
=>
{
it
(
'
calls `config.fetchLabels` with provided searchTerm param
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
);
wrapper
.
vm
.
fetchLabel
BySearchTerm
(
'
foo
'
);
wrapper
.
vm
.
fetchLabel
s
(
'
foo
'
);
expect
(
wrapper
.
vm
.
config
.
fetchLabels
).
toHaveBeenCalledWith
(
'
foo
'
);
});
...
...
@@ -110,7 +110,7 @@ describe('LabelToken', () => {
it
(
'
sets response to `labels` when request is succesful
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockResolvedValue
(
mockLabels
);
wrapper
.
vm
.
fetchLabel
BySearchTerm
(
'
foo
'
);
wrapper
.
vm
.
fetchLabel
s
(
'
foo
'
);
return
waitForPromises
().
then
(()
=>
{
expect
(
wrapper
.
vm
.
labels
).
toEqual
(
mockLabels
);
...
...
@@ -120,7 +120,7 @@ describe('LabelToken', () => {
it
(
'
calls `createFlash` with flash error message when request fails
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockRejectedValue
({});
wrapper
.
vm
.
fetchLabel
BySearchTerm
(
'
foo
'
);
wrapper
.
vm
.
fetchLabel
s
(
'
foo
'
);
return
waitForPromises
().
then
(()
=>
{
expect
(
createFlash
).
toHaveBeenCalledWith
({
...
...
@@ -132,7 +132,7 @@ describe('LabelToken', () => {
it
(
'
sets `loading` to false when request completes
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockRejectedValue
({});
wrapper
.
vm
.
fetchLabel
BySearchTerm
(
'
foo
'
);
wrapper
.
vm
.
fetchLabel
s
(
'
foo
'
);
return
waitForPromises
().
then
(()
=>
{
expect
(
wrapper
.
vm
.
loading
).
toBe
(
false
);
...
...
@@ -160,7 +160,7 @@ describe('LabelToken', () => {
expect
(
baseTokenEl
.
exists
()).
toBe
(
true
);
expect
(
baseTokenEl
.
props
()).
toMatchObject
({
suggestions
:
mockLabels
,
fn
ActiveTokenValue
:
wrapper
.
vm
.
getActiveLabel
,
get
ActiveTokenValue
:
wrapper
.
vm
.
getActiveLabel
,
});
});
...
...
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