Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
urgi-is
FAIDARE
Commits
2726921c
Commit
2726921c
authored
Mar 28, 2019
by
Guillaume Cornut
Browse files
fix: Simplify KeyValueObject converter.
parent
681e1024
Changes
4
Hide whitespace changes
Inline
Side-by-side
frontend/src/app/site-card/site-card.component.ts
View file @
2726921c
...
...
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import
{
BrapiService
}
from
'
../brapi.service
'
;
import
{
ActivatedRoute
}
from
'
@angular/router
'
;
import
{
BrapiLocation
}
from
'
../models/brapi.model
'
;
import
{
KeyValueObject
}
from
'
../utils
'
;
import
{
KeyValueObject
,
toKeyValueObjects
}
from
'
../utils
'
;
import
{
DataDiscoverySource
}
from
'
../models/data-discovery.model
'
;
import
{
GnpisService
}
from
'
../gnpis.service
'
;
...
...
@@ -30,7 +30,7 @@ export class SiteCardComponent implements OnInit {
this
.
location
=
response
.
result
;
this
.
additionalInfos
=
[];
if
(
this
.
location
.
additionalInfo
)
{
this
.
manageAdditionalInfo
(
KeyValueObject
.
fromObject
(
this
.
location
.
additionalInfo
).
sort
());
this
.
manageAdditionalInfo
(
to
KeyValueObject
s
(
this
.
location
.
additionalInfo
).
sort
());
}
const
sourceURI
=
location
[
'
schema:includedInDataCatalog
'
];
// TODO Remove the condition when the field includedInDataCatalog will be added to URGI study.
...
...
frontend/src/app/study-card/study-card.component.ts
View file @
2726921c
...
...
@@ -5,7 +5,7 @@ import { BrapiGermplasm, BrapiObservationVariable, BrapiStudy, BrapiTrial } from
import
{
GnpisService
}
from
'
../gnpis.service
'
;
import
{
DataDiscoverySource
}
from
'
../models/data-discovery.model
'
;
import
{
KeyValueObject
}
from
'
../utils
'
;
import
{
KeyValueObject
,
toKeyValueObjects
}
from
'
../utils
'
;
@
Component
({
selector
:
'
gpds-study-card
'
,
...
...
@@ -43,7 +43,7 @@ export class StudyCardComponent implements OnInit {
this
.
additionalInfos
=
[];
if
(
this
.
study
.
additionalInfo
)
{
this
.
additionalInfos
=
KeyValueObject
.
fromObject
(
this
.
study
.
additionalInfo
).
sort
();
this
.
additionalInfos
=
to
KeyValueObject
s
(
this
.
study
.
additionalInfo
).
sort
();
}
// Get study trials
...
...
frontend/src/app/utils.spec.ts
View file @
2726921c
import
{
KeyValueObject
}
from
'
./utils
'
;
import
{
KeyValueObject
,
toKeyValueObjects
}
from
'
./utils
'
;
describe
(
'
KeyValueObject
'
,
()
=>
{
it
(
'
should convert JS object to array of KeyValueObject
'
,
()
=>
{
const
actual
=
KeyValueObject
.
fromObject
({
const
actual
=
to
KeyValueObject
s
({
'
a
'
:
'
1
'
,
'
b
'
:
'
2
'
,
'
c
'
:
null
,
...
...
@@ -13,10 +13,10 @@ describe('KeyValueObject', () => {
'
f
'
:
'
3
'
});
const
expected
=
[
new
KeyValueObject
(
'
a
'
,
'
1
'
)
,
new
KeyValueObject
(
'
b
'
,
'
2
'
)
,
new
KeyValueObject
(
'
f
'
,
'
3
'
)
,
const
expected
:
KeyValueObject
[]
=
[
{
key
:
'
a
'
,
value
:
'
1
'
}
,
{
key
:
'
b
'
,
value
:
'
2
'
}
,
{
key
:
'
f
'
,
value
:
'
3
'
}
,
];
expect
(
actual
).
toEqual
(
expected
);
...
...
frontend/src/app/utils.ts
View file @
2726921c
...
...
@@ -8,19 +8,18 @@ export function asArray<T>(obj: T | T[]): T[] {
return
[
obj
];
}
export
class
KeyValueObject
{
public
key
:
string
;
public
value
:
string
;
constructor
(
key
:
string
,
value
:
string
)
{
this
.
key
=
key
;
this
.
value
=
value
;
}
export
interface
KeyValueObject
{
key
:
string
;
value
:
string
;
}
static
fromObject
(
o
:
{
[
key
:
string
]:
string
}):
KeyValueObject
[]
{
return
Object
.
entries
(
o
)
/**
* Transform an object with string keys and values to a list of `KeyValueObject`.
* Also makes sure the keys and values are truthy.
*/
export
function
toKeyValueObjects
(
object
:
Record
<
string
,
string
>
):
KeyValueObject
[]
{
return
Object
.
entries
(
object
)
.
filter
(([
key
,
value
])
=>
!!
key
&&
!!
value
)
.
map
(([
key
,
value
])
=>
new
KeyValueObject
(
key
,
value
));
}
.
map
(([
key
,
value
])
=>
({
key
,
value
}));
}
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