fix version sorting and icon display for marketplace

This commit is contained in:
Lucy Cifferello
2024-06-24 17:49:57 -04:00
parent b8eb8a90a5
commit 6e2cf8bb3f
3 changed files with 19 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@start9labs/marketplace",
"version": "0.3.27",
"version": "0.3.28",
"peerDependencies": {
"@angular/common": ">=13.2.0",
"@angular/core": ">=13.2.0",

View File

@@ -39,7 +39,21 @@ export class ReleaseNotesComponent {
}
asIsOrder(a: KeyValue<string, string>, b: KeyValue<string, string>) {
return a.key > b.key ? -1 : b.key > a.key ? 1 : 0
const a1 = a.key.split('.')
const b1 = b.key.split('.')
// contingency in case there's a 4th or 5th version
const len = Math.min(a1.length, b1.length)
// look through each version number and compare.
for (let i = 0; i < len; i++) {
const a2 = +a1[i] || 0
const b2 = +b1[i] || 0
if (a2 !== b2) {
// sort descending
return a2 > b2 ? -1 : 1
}
}
return a1.length - b1.length
}
async showReleaseNotes(content: PolymorpheusContent<TuiDialogContext>) {

View File

@@ -125,13 +125,15 @@ export class MarketplaceDepItemComponent {
getImage(key: string, marketplace: StoreIdentity | null) {
const icon = this.pkg.dependencyMetadata[key]?.icon
const camelToSnakeCase = (str: string) =>
str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)
if (icon) {
try {
const iconUrl = new URL(icon)
return iconUrl.href
} catch (e) {
return `${marketplace?.url}package/v0/icon/${key}`
return `${marketplace?.url}package/v0/icon/${camelToSnakeCase(key)}`
}
} else {
return key.substring(0, 2)