Skip to content

Commit dca8094

Browse files
committed
updated command pallet to include changelog
1 parent d4bce55 commit dca8094

File tree

6 files changed

+70
-22
lines changed

6 files changed

+70
-22
lines changed

app/composables/useCommandPalettePackageCommands.ts

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export function useCommandPalettePackageCommands(
2727
.includes(packageName)
2828
}
2929

30+
const { data: changelog } = usePackageChangelog(
31+
() => toValue(context)?.packageName,
32+
() => toValue(context)?.resolvedVersion,
33+
)
34+
3035
useCommandPaletteContextCommands(
3136
computed((): CommandPaletteContextCommandInput[] => {
3237
const resolvedContext = toValue(context)
@@ -88,25 +93,43 @@ export function useCommandPalettePackageCommands(
8893
activeLabel: activeLabel(route.name === 'code', t('command_palette.here')),
8994
to: codeLink,
9095
},
91-
{
92-
id: 'package-compare',
96+
]
97+
98+
const uChangelog = changelog.value
99+
if (uChangelog?.type === 'md' || uChangelog?.type === 'release') {
100+
commands.push({
101+
id: 'package-changelog',
93102
group: 'package',
94-
label: t('command_palette.package.compare'),
95-
keywords: [resolvedContext.packageName, t('shortcuts.compare_from_package')],
96-
iconClass: 'i-lucide:git-compare',
97-
active: route.name === 'compare' && isCurrentPackageCompare(resolvedContext.packageName),
103+
label: t('command_palette.package.changelog'),
104+
keywords: [resolvedContext.packageName, t('command_palette.package.changelog')],
105+
iconClass: 'i-lucide:notebook-text',
106+
to: changelogRoute(resolvedContext.packageName, resolvedContext.resolvedVersion),
107+
active: route.name === 'changelog' || route.name === 'changelog-version',
98108
activeLabel: activeLabel(
99-
route.name === 'compare' && isCurrentPackageCompare(resolvedContext.packageName),
109+
route.name === 'changelog' || route.name === 'changelog-version',
100110
t('command_palette.here'),
101111
),
102-
to: {
103-
name: 'compare',
104-
query: {
105-
packages: resolvedContext.packageName,
106-
},
112+
})
113+
}
114+
115+
commands.push({
116+
id: 'package-compare',
117+
group: 'package',
118+
label: t('command_palette.package.compare'),
119+
keywords: [resolvedContext.packageName, t('shortcuts.compare_from_package')],
120+
iconClass: 'i-lucide:git-compare',
121+
active: route.name === 'compare' && isCurrentPackageCompare(resolvedContext.packageName),
122+
activeLabel: activeLabel(
123+
route.name === 'compare' && isCurrentPackageCompare(resolvedContext.packageName),
124+
t('command_palette.here'),
125+
),
126+
to: {
127+
name: 'compare',
128+
query: {
129+
packages: resolvedContext.packageName,
107130
},
108131
},
109-
]
132+
})
110133

111134
if (resolvedContext.tarballUrl) {
112135
commands.push({

app/composables/usePackageChangelog.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { ChangelogInfo } from '~~/shared/types/changelog'
22

33
export function usePackageChangelog(
4-
packageName: MaybeRefOrGetter<string>,
4+
packageName: MaybeRefOrGetter<string | null | undefined>,
55
version?: MaybeRefOrGetter<string | null | undefined>,
66
) {
7-
return useLazyFetch<ChangelogInfo>(() => {
7+
return useLazyFetch<ChangelogInfo | null>(() => {
88
const name = toValue(packageName)
9+
if (!name) return 'data:text/json,null' // returns null
910
const ver = toValue(version)
1011
const base = `/api/changelog/info/${name}`
1112
return ver ? `${base}/v/${ver}` : base

app/pages/package-changelog/[[org]]/[name].vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ const stickyStyle = computed(() => {
7070
}
7171
})
7272
73+
// command pallet
74+
const { versions: commandPaletteVersions, ensureLoaded: ensureCommandPaletteVersionsLoaded } =
75+
useCommandPalettePackageVersions(packageName)
76+
77+
const commandPalettePackageContext = computed(() => {
78+
const packageData = pkg.value
79+
if (!packageData) return null
80+
81+
return {
82+
packageName: packageData.name,
83+
resolvedVersion: version.value ?? packageData['dist-tags']?.latest ?? null,
84+
latestVersion: packageData['dist-tags']?.latest ?? null,
85+
versions: commandPaletteVersions.value ?? Object.keys(packageData.versions ?? {}),
86+
tarballUrl: packageData.requestedVersion?.dist.tarball ?? null,
87+
}
88+
})
89+
90+
useCommandPalettePackageContext(commandPalettePackageContext, {
91+
onOpen: ensureCommandPaletteVersionsLoaded,
92+
})
93+
useCommandPalettePackageCommands(commandPalettePackageContext)
94+
95+
// og image
7396
defineOgImageComponent('Default', {
7497
title: () => `${pkg.value?.name ?? 'Package'} - Changelogs`,
7598
description: () => pkg.value?.license ?? '',

i18n/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@
149149
"code": "Code",
150150
"diff": "Diff",
151151
"compare": "Compare this package",
152-
"download": "Download tarball"
152+
"download": "Download tarball",
153+
"changelog": "Changelog"
153154
},
154155
"package_actions": {
155156
"copy_run": "Copy run command"

i18n/locales/fr-FR.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@
149149
"code": "Code",
150150
"diff": "Diff",
151151
"compare": "Comparer ce paquet",
152-
"download": "Télécharger le tarball"
152+
"download": "Télécharger le tarball",
153+
"changelog": "Changements"
153154
},
154155
"package_actions": {
155156
"copy_run": "Copier la commande d'exécution"
@@ -555,11 +556,7 @@
555556
},
556557
"page_title": "Historique des versions",
557558
"current_tags": "Tags actuels",
558-
"no_match_filter": "Aucune version ne correspond à {filter}",
559-
"copy_alt": {
560-
"per_version_analysis": "La version {version} a été téléchargée {downloads} fois",
561-
"general_description": "Graphique en barres montrant les téléchargements par version pour {versions_count} versions {semver_grouping_mode} du paquet {package_name}, {date_range_label} de la version {first_version} à la version {last_version}. La version la plus téléchargée est {max_downloaded_version} avec {max_version_downloads} téléchargements. {per_version_analysis}. {watermark}."
562-
}
559+
"no_match_filter": "Aucune version ne correspond à {filter}"
563560
},
564561
"dependencies": {
565562
"title": "Dépendances ({count})",

i18n/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@
453453
},
454454
"download": {
455455
"type": "string"
456+
},
457+
"changelog": {
458+
"type": "string"
456459
}
457460
},
458461
"additionalProperties": false

0 commit comments

Comments
 (0)