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
fce54015
Commit
fce54015
authored
Aug 02, 2021
by
Nicolò Maria Mezzopera
Committed by
Olena Horal-Koretska
Aug 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor package metadata to apollo aproach
parent
f83dbb35
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
189 additions
and
59 deletions
+189
-59
app/assets/javascripts/packages_and_registries/package_registry/components/details/additional_metadata.vue
...ckage_registry/components/details/additional_metadata.vue
+27
-17
app/assets/javascripts/packages_and_registries/package_registry/components/details/app.vue
...nd_registries/package_registry/components/details/app.vue
+4
-4
app/assets/javascripts/packages_and_registries/package_registry/graphql/fragmentTypes.json
...nd_registries/package_registry/graphql/fragmentTypes.json
+17
-0
app/assets/javascripts/packages_and_registries/package_registry/graphql/index.js
...packages_and_registries/package_registry/graphql/index.js
+9
-0
app/assets/javascripts/packages_and_registries/package_registry/graphql/queries/get_package_details.query.graphql
...egistry/graphql/queries/get_package_details.query.graphql
+30
-0
spec/frontend/packages_and_registries/package_registry/components/details/additional_metadata_spec.js
...e_registry/components/details/additional_metadata_spec.js
+50
-38
spec/frontend/packages_and_registries/package_registry/components/details/app_spec.js
...egistries/package_registry/components/details/app_spec.js
+13
-0
spec/frontend/packages_and_registries/package_registry/mock_data.js
...end/packages_and_registries/package_registry/mock_data.js
+39
-0
No files found.
app/assets/javascripts/packages_and_registries/package_registry/components/details/additional_metadata.vue
View file @
fce54015
<
script
>
import
{
GlLink
,
GlSprintf
}
from
'
@gitlab/ui
'
;
import
{
s__
}
from
'
~/locale
'
;
import
{
PackageType
}
from
'
~/packages/shared/constants
'
;
import
{
PACKAGE_TYPE_NUGET
,
PACKAGE_TYPE_CONAN
,
PACKAGE_TYPE_MAVEN
,
}
from
'
~/packages_and_registries/package_registry/constants
'
;
import
DetailsRow
from
'
~/vue_shared/components/registry/details_row.vue
'
;
export
default
{
...
...
@@ -25,12 +29,18 @@ export default {
},
computed
:
{
showMetadata
()
{
const
visibilityConditions
=
{
[
PackageType
.
NUGET
]:
this
.
packageEntity
.
nuget_metadatum
,
[
PackageType
.
CONAN
]:
this
.
packageEntity
.
conan_metadatum
,
[
PackageType
.
MAVEN
]:
this
.
packageEntity
.
maven_metadatum
,
};
return
visibilityConditions
[
this
.
packageEntity
.
package_type
];
return
[
PACKAGE_TYPE_NUGET
,
PACKAGE_TYPE_CONAN
,
PACKAGE_TYPE_MAVEN
].
includes
(
this
.
packageEntity
.
packageType
,
);
},
showNugetMetadata
()
{
return
this
.
packageEntity
.
packageType
===
PACKAGE_TYPE_NUGET
;
},
showConanMetadata
()
{
return
this
.
packageEntity
.
packageType
===
PACKAGE_TYPE_CONAN
;
},
showMavenMetadata
()
{
return
this
.
packageEntity
.
packageType
===
PACKAGE_TYPE_MAVEN
;
},
},
};
...
...
@@ -41,12 +51,12 @@ export default {
<h3
class=
"gl-font-lg"
data-testid=
"title"
>
{{
__
(
'
Additional Metadata
'
)
}}
</h3>
<div
class=
"gl-bg-gray-50 gl-inset-border-1-gray-100 gl-rounded-base"
data-testid=
"main"
>
<template
v-if=
"
packageEntity.nuget_metadatum
"
>
<template
v-if=
"
showNugetMetadata
"
>
<details-row
icon=
"project"
padding=
"gl-p-4"
dashed
data-testid=
"nuget-source"
>
<gl-sprintf
:message=
"$options.i18n.sourceText"
>
<template
#link
>
<gl-link
:href=
"packageEntity.
nuget_metadatum.project_u
rl"
target=
"_blank"
>
{{
packageEntity
.
nuget_metadatum
.
project_u
rl
<gl-link
:href=
"packageEntity.
metadata.projectU
rl"
target=
"_blank"
>
{{
packageEntity
.
metadata
.
projectU
rl
}}
</gl-link>
</
template
>
</gl-sprintf>
...
...
@@ -54,8 +64,8 @@ export default {
<details-row
icon=
"license"
padding=
"gl-p-4"
data-testid=
"nuget-license"
>
<gl-sprintf
:message=
"$options.i18n.licenseText"
>
<
template
#link
>
<gl-link
:href=
"packageEntity.
nuget_metadatum.license_u
rl"
target=
"_blank"
>
{{
packageEntity
.
nuget_metadatum
.
license_u
rl
<gl-link
:href=
"packageEntity.
metadata.licenseU
rl"
target=
"_blank"
>
{{
packageEntity
.
metadata
.
licenseU
rl
}}
</gl-link>
</
template
>
</gl-sprintf>
...
...
@@ -63,28 +73,28 @@ export default {
</template>
<details-row
v-else-if=
"
packageEntity.conan_metadatum
"
v-else-if=
"
showConanMetadata
"
icon=
"information-o"
padding=
"gl-p-4"
data-testid=
"conan-recipe"
>
<gl-sprintf
:message=
"$options.i18n.recipeText"
>
<
template
#recipe
>
{{
packageEntity
.
nam
e
}}
</
template
>
<
template
#recipe
>
{{
packageEntity
.
metadata
.
recip
e
}}
</
template
>
</gl-sprintf>
</details-row>
<
template
v-else-if=
"
packageEntity.maven_metadatum
"
>
<
template
v-else-if=
"
showMavenMetadata
"
>
<details-row
icon=
"information-o"
padding=
"gl-p-4"
dashed
data-testid=
"maven-app"
>
<gl-sprintf
:message=
"$options.i18n.appName"
>
<template
#name
>
<strong>
{{
packageEntity
.
m
aven_metadatum
.
app_n
ame
}}
</strong>
<strong>
{{
packageEntity
.
m
etadata
.
appN
ame
}}
</strong>
</
template
>
</gl-sprintf>
</details-row>
<details-row
icon=
"information-o"
padding=
"gl-p-4"
data-testid=
"maven-group"
>
<gl-sprintf
:message=
"$options.i18n.appGroup"
>
<
template
#group
>
<strong>
{{
packageEntity
.
m
aven_metadatum
.
app_g
roup
}}
</strong>
<strong>
{{
packageEntity
.
m
etadata
.
appG
roup
}}
</strong>
</
template
>
</gl-sprintf>
</details-row>
...
...
app/assets/javascripts/packages_and_registries/package_registry/components/details/app.vue
View file @
fce54015
...
...
@@ -19,13 +19,13 @@ import { convertToGraphQLId } from '~/graphql_shared/utils';
import
{
numberToHumanSize
}
from
'
~/lib/utils/number_utils
'
;
import
{
objectToQuery
}
from
'
~/lib/utils/url_utility
'
;
import
{
s__
,
__
}
from
'
~/locale
'
;
// import AdditionalMetadata from '~/packages/details/components/additional_metadata.vue';
// import DependencyRow from '~/packages/details/components/dependency_row.vue';
// import InstallationCommands from '~/packages/details/components/installation_commands.vue';
// import PackageFiles from '~/packages/details/components/package_files.vue';
// import PackageListRow from '~/packages/shared/components/package_list_row.vue';
import
PackagesListLoader
from
'
~/packages/shared/components/packages_list_loader.vue
'
;
import
{
packageTypeToTrackCategory
}
from
'
~/packages/shared/utils
'
;
import
AdditionalMetadata
from
'
~/packages_and_registries/package_registry/components/details/additional_metadata.vue
'
;
import
PackageHistory
from
'
~/packages_and_registries/package_registry/components/details/package_history.vue
'
;
import
{
PACKAGE_TYPE_NUGET
,
...
...
@@ -61,7 +61,7 @@ export default {
// PackageListRow,
// DependencyRow,
PackageHistory
,
//
AdditionalMetadata,
AdditionalMetadata
,
// InstallationCommands,
// PackageFiles,
},
...
...
@@ -244,9 +244,9 @@ export default {
:package-entity="packageEntity"
:npm-path="npmPath"
:npm-help-path="npmHelpPath"
/>
/>
-->
<additional-metadata :package-entity="packageEntity" />
-->
<additional-metadata
:package-entity=
"packageEntity"
/>
</div>
<!-- <package-files
...
...
app/assets/javascripts/packages_and_registries/package_registry/graphql/fragmentTypes.json
0 → 100644
View file @
fce54015
{
"__schema"
:
{
"types"
:
[
{
"kind"
:
"UNION"
,
"name"
:
"PackageMetadata"
,
"possibleTypes"
:
[
{
"name"
:
"ComposerMetadata"
},
{
"name"
:
"ConanMetadata"
},
{
"name"
:
"MavenMetadata"
},
{
"name"
:
"NugetMetadata"
},
{
"name"
:
"PypiMetadata"
}
]
}
]
}
}
app/assets/javascripts/packages_and_registries/package_registry/graphql/index.js
View file @
fce54015
import
{
IntrospectionFragmentMatcher
}
from
'
apollo-cache-inmemory
'
;
import
Vue
from
'
vue
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
createDefaultClient
from
'
~/lib/graphql
'
;
import
introspectionQueryResultData
from
'
./fragmentTypes.json
'
;
const
fragmentMatcher
=
new
IntrospectionFragmentMatcher
({
introspectionQueryResultData
,
});
Vue
.
use
(
VueApollo
);
...
...
@@ -8,6 +14,9 @@ export const apolloProvider = new VueApollo({
defaultClient
:
createDefaultClient
(
{},
{
cacheConfig
:
{
fragmentMatcher
,
},
assumeImmutableResults
:
true
,
},
),
...
...
app/assets/javascripts/packages_and_registries/package_registry/graphql/queries/get_package_details.query.graphql
View file @
fce54015
...
...
@@ -40,5 +40,35 @@ query getPackageDetails($id: ID!) {
size
}
}
metadata
{
...
on
ComposerMetadata
{
targetSha
composerJson
{
license
version
}
}
...
on
PypiMetadata
{
requiredPython
}
...
on
ConanMetadata
{
packageChannel
packageUsername
recipe
recipePath
}
...
on
MavenMetadata
{
appName
appGroup
appVersion
path
}
...
on
NugetMetadata
{
iconUrl
licenseUrl
projectUrl
}
}
}
}
spec/frontend/packages_and_registries/package_registry/components/details/additional_metadata_spec.js
View file @
fce54015
import
{
GlLink
,
GlSprintf
}
from
'
@gitlab/ui
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
mavenPackage
,
conanPackage
,
nugetPackage
,
npmPackage
}
from
'
jest/packages/mock_data
'
;
import
{
shallowMountExtended
}
from
'
helpers/vue_test_utils_helper
'
;
import
{
conanMetadata
,
mavenMetadata
,
nugetMetadata
,
packageData
,
}
from
'
jest/packages_and_registries/package_registry/mock_data
'
;
import
component
from
'
~/packages_and_registries/package_registry/components/details/additional_metadata.vue
'
;
import
{
PACKAGE_TYPE_NUGET
,
PACKAGE_TYPE_CONAN
,
PACKAGE_TYPE_MAVEN
,
PACKAGE_TYPE_NPM
,
}
from
'
~/packages_and_registries/package_registry/constants
'
;
import
DetailsRow
from
'
~/vue_shared/components/registry/details_row.vue
'
;
const
mavenPackage
=
{
packageType
:
PACKAGE_TYPE_MAVEN
,
metadata
:
mavenMetadata
()
};
const
conanPackage
=
{
packageType
:
PACKAGE_TYPE_CONAN
,
metadata
:
conanMetadata
()
};
const
nugetPackage
=
{
packageType
:
PACKAGE_TYPE_NUGET
,
metadata
:
nugetMetadata
()
};
const
npmPackage
=
{
packageType
:
PACKAGE_TYPE_NPM
,
metadata
:
{}
};
describe
(
'
Package Additional Metadata
'
,
()
=>
{
let
wrapper
;
const
defaultProps
=
{
packageEntity
:
{
...
mavenPackage
},
packageEntity
:
{
...
packageData
(
mavenPackage
),
},
};
const
mountComponent
=
(
props
)
=>
{
wrapper
=
shallowMount
(
component
,
{
wrapper
=
shallowMount
Extended
(
component
,
{
propsData
:
{
...
defaultProps
,
...
props
},
stubs
:
{
DetailsRow
,
...
...
@@ -25,14 +43,14 @@ describe('Package Additional Metadata', () => {
wrapper
=
null
;
});
const
findTitle
=
()
=>
wrapper
.
find
(
'
[data-testid="title"]
'
);
const
findMainArea
=
()
=>
wrapper
.
find
(
'
[data-testid="main"]
'
);
const
findNugetSource
=
()
=>
wrapper
.
find
(
'
[data-testid="nuget-source"]
'
);
const
findNugetLicense
=
()
=>
wrapper
.
find
(
'
[data-testid="nuget-license"]
'
);
const
findConanRecipe
=
()
=>
wrapper
.
find
(
'
[data-testid="conan-recipe"]
'
);
const
findMavenApp
=
()
=>
wrapper
.
find
(
'
[data-testid="maven-app"]
'
);
const
findMavenGroup
=
()
=>
wrapper
.
find
(
'
[data-testid="maven-group"]
'
);
const
findElementLink
=
(
container
)
=>
container
.
find
(
GlLink
);
const
findTitle
=
()
=>
wrapper
.
find
ByTestId
(
'
title
'
);
const
findMainArea
=
()
=>
wrapper
.
find
ByTestId
(
'
main
'
);
const
findNugetSource
=
()
=>
wrapper
.
find
ByTestId
(
'
nuget-source
'
);
const
findNugetLicense
=
()
=>
wrapper
.
find
ByTestId
(
'
nuget-license
'
);
const
findConanRecipe
=
()
=>
wrapper
.
find
ByTestId
(
'
conan-recipe
'
);
const
findMavenApp
=
()
=>
wrapper
.
find
ByTestId
(
'
maven-app
'
);
const
findMavenGroup
=
()
=>
wrapper
.
find
ByTestId
(
'
maven-group
'
);
const
findElementLink
=
(
container
)
=>
container
.
find
Component
(
GlLink
);
it
(
'
has the correct title
'
,
()
=>
{
mountComponent
();
...
...
@@ -43,27 +61,21 @@ describe('Package Additional Metadata', () => {
expect
(
title
.
text
()).
toBe
(
'
Additional Metadata
'
);
});
describe
.
each
`
packageEntity | visible | metadata
${
mavenPackage
}
|
${
true
}
|
${
'
maven_metadatum
'
}
${
conanPackage
}
|
${
true
}
|
${
'
conan_metadatum
'
}
${
nugetPackage
}
|
${
true
}
|
${
'
nuget_metadatum
'
}
${
npmPackage
}
|
${
false
}
|
${
null
}
`
(
'
Component visibility
'
,
({
packageEntity
,
visible
,
metadata
})
=>
{
it
(
`Is
${
visible
}
that the component markup is visible when the package is
${
packageEntity
.
package_type
}
`
,
()
=>
{
it
.
each
`
packageEntity | visible | packageType
${
mavenPackage
}
|
${
true
}
|
${
PACKAGE_TYPE_MAVEN
}
${
conanPackage
}
|
${
true
}
|
${
PACKAGE_TYPE_CONAN
}
${
nugetPackage
}
|
${
true
}
|
${
PACKAGE_TYPE_NUGET
}
${
npmPackage
}
|
${
false
}
|
${
PACKAGE_TYPE_NPM
}
`
(
`It is $visible that the component is visible when the package is $packageType`
,
({
packageEntity
,
visible
})
=>
{
mountComponent
({
packageEntity
});
expect
(
findTitle
().
exists
()).
toBe
(
visible
);
expect
(
findMainArea
().
exists
()).
toBe
(
visible
);
});
it
(
`The component is hidden if
${
metadata
}
is missing`
,
()
=>
{
mountComponent
({
packageEntity
:
{
...
packageEntity
,
[
metadata
]:
null
}
});
expect
(
findTitle
().
exists
()).
toBe
(
false
);
expect
(
findMainArea
().
exists
()).
toBe
(
false
);
});
});
},
);
describe
(
'
nuget metadata
'
,
()
=>
{
beforeEach
(()
=>
{
...
...
@@ -72,14 +84,14 @@ describe('Package Additional Metadata', () => {
it
.
each
`
name | finderFunction | text | link | icon
${
'
source
'
}
|
${
findNugetSource
}
|
${
'
Source project located at project
-foo-url
'
}
|
${
'
project_u
rl
'
}
|
${
'
project
'
}
${
'
license
'
}
|
${
findNugetLicense
}
|
${
'
License information located at license
-foo-url
'
}
|
${
'
license_u
rl
'
}
|
${
'
license
'
}
${
'
source
'
}
|
${
findNugetSource
}
|
${
'
Source project located at project
Url
'
}
|
${
'
projectU
rl
'
}
|
${
'
project
'
}
${
'
license
'
}
|
${
findNugetLicense
}
|
${
'
License information located at license
Url
'
}
|
${
'
licenseU
rl
'
}
|
${
'
license
'
}
`
(
'
$name element
'
,
({
finderFunction
,
text
,
link
,
icon
})
=>
{
const
element
=
finderFunction
();
expect
(
element
.
exists
()).
toBe
(
true
);
expect
(
element
.
text
()).
toBe
(
text
);
expect
(
element
.
props
(
'
icon
'
)).
toBe
(
icon
);
expect
(
findElementLink
(
element
).
attributes
(
'
href
'
)).
toBe
(
nugetPackage
.
nuget_metadatum
[
link
]);
expect
(
findElementLink
(
element
).
attributes
(
'
href
'
)).
toBe
(
nugetPackage
.
metadata
[
link
]);
});
});
...
...
@@ -90,7 +102,7 @@ describe('Package Additional Metadata', () => {
it
.
each
`
name | finderFunction | text | icon
${
'
recipe
'
}
|
${
findConanRecipe
}
|
${
'
Recipe:
conan-package/1.0.0@conan+conan-package
/stable
'
}
|
${
'
information-o
'
}
${
'
recipe
'
}
|
${
findConanRecipe
}
|
${
'
Recipe:
package-8/1.0.0@gitlab-org+gitlab-test
/stable
'
}
|
${
'
information-o
'
}
`
(
'
$name element
'
,
({
finderFunction
,
text
,
icon
})
=>
{
const
element
=
finderFunction
();
expect
(
element
.
exists
()).
toBe
(
true
);
...
...
@@ -106,8 +118,8 @@ describe('Package Additional Metadata', () => {
it
.
each
`
name | finderFunction | text | icon
${
'
app
'
}
|
${
findMavenApp
}
|
${
'
App name:
test-app
'
}
|
${
'
information-o
'
}
${
'
group
'
}
|
${
findMavenGroup
}
|
${
'
App group:
com.test.ap
p
'
}
|
${
'
information-o
'
}
${
'
app
'
}
|
${
findMavenApp
}
|
${
'
App name:
appName
'
}
|
${
'
information-o
'
}
${
'
group
'
}
|
${
findMavenGroup
}
|
${
'
App group:
appGrou
p
'
}
|
${
'
information-o
'
}
`
(
'
$name element
'
,
({
finderFunction
,
text
,
icon
})
=>
{
const
element
=
finderFunction
();
expect
(
element
.
exists
()).
toBe
(
true
);
...
...
spec/frontend/packages_and_registries/package_registry/components/details/app_spec.js
View file @
fce54015
...
...
@@ -5,6 +5,7 @@ import createMockApollo from 'helpers/mock_apollo_helper';
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
createFlash
from
'
~/flash
'
;
import
AdditionalMetadata
from
'
~/packages_and_registries/package_registry/components/details/additional_metadata.vue
'
;
import
PackagesApp
from
'
~/packages_and_registries/package_registry/components/details/app.vue
'
;
import
PackageHistory
from
'
~/packages_and_registries/package_registry/components/details/package_history.vue
'
;
import
PackageTitle
from
'
~/packages_and_registries/package_registry/components/details/package_title.vue
'
;
...
...
@@ -48,6 +49,7 @@ describe('PackagesApp', () => {
const
findEmptyState
=
()
=>
wrapper
.
findComponent
(
GlEmptyState
);
const
findPackageTitle
=
()
=>
wrapper
.
findComponent
(
PackageTitle
);
const
findPackageHistory
=
()
=>
wrapper
.
findComponent
(
PackageHistory
);
const
findAdditionalMetadata
=
()
=>
wrapper
.
findComponent
(
AdditionalMetadata
);
afterEach
(()
=>
{
wrapper
.
destroy
();
...
...
@@ -95,4 +97,15 @@ describe('PackagesApp', () => {
projectName
:
provide
.
projectName
,
});
});
it
(
'
renders additional metadata and has the right props
'
,
async
()
=>
{
createComponent
();
await
waitForPromises
();
expect
(
findAdditionalMetadata
().
exists
()).
toBe
(
true
);
expect
(
findAdditionalMetadata
().
props
()).
toMatchObject
({
packageEntity
:
expect
.
objectContaining
(
packageData
()),
});
});
});
spec/frontend/packages_and_registries/package_registry/mock_data.js
View file @
fce54015
...
...
@@ -58,10 +58,49 @@ export const packageData = (extend) => ({
...
extend
,
});
export
const
conanMetadata
=
()
=>
({
packageChannel
:
'
stable
'
,
packageUsername
:
'
gitlab-org+gitlab-test
'
,
recipe
:
'
package-8/1.0.0@gitlab-org+gitlab-test/stable
'
,
recipePath
:
'
package-8/1.0.0/gitlab-org+gitlab-test/stable
'
,
});
export
const
composerMetadata
=
()
=>
({
targetSha
:
'
b83d6e391c22777fca1ed3012fce84f633d7fed0
'
,
composerJson
:
{
license
:
'
MIT
'
,
version
:
'
1.0.0
'
,
},
});
export
const
pypyMetadata
=
()
=>
({
requiredPython
:
'
1.0.0
'
,
});
export
const
mavenMetadata
=
()
=>
({
appName
:
'
appName
'
,
appGroup
:
'
appGroup
'
,
appVersion
:
'
appVersion
'
,
path
:
'
path
'
,
});
export
const
nugetMetadata
=
()
=>
({
iconUrl
:
'
iconUrl
'
,
licenseUrl
:
'
licenseUrl
'
,
projectUrl
:
'
projectUrl
'
,
});
export
const
packageDetailsQuery
=
()
=>
({
data
:
{
package
:
{
...
packageData
(),
metadata
:
{
...
conanMetadata
(),
...
composerMetadata
(),
...
pypyMetadata
(),
...
mavenMetadata
(),
...
nugetMetadata
(),
},
tags
:
{
nodes
:
packageTags
(),
__typename
:
'
PackageTagConnection
'
,
...
...
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