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
Show 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 {
...
@@ -28,11 +28,6 @@ export default {
};
};
},
},
methods
:
{
methods
:
{
fnCurrentTokenValue
(
data
)
{
// By default, values are transformed with `toLowerCase`
// however, runner tags are case sensitive.
return
data
;
},
getTagsOptions
(
search
)
{
getTagsOptions
(
search
)
{
// TODO This should be implemented via a GraphQL API
// TODO This should be implemented via a GraphQL API
// The API should
// The API should
...
@@ -72,7 +67,6 @@ export default {
...
@@ -72,7 +67,6 @@ export default {
:config=
"config"
:config=
"config"
:suggestions-loading=
"loading"
:suggestions-loading=
"loading"
:suggestions=
"tags"
:suggestions=
"tags"
:fn-current-token-value=
"fnCurrentTokenValue"
:recent-suggestions-storage-key=
"config.recentTokenValuesStorageKey"
:recent-suggestions-storage-key=
"config.recentTokenValuesStorageKey"
@
fetch-suggestions=
"fetchTags"
@
fetch-suggestions=
"fetchTags"
v-on=
"$listeners"
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 {
...
@@ -31,19 +31,25 @@ export default {
data
()
{
data
()
{
return
{
return
{
authors
:
this
.
config
.
initialAuthors
||
[],
authors
:
this
.
config
.
initialAuthors
||
[],
defaultAuthors
:
this
.
config
.
defaultAuthors
||
[
DEFAULT_LABEL_ANY
],
preloadedAuthors
:
this
.
config
.
preloadedAuthors
||
[],
loading
:
false
,
loading
:
false
,
};
};
},
},
computed
:
{
defaultAuthors
()
{
return
this
.
config
.
defaultAuthors
||
[
DEFAULT_LABEL_ANY
];
},
preloadedAuthors
()
{
return
this
.
config
.
preloadedAuthors
||
[];
},
},
methods
:
{
methods
:
{
getActiveAuthor
(
authors
,
currentValue
)
{
getActiveAuthor
(
authors
,
data
)
{
return
authors
.
find
((
author
)
=>
author
.
username
.
toLowerCase
()
===
currentValue
);
return
authors
.
find
((
author
)
=>
author
.
username
.
toLowerCase
()
===
data
.
toLowerCase
()
);
},
},
getAvatarUrl
(
author
)
{
getAvatarUrl
(
author
)
{
return
author
.
avatarUrl
||
author
.
avatar_url
;
return
author
.
avatarUrl
||
author
.
avatar_url
;
},
},
fetchAuthor
BySearchTerm
(
searchTerm
)
{
fetchAuthor
s
(
searchTerm
)
{
this
.
loading
=
true
;
this
.
loading
=
true
;
const
fetchPromise
=
this
.
config
.
fetchPath
const
fetchPromise
=
this
.
config
.
fetchPath
?
this
.
config
.
fetchAuthors
(
this
.
config
.
fetchPath
,
searchTerm
)
?
this
.
config
.
fetchAuthors
(
this
.
config
.
fetchPath
,
searchTerm
)
...
@@ -76,11 +82,11 @@ export default {
...
@@ -76,11 +82,11 @@ export default {
:active=
"active"
:active=
"active"
:suggestions-loading=
"loading"
:suggestions-loading=
"loading"
:suggestions=
"authors"
:suggestions=
"authors"
:
fn
-active-token-value=
"getActiveAuthor"
:
get
-active-token-value=
"getActiveAuthor"
:default-suggestions=
"defaultAuthors"
:default-suggestions=
"defaultAuthors"
:preloaded-suggestions=
"preloadedAuthors"
:preloaded-suggestions=
"preloadedAuthors"
:recent-suggestions-storage-key=
"config.recentSuggestionsStorageKey"
:recent-suggestions-storage-key=
"config.recentSuggestionsStorageKey"
@
fetch-suggestions=
"fetchAuthor
BySearchTerm
"
@
fetch-suggestions=
"fetchAuthor
s
"
v-on=
"$listeners"
v-on=
"$listeners"
>
>
<template
#view
="
{ viewTokenProps: { inputValue, activeTokenValue } }">
<template
#view
="
{ viewTokenProps: { inputValue, activeTokenValue } }">
...
@@ -91,7 +97,7 @@ export default {
...
@@ -91,7 +97,7 @@ export default {
shape=
"circle"
shape=
"circle"
class=
"gl-mr-2"
class=
"gl-mr-2"
/>
/>
<span>
{{
activeTokenValue
?
activeTokenValue
.
name
:
inputValue
}}
</span>
{{
activeTokenValue
?
activeTokenValue
.
name
:
inputValue
}}
</
template
>
</
template
>
<
template
#suggestions-list=
"{ suggestions }"
>
<
template
#suggestions-list=
"{ suggestions }"
>
<gl-filtered-search-suggestion
<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 {
...
@@ -42,12 +42,10 @@ export default {
required
:
false
,
required
:
false
,
default
:
()
=>
[],
default
:
()
=>
[],
},
},
fn
ActiveTokenValue
:
{
get
ActiveTokenValue
:
{
type
:
Function
,
type
:
Function
,
required
:
false
,
required
:
false
,
default
:
(
suggestions
,
currentTokenValue
)
=>
{
default
:
(
suggestions
,
data
)
=>
suggestions
.
find
(({
value
})
=>
value
===
data
),
return
suggestions
.
find
(({
value
})
=>
value
===
currentTokenValue
);
},
},
},
defaultSuggestions
:
{
defaultSuggestions
:
{
type
:
Array
,
type
:
Array
,
...
@@ -69,11 +67,6 @@ export default {
...
@@ -69,11 +67,6 @@ export default {
required
:
false
,
required
:
false
,
default
:
'
id
'
,
default
:
'
id
'
,
},
},
fnCurrentTokenValue
:
{
type
:
Function
,
required
:
false
,
default
:
null
,
},
},
},
data
()
{
data
()
{
return
{
return
{
...
@@ -81,7 +74,6 @@ export default {
...
@@ -81,7 +74,6 @@ export default {
recentSuggestions
:
this
.
recentSuggestionsStorageKey
recentSuggestions
:
this
.
recentSuggestionsStorageKey
?
getRecentlyUsedSuggestions
(
this
.
recentSuggestionsStorageKey
)
?
getRecentlyUsedSuggestions
(
this
.
recentSuggestionsStorageKey
)
:
[],
:
[],
loading
:
false
,
};
};
},
},
computed
:
{
computed
:
{
...
@@ -94,14 +86,8 @@ export default {
...
@@ -94,14 +86,8 @@ export default {
preloadedTokenIds
()
{
preloadedTokenIds
()
{
return
this
.
preloadedSuggestions
.
map
((
tokenValue
)
=>
tokenValue
[
this
.
valueIdentifier
]);
return
this
.
preloadedSuggestions
.
map
((
tokenValue
)
=>
tokenValue
[
this
.
valueIdentifier
]);
},
},
currentTokenValue
()
{
if
(
this
.
fnCurrentTokenValue
)
{
return
this
.
fnCurrentTokenValue
(
this
.
value
.
data
);
}
return
this
.
value
.
data
.
toLowerCase
();
},
activeTokenValue
()
{
activeTokenValue
()
{
return
this
.
fnActiveTokenValue
(
this
.
suggestions
,
this
.
currentTokenValue
);
return
this
.
getActiveTokenValue
(
this
.
suggestions
,
this
.
value
.
data
);
},
},
/**
/**
* Return all the suggestions when searchKey is present
* 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 {
...
@@ -33,14 +33,18 @@ export default {
data
()
{
data
()
{
return
{
return
{
labels
:
this
.
config
.
initialLabels
||
[],
labels
:
this
.
config
.
initialLabels
||
[],
defaultLabels
:
this
.
config
.
defaultLabels
||
DEFAULT_LABELS
,
loading
:
false
,
loading
:
false
,
};
};
},
},
computed
:
{
defaultLabels
()
{
return
this
.
config
.
defaultLabels
||
DEFAULT_LABELS
;
},
},
methods
:
{
methods
:
{
getActiveLabel
(
labels
,
currentValue
)
{
getActiveLabel
(
labels
,
data
)
{
return
labels
.
find
(
return
labels
.
find
(
(
label
)
=>
this
.
getLabelName
(
label
).
toLowerCase
()
===
stripQuotes
(
currentValue
),
(
label
)
=>
this
.
getLabelName
(
label
).
toLowerCase
()
===
stripQuotes
(
data
).
toLowerCase
(
),
);
);
},
},
/**
/**
...
@@ -68,7 +72,7 @@ export default {
...
@@ -68,7 +72,7 @@ export default {
}
}
return
{};
return
{};
},
},
fetchLabel
BySearchTerm
(
searchTerm
)
{
fetchLabel
s
(
searchTerm
)
{
this
.
loading
=
true
;
this
.
loading
=
true
;
this
.
config
this
.
config
.
fetchLabels
(
searchTerm
)
.
fetchLabels
(
searchTerm
)
...
@@ -98,10 +102,10 @@ export default {
...
@@ -98,10 +102,10 @@ export default {
:active=
"active"
:active=
"active"
:suggestions-loading=
"loading"
:suggestions-loading=
"loading"
:suggestions=
"labels"
:suggestions=
"labels"
:
fn
-active-token-value=
"getActiveLabel"
:
get
-active-token-value=
"getActiveLabel"
:default-suggestions=
"defaultLabels"
:default-suggestions=
"defaultLabels"
:recent-suggestions-storage-key=
"config.recentSuggestionsStorageKey"
:recent-suggestions-storage-key=
"config.recentSuggestionsStorageKey"
@
fetch-suggestions=
"fetchLabel
BySearchTerm
"
@
fetch-suggestions=
"fetchLabel
s
"
v-on=
"$listeners"
v-on=
"$listeners"
>
>
<template
<template
...
...
spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js
View file @
76945154
...
@@ -86,7 +86,7 @@ describe('AuthorToken', () => {
...
@@ -86,7 +86,7 @@ describe('AuthorToken', () => {
});
});
describe
(
'
methods
'
,
()
=>
{
describe
(
'
methods
'
,
()
=>
{
describe
(
'
fetchAuthor
BySearchTerm
'
,
()
=>
{
describe
(
'
fetchAuthor
s
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
wrapper
=
createComponent
();
wrapper
=
createComponent
();
});
});
...
@@ -155,7 +155,7 @@ describe('AuthorToken', () => {
...
@@ -155,7 +155,7 @@ describe('AuthorToken', () => {
expect
(
baseTokenEl
.
exists
()).
toBe
(
true
);
expect
(
baseTokenEl
.
exists
()).
toBe
(
true
);
expect
(
baseTokenEl
.
props
()).
toMatchObject
({
expect
(
baseTokenEl
.
props
()).
toMatchObject
({
suggestions
:
mockAuthors
,
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 = {
...
@@ -53,7 +53,6 @@ const mockProps = {
suggestionsLoading
:
false
,
suggestionsLoading
:
false
,
defaultSuggestions
:
DEFAULT_LABELS
,
defaultSuggestions
:
DEFAULT_LABELS
,
recentSuggestionsStorageKey
:
mockStorageKey
,
recentSuggestionsStorageKey
:
mockStorageKey
,
fnCurrentTokenValue
:
jest
.
fn
(),
};
};
function
createComponent
({
function
createComponent
({
...
@@ -99,31 +98,20 @@ describe('BaseToken', () => {
...
@@ -99,31 +98,20 @@ describe('BaseToken', () => {
});
});
describe
(
'
computed
'
,
()
=>
{
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
'
,
()
=>
{
describe
(
'
activeTokenValue
'
,
()
=>
{
it
(
'
calls `
fn
ActiveTokenValue` when it is provided
'
,
async
()
=>
{
it
(
'
calls `
get
ActiveTokenValue` when it is provided
'
,
async
()
=>
{
const
mock
Fn
ActiveTokenValue
=
jest
.
fn
();
const
mock
Get
ActiveTokenValue
=
jest
.
fn
();
wrapper
.
setProps
({
wrapper
.
setProps
({
fnActiveTokenValue
:
mockFnActiveTokenValue
,
getActiveTokenValue
:
mockGetActiveTokenValue
,
fnCurrentTokenValue
:
undefined
,
});
});
await
wrapper
.
vm
.
$nextTick
();
await
wrapper
.
vm
.
$nextTick
();
expect
(
mock
Fn
ActiveTokenValue
).
toHaveBeenCalledTimes
(
1
);
expect
(
mock
Get
ActiveTokenValue
).
toHaveBeenCalledTimes
(
1
);
expect
(
mock
Fn
ActiveTokenValue
).
toHaveBeenCalledWith
(
expect
(
mock
Get
ActiveTokenValue
).
toHaveBeenCalledWith
(
mockLabels
,
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', () => {
...
@@ -98,11 +98,11 @@ describe('LabelToken', () => {
});
});
});
});
describe
(
'
fetchLabel
BySearchTerm
'
,
()
=>
{
describe
(
'
fetchLabel
s
'
,
()
=>
{
it
(
'
calls `config.fetchLabels` with provided searchTerm param
'
,
()
=>
{
it
(
'
calls `config.fetchLabels` with provided searchTerm param
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
);
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
);
wrapper
.
vm
.
fetchLabel
BySearchTerm
(
'
foo
'
);
wrapper
.
vm
.
fetchLabel
s
(
'
foo
'
);
expect
(
wrapper
.
vm
.
config
.
fetchLabels
).
toHaveBeenCalledWith
(
'
foo
'
);
expect
(
wrapper
.
vm
.
config
.
fetchLabels
).
toHaveBeenCalledWith
(
'
foo
'
);
});
});
...
@@ -110,7 +110,7 @@ describe('LabelToken', () => {
...
@@ -110,7 +110,7 @@ describe('LabelToken', () => {
it
(
'
sets response to `labels` when request is succesful
'
,
()
=>
{
it
(
'
sets response to `labels` when request is succesful
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockResolvedValue
(
mockLabels
);
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockResolvedValue
(
mockLabels
);
wrapper
.
vm
.
fetchLabel
BySearchTerm
(
'
foo
'
);
wrapper
.
vm
.
fetchLabel
s
(
'
foo
'
);
return
waitForPromises
().
then
(()
=>
{
return
waitForPromises
().
then
(()
=>
{
expect
(
wrapper
.
vm
.
labels
).
toEqual
(
mockLabels
);
expect
(
wrapper
.
vm
.
labels
).
toEqual
(
mockLabels
);
...
@@ -120,7 +120,7 @@ describe('LabelToken', () => {
...
@@ -120,7 +120,7 @@ describe('LabelToken', () => {
it
(
'
calls `createFlash` with flash error message when request fails
'
,
()
=>
{
it
(
'
calls `createFlash` with flash error message when request fails
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockRejectedValue
({});
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockRejectedValue
({});
wrapper
.
vm
.
fetchLabel
BySearchTerm
(
'
foo
'
);
wrapper
.
vm
.
fetchLabel
s
(
'
foo
'
);
return
waitForPromises
().
then
(()
=>
{
return
waitForPromises
().
then
(()
=>
{
expect
(
createFlash
).
toHaveBeenCalledWith
({
expect
(
createFlash
).
toHaveBeenCalledWith
({
...
@@ -132,7 +132,7 @@ describe('LabelToken', () => {
...
@@ -132,7 +132,7 @@ describe('LabelToken', () => {
it
(
'
sets `loading` to false when request completes
'
,
()
=>
{
it
(
'
sets `loading` to false when request completes
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockRejectedValue
({});
jest
.
spyOn
(
wrapper
.
vm
.
config
,
'
fetchLabels
'
).
mockRejectedValue
({});
wrapper
.
vm
.
fetchLabel
BySearchTerm
(
'
foo
'
);
wrapper
.
vm
.
fetchLabel
s
(
'
foo
'
);
return
waitForPromises
().
then
(()
=>
{
return
waitForPromises
().
then
(()
=>
{
expect
(
wrapper
.
vm
.
loading
).
toBe
(
false
);
expect
(
wrapper
.
vm
.
loading
).
toBe
(
false
);
...
@@ -160,7 +160,7 @@ describe('LabelToken', () => {
...
@@ -160,7 +160,7 @@ describe('LabelToken', () => {
expect
(
baseTokenEl
.
exists
()).
toBe
(
true
);
expect
(
baseTokenEl
.
exists
()).
toBe
(
true
);
expect
(
baseTokenEl
.
props
()).
toMatchObject
({
expect
(
baseTokenEl
.
props
()).
toMatchObject
({
suggestions
:
mockLabels
,
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