-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4872 from FlowFuse/team-bom-ui
Team Bill Of Materials UI
- Loading branch information
Showing
22 changed files
with
1,437 additions
and
612 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
frontend/src/components/bill-of-materials/BomDependencies.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<template> | ||
<div v-if="Object.keys(dependencies).length > 0" class="dependencies" data-el="dependencies"> | ||
<dependency-item | ||
v-for="(versions, dependencyTitle) in dependencies" | ||
:key="dependencyTitle" | ||
:title="dependencyTitle" | ||
:versions="versions" | ||
:start-closed="startClosed" | ||
/> | ||
</div> | ||
<div v-else class="empty text-center opacity-60"> | ||
<p>Oops! We couldn't find any matching results.</p> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import DependencyItem from './DependencyItem.vue' | ||
export default { | ||
name: 'BomDependencies', | ||
components: { DependencyItem }, | ||
props: { | ||
payload: { | ||
required: true, | ||
type: Object | ||
}, | ||
searchTerm: { | ||
required: false, | ||
type: String, | ||
default: '' | ||
}, | ||
startClosed: { | ||
required: false, | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
computed: { | ||
dependencies () { | ||
return this.payload.children | ||
.reduce((acc, currentInstance) => { | ||
currentInstance.dependencies.forEach(dep => { | ||
const searchTerm = this.searchTerm.trim() | ||
const installedDependencyVersion = dep.version?.current ?? dep.version?.wanted ?? 'N/A' | ||
const dependencyNameMatchesSearch = dep.name.toLowerCase().includes(searchTerm.toLowerCase()) | ||
const dependencyVersionMatchesSearch = installedDependencyVersion.toLowerCase().includes(searchTerm.toLowerCase()) | ||
const matchesInstanceName = currentInstance.name.toLowerCase().includes(searchTerm.toLowerCase()) | ||
const includeDependency = () => { | ||
if (!Object.prototype.hasOwnProperty.call(acc, dep.name)) { | ||
acc[dep.name] = {} | ||
} | ||
if (!Object.prototype.hasOwnProperty.call(acc[dep.name], installedDependencyVersion)) { | ||
acc[dep.name][installedDependencyVersion] = [] | ||
} | ||
acc[dep.name][installedDependencyVersion].push(currentInstance) | ||
} | ||
switch (true) { | ||
case !searchTerm.length: | ||
includeDependency() | ||
break | ||
case matchesInstanceName: | ||
includeDependency() | ||
break | ||
case dependencyVersionMatchesSearch || dependencyNameMatchesSearch: | ||
includeDependency() | ||
break | ||
default: | ||
break | ||
} | ||
}) | ||
return acc | ||
}, {}) | ||
} | ||
} | ||
} | ||
</script> | ||
<style scoped lang="scss"> | ||
</style> |
179 changes: 179 additions & 0 deletions
179
frontend/src/components/bill-of-materials/DependencyItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
<template> | ||
<section class="dependency-item" data-el="dependency-item" :data-item="title"> | ||
<div class="dependency-header" :class="{open: isOpen}" @click="toggleOpenState"> | ||
<ChevronRightIcon class="ff-icon-sm ff-toggle" /> | ||
<div class="title truncate"> | ||
<h3 class="truncate">{{ title }}</h3> | ||
<p class="truncate">({{ versionsCount }} {{ pluralize('Version', versionsCount) }})</p> | ||
</div> | ||
<div class="details truncate"> | ||
<span class="truncate">Latest: {{ externalLatest }}</span> | ||
<span class="truncate">Released: {{ externalLastModified }}</span> | ||
</div> | ||
</div> | ||
<template v-if="isOpen"> | ||
<versions-list | ||
v-for="(entry, key) in sortedVersions" :key="key" | ||
:instances="entry[1]" | ||
:version="entry[0]" | ||
/> | ||
</template> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import { ChevronRightIcon } from '@heroicons/vue/outline' | ||
import ExternalClient from '../../api/external.js' | ||
import { pluralize } from '../../composables/String.js' | ||
import daysSince from '../../utils/daysSince.js' | ||
import VersionsList from './VersionsList.vue' | ||
export default { | ||
name: 'DependencyItem', | ||
components: { | ||
VersionsList, | ||
ChevronRightIcon | ||
}, | ||
props: { | ||
title: { | ||
required: true, | ||
type: String | ||
}, | ||
versions: { | ||
required: true, | ||
type: Object | ||
}, | ||
startClosed: { | ||
required: false, | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
data () { | ||
return { | ||
externalDependency: null, | ||
isOpen: true | ||
} | ||
}, | ||
computed: { | ||
sortedVersions () { | ||
return Object.entries(this.versions).sort((a, b) => { | ||
return b[0].localeCompare(a[0]) | ||
}) | ||
}, | ||
externalLatest () { | ||
if ( | ||
!this.externalDependency || | ||
( | ||
!Object.prototype.hasOwnProperty.call(this.externalDependency, 'dist-tags') && | ||
!Object.prototype.hasOwnProperty.call(this.externalDependency['dist-tags'], 'latest') && | ||
!Object.prototype.hasOwnProperty.call(this.externalDependency, 'versions') && | ||
!Object.prototype.hasOwnProperty.call( | ||
this.externalDependency.versions, | ||
this.externalDependency['dist-tags'].latest | ||
) | ||
) | ||
) { | ||
return 'N/A' | ||
} | ||
return this.externalDependency.versions[this.externalDependency['dist-tags'].latest].version | ||
}, | ||
externalLastModified () { | ||
if ( | ||
!this.externalDependency || | ||
( | ||
!Object.prototype.hasOwnProperty.call(this.externalDependency, 'time') && | ||
!Object.prototype.hasOwnProperty.call(this.externalDependency.time, 'modified') | ||
) | ||
) { | ||
return 'N/A' | ||
} | ||
return daysSince(this.externalDependency.time.modified, true) | ||
}, | ||
versionsCount () { | ||
return Object.keys(this.versions).length | ||
} | ||
}, | ||
created () { | ||
this.isOpen = !this.startClosed | ||
}, | ||
mounted () { | ||
this.getExternalDependency() | ||
}, | ||
methods: { | ||
pluralize, | ||
async getExternalDependency () { | ||
this.externalDependency = await ExternalClient.getNpmDependency(this.title) | ||
}, | ||
toggleOpenState () { | ||
this.isOpen = !this.isOpen | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.dependency-item { | ||
border: 1px solid $ff-grey-300; | ||
margin-bottom: 12px; | ||
.dependency-header { | ||
cursor: pointer; | ||
background: $ff-grey-100; | ||
display: flex; | ||
padding: 6px 9px; | ||
align-items: center; | ||
gap: 15px; | ||
.title { | ||
flex: 1; | ||
display: flex; | ||
align-items: center; | ||
gap: 15px; | ||
h3, p { | ||
margin: 0; | ||
line-height: 1; | ||
} | ||
p { | ||
color: $ff-grey-500; | ||
font-weight: 400; | ||
font-size: 80%; | ||
} | ||
} | ||
.details { | ||
display: flex; | ||
flex-direction: column; | ||
text-align: right; | ||
font-size: 0.875rem; | ||
font-weight: 500; | ||
} | ||
.ff-toggle { | ||
transition: ease-in-out .3s; | ||
} | ||
&.open { | ||
border-bottom: 1px solid $ff-grey-300; | ||
.ff-toggle { | ||
transform: rotate(90deg); | ||
} | ||
} | ||
} | ||
&:last-of-type { | ||
.ff-accordion { | ||
button { | ||
border-bottom: none; | ||
} | ||
} | ||
} | ||
} | ||
</style> |
Oops, something went wrong.