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
b18f0092
Commit
b18f0092
authored
Dec 18, 2021
by
Ezekiel Kigbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prefer lodash pickBy
Removes the omitEmptyProperties method in favour of lodash pickBy
parent
7cfef3af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
55 deletions
+11
-55
app/assets/javascripts/init_confirm_danger.js
app/assets/javascripts/init_confirm_danger.js
+11
-7
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+0
-22
spec/frontend/lib/utils/common_utils_spec.js
spec/frontend/lib/utils/common_utils_spec.js
+0
-26
No files found.
app/assets/javascripts/init_confirm_danger.js
View file @
b18f0092
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
{
parseBoolean
,
omitEmptyProperties
}
from
'
./lib/utils/common_utils
'
;
import
{
pickBy
}
from
'
lodash
'
;
import
{
parseBoolean
}
from
'
./lib/utils/common_utils
'
;
import
ConfirmDanger
from
'
./vue_shared/components/confirm_danger/confirm_danger.vue
'
;
import
ConfirmDanger
from
'
./vue_shared/components/confirm_danger/confirm_danger.vue
'
;
export
default
()
=>
{
export
default
()
=>
{
...
@@ -22,12 +23,15 @@ export default () => {
...
@@ -22,12 +23,15 @@ export default () => {
return
new
Vue
({
return
new
Vue
({
el
,
el
,
provide
:
omitEmptyProperties
({
provide
:
pickBy
(
htmlConfirmationMessage
,
{
confirmDangerMessage
,
htmlConfirmationMessage
,
additionalInformation
,
confirmDangerMessage
,
confirmButtonText
,
additionalInformation
,
}),
confirmButtonText
,
},
(
v
)
=>
Boolean
(
v
),
),
render
:
(
createElement
)
=>
render
:
(
createElement
)
=>
createElement
(
ConfirmDanger
,
{
createElement
(
ConfirmDanger
,
{
props
:
{
props
:
{
...
...
app/assets/javascripts/lib/utils/common_utils.js
View file @
b18f0092
...
@@ -746,25 +746,3 @@ export const isLoggedIn = () => Boolean(window.gon?.current_user_id);
...
@@ -746,25 +746,3 @@ export const isLoggedIn = () => Boolean(window.gon?.current_user_id);
*/
*/
export
const
convertArrayOfObjectsToCamelCase
=
(
array
)
=>
export
const
convertArrayOfObjectsToCamelCase
=
(
array
)
=>
array
.
map
((
o
)
=>
convertObjectPropsToCamelCase
(
o
));
array
.
map
((
o
)
=>
convertObjectPropsToCamelCase
(
o
));
/**
* This method takes an object and omits any properties
* that are null, undefined, false or empty. The returned
* object only includes properties that have a `truthy` value.
*
* @param {Object} obj - Target object to be checked
* @returns {Object} Resulting object with only truthy properties
*/
export
const
omitEmptyProperties
=
(
obj
=
{})
=>
{
const
entries
=
Object
.
entries
(
obj
);
if
(
!
entries
.
length
)
{
return
obj
;
}
return
entries
.
reduce
((
acc
,
[
key
,
value
])
=>
{
if
(
!
value
)
{
return
acc
;
}
return
{
...
acc
,
[
key
]:
value
};
},
{});
};
spec/frontend/lib/utils/common_utils_spec.js
View file @
b18f0092
...
@@ -1051,30 +1051,4 @@ describe('common_utils', () => {
...
@@ -1051,30 +1051,4 @@ describe('common_utils', () => {
expect
(
result
).
toEqual
([{
hello
:
''
},
{
helloWorld
:
''
}]);
expect
(
result
).
toEqual
([{
hello
:
''
},
{
helloWorld
:
''
}]);
});
});
});
});
describe
(
'
omitEmptyProperties
'
,
()
=>
{
let
res
;
const
empty
=
{
foo
:
null
,
bar
:
undefined
,
baz
:
''
,
qux
:
false
};
const
values
=
{
a
:
'
a
'
,
b
:
1
,
c
:
{
d
:
'
d
'
},
e
:
[
'
f
'
]
};
beforeEach
(()
=>
{
res
=
Object
.
keys
(
commonUtils
.
omitEmptyProperties
({
...
empty
,
...
values
,
}),
);
});
it
(
'
returns an object with properties that have a value
'
,
()
=>
{
const
valueKeys
=
Object
.
keys
(
values
);
expect
(
res
).
toEqual
(
valueKeys
);
});
it
(
'
ignores properties that are empty, nullable or falsy
'
,
()
=>
{
Object
.
keys
(
empty
).
forEach
((
key
)
=>
{
expect
(
res
).
not
.
toContain
(
key
);
});
});
});
});
});
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