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
1e58e447
Commit
1e58e447
authored
Sep 18, 2020
by
Ethan Reesor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use fuzzy matching for issuable awards
parent
9e72553a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
10 deletions
+49
-10
app/assets/javascripts/awards_handler.js
app/assets/javascripts/awards_handler.js
+1
-1
app/assets/javascripts/emoji/index.js
app/assets/javascripts/emoji/index.js
+13
-7
changelogs/unreleased/issuable-award-fuzzy-search.yml
changelogs/unreleased/issuable-award-fuzzy-search.yml
+5
-0
spec/frontend/awards_handler_spec.js
spec/frontend/awards_handler_spec.js
+10
-0
spec/frontend/emoji/emoji_spec.js
spec/frontend/emoji/emoji_spec.js
+20
-2
No files found.
app/assets/javascripts/awards_handler.js
View file @
1e58e447
...
...
@@ -572,7 +572,7 @@ export class AwardsHandler {
}
findMatchingEmojiElements
(
query
)
{
const
emojiMatches
=
this
.
emoji
.
filterEmojiNamesByAlia
s
(
query
);
const
emojiMatches
=
this
.
emoji
.
queryEmojiName
s
(
query
);
const
$emojiElements
=
$
(
'
.emoji-menu-list:not(.frequent-emojis) [data-name]
'
);
const
$matchingElements
=
$emojiElements
.
filter
(
(
i
,
elm
)
=>
emojiMatches
.
indexOf
(
elm
.
dataset
.
name
)
>=
0
,
...
...
app/assets/javascripts/emoji/index.js
View file @
1e58e447
import
{
uniq
}
from
'
lodash
'
;
import
fuzzaldrinPlus
from
'
fuzzaldrin-plus
'
;
import
emojiAliases
from
'
emojis/aliases.json
'
;
import
axios
from
'
../lib/utils/axios_utils
'
;
...
...
@@ -62,13 +63,18 @@ export function isEmojiNameValid(name) {
return
validEmojiNames
.
indexOf
(
name
)
>=
0
;
}
export
function
filterEmojiNames
(
filter
)
{
const
match
=
filter
.
toLowerCase
();
return
validEmojiNames
.
filter
(
name
=>
name
.
indexOf
(
match
)
>=
0
);
}
export
function
filterEmojiNamesByAlias
(
filter
)
{
return
uniq
(
filterEmojiNames
(
filter
).
map
(
name
=>
normalizeEmojiName
(
name
)));
/**
* Search emoji by name or alias. Returns a normalized, deduplicated list of
* names.
*
* Calling with an empty filter returns an empty array.
*
* @param {String}
* @returns {Array}
*/
export
function
queryEmojiNames
(
filter
)
{
const
matches
=
fuzzaldrinPlus
.
filter
(
validEmojiNames
,
filter
);
return
uniq
(
matches
.
map
(
name
=>
normalizeEmojiName
(
name
)));
}
let
emojiCategoryMap
;
...
...
changelogs/unreleased/issuable-award-fuzzy-search.yml
0 → 100644
View file @
1e58e447
---
title
:
Use fuzzy matching for issuable awards
merge_request
:
42674
author
:
Ethan Reesor (@firelizzard)
type
:
added
spec/frontend/awards_handler_spec.js
View file @
1e58e447
...
...
@@ -309,6 +309,16 @@ describe('AwardsHandler', () => {
expect
(
$
(
'
[data-name=alien]
'
).
is
(
'
:visible
'
)).
toBe
(
true
);
expect
(
$
(
'
.js-emoji-menu-search
'
).
val
()).
toBe
(
''
);
});
it
(
'
should fuzzy filter the emoji
'
,
async
()
=>
{
await
openAndWaitForEmojiMenu
();
awardsHandler
.
searchEmojis
(
'
sgls
'
);
expect
(
$
(
'
[data-name=angel]
'
).
is
(
'
:visible
'
)).
toBe
(
false
);
expect
(
$
(
'
[data-name=anger]
'
).
is
(
'
:visible
'
)).
toBe
(
false
);
expect
(
$
(
'
[data-name=sunglasses]
'
).
is
(
'
:visible
'
)).
toBe
(
true
);
});
});
describe
(
'
emoji menu
'
,
()
=>
{
...
...
spec/frontend/emoji/emoji_spec.js
View file @
1e58e447
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
{
trimText
}
from
'
helpers/text_helper
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
initEmojiMap
,
glEmojiTag
,
EMOJI_VERSION
}
from
'
~/emoji
'
;
import
{
initEmojiMap
,
glEmojiTag
,
queryEmojiNames
,
EMOJI_VERSION
}
from
'
~/emoji
'
;
import
isEmojiUnicodeSupported
,
{
isFlagEmoji
,
isRainbowFlagEmoji
,
...
...
@@ -57,8 +57,15 @@ describe('gl_emoji', () => {
let
mock
;
beforeEach
(()
=>
{
const
emojiData
=
Object
.
fromEntries
(
Object
.
values
(
emojiFixtureMap
).
map
(
m
=>
{
const
{
name
:
n
,
moji
:
e
,
unicodeVersion
:
u
,
category
:
c
,
description
:
d
}
=
m
;
return
[
n
,
{
c
,
e
,
d
,
u
}];
}),
);
mock
=
new
MockAdapter
(
axios
);
mock
.
onGet
(
`/-/emojis/
${
EMOJI_VERSION
}
/emojis.json`
).
reply
(
200
);
mock
.
onGet
(
`/-/emojis/
${
EMOJI_VERSION
}
/emojis.json`
).
reply
(
200
,
JSON
.
stringify
(
emojiData
)
);
return
initEmojiMap
().
catch
(()
=>
{});
});
...
...
@@ -378,4 +385,15 @@ describe('gl_emoji', () => {
expect
(
isSupported
).
toBeFalsy
();
});
});
describe
(
'
queryEmojiNames
'
,
()
=>
{
const
contains
=
(
e
,
term
)
=>
{
const
names
=
queryEmojiNames
(
term
);
expect
(
names
.
indexOf
(
e
.
name
)
>=
0
).
toBe
(
true
);
};
it
(
'
should match by name
'
,
()
=>
contains
(
emojiFixtureMap
.
grey_question
,
'
grey_question
'
));
it
(
'
should match by partial name
'
,
()
=>
contains
(
emojiFixtureMap
.
grey_question
,
'
question
'
));
it
(
'
should fuzzy match by name
'
,
()
=>
contains
(
emojiFixtureMap
.
grey_question
,
'
grqtn
'
));
});
});
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