diff --git a/src/composables/useDocsLink.ts b/src/composables/useDocsLink.ts index 0defe7b0..ff374507 100644 --- a/src/composables/useDocsLink.ts +++ b/src/composables/useDocsLink.ts @@ -1,25 +1,41 @@ -import { computed } from 'vue' import { formatVersion } from '@/utils' -import { config } from 'config' +import { config, type GatewayEdition } from 'config' +import { EntityType } from '@/types' -export const useDocsLink = (entity: string) => { - const version = computed(() => { - if (!config.GATEWAY_VERSION) { - return 'latest' - } +const getVersionInPath = (edition: GatewayEdition) => { + if (!config.GATEWAY_VERSION) { + return 'latest' + } - return `${formatVersion(config.GATEWAY_VERSION)}.x` - }) + return edition === 'enterprise' + // For Enterprise, the version has a pattern of ..0.x where the 3rd digit + // will always be 0 regardless of the actual patch version + ? `${formatVersion(config.GATEWAY_VERSION)}.0.x` + // For OSS, the version has a pattern of ..x + : `${formatVersion(config.GATEWAY_VERSION)}.x` +} + +export const useDocsLink = (entityType: EntityType) => { + const edition = config.GATEWAY_EDITION ?? 'community' + const versionInPath = getVersionInPath(edition) + const docsBase = `https://docs.konghq.com/gateway/api/admin-${edition === 'enterprise' ? 'ee' : 'oss'}/${versionInPath}/#/` - const docsBase = computed(() => `https://docs.konghq.com/gateway/${version.value}/admin-api`) - const docsLink = computed(() => { - switch (entity) { - case 'key-set': - return `${docsBase.value}/#key-sets-entity` - default: - return `${docsBase.value}/#${entity}-object` - } - }) + const entityTypeToSpecLinkMap = { + [EntityType.GatewayService]: 'Services', + [EntityType.Route]: 'Routes', + [EntityType.Consumer]: 'Consumers', + [EntityType.ConsumerGroup]: 'consumer_groups', + [EntityType.Plugin]: 'Plugins', + [EntityType.Upstream]: 'Upstreams', + [EntityType.Certificate]: 'Certificates', + [EntityType.CACertificate]: 'CA Certificates', + [EntityType.SNI]: 'SNIs', + [EntityType.Key]: 'Keys', + [EntityType.KeySet]: 'Key-sets', + [EntityType.Target]: 'Targets', + [EntityType.Vault]: 'Vaults', + } + const docsLink = `${docsBase}${entityTypeToSpecLinkMap[entityType] ?? ''}` return docsLink } diff --git a/src/pages/ca-certificates/List.vue b/src/pages/ca-certificates/List.vue index 29cd7db3..a4ad8bba 100644 --- a/src/pages/ca-certificates/List.vue +++ b/src/pages/ca-certificates/List.vue @@ -30,6 +30,7 @@ import { useListGeneralConfig } from '@/composables/useListGeneralConfig' import { useListRedirect } from '@/composables/useListRedirect' import { useToaster } from '@/composables/useToaster' import { useDocsLink } from '@/composables/useDocsLink' +import { EntityType } from '@/types' defineOptions({ name: 'CACertificateList', @@ -38,7 +39,7 @@ defineOptions({ const { createRedirectRouteQuery } = useListRedirect() const toaster = useToaster() const { t } = useI18n() -const docsLink = useDocsLink('ca-certificate') +const docsLink = useDocsLink(EntityType.CACertificate) const createRoute = computed(() => { return { name: 'ca-certificate-create' } diff --git a/src/pages/certificates/List.vue b/src/pages/certificates/List.vue index 0a0f3d44..a4b00d8f 100644 --- a/src/pages/certificates/List.vue +++ b/src/pages/certificates/List.vue @@ -30,6 +30,7 @@ import { useListGeneralConfig } from '@/composables/useListGeneralConfig' import { useListRedirect } from '@/composables/useListRedirect' import { useToaster } from '@/composables/useToaster' import { useDocsLink } from '@/composables/useDocsLink' +import { EntityType } from '@/types' defineOptions({ name: 'CertificateList', @@ -38,7 +39,7 @@ defineOptions({ const { createRedirectRouteQuery } = useListRedirect() const toaster = useToaster() const { t } = useI18n() -const docsLink = useDocsLink('certificate') +const docsLink = useDocsLink(EntityType.Certificate) const createRoute = computed(() => { return { name: 'certificate-create' } diff --git a/src/pages/consumers/List.vue b/src/pages/consumers/List.vue index f66af91f..da07839d 100644 --- a/src/pages/consumers/List.vue +++ b/src/pages/consumers/List.vue @@ -31,6 +31,7 @@ import { useCopyEventHandlers } from '@/composables/useCopyEventHandlers' import { useToaster } from '@/composables/useToaster' import { useI18n } from '@/composables/useI18n' import { useDocsLink } from '@/composables/useDocsLink' +import { EntityType } from '@/types' defineOptions({ name: 'ConsumerList', @@ -39,7 +40,7 @@ defineOptions({ const { createRedirectRouteQuery } = useListRedirect() const toaster = useToaster() const { t } = useI18n() -const docsLink = useDocsLink('consumer') +const docsLink = useDocsLink(EntityType.Consumer) const createRoute = computed(() => { return { name: 'consumer-create' } diff --git a/src/pages/key-sets/List.vue b/src/pages/key-sets/List.vue index 60445bfb..a76c41b1 100644 --- a/src/pages/key-sets/List.vue +++ b/src/pages/key-sets/List.vue @@ -31,6 +31,7 @@ import { useToaster } from '@/composables/useToaster' import { useCopyEventHandlers } from '@/composables/useCopyEventHandlers' import { useI18n } from '@/composables/useI18n' import { useDocsLink } from '@/composables/useDocsLink' +import { EntityType } from '@/types' defineOptions({ name: 'KeySetList', @@ -39,7 +40,7 @@ defineOptions({ const { createRedirectRouteQuery } = useListRedirect() const toaster = useToaster() const { t } = useI18n() -const docsLink = useDocsLink('key-set') +const docsLink = useDocsLink(EntityType.KeySet) const filterSchema = computed(() => { return { diff --git a/src/pages/keys/List.vue b/src/pages/keys/List.vue index b6a926d3..7663f349 100644 --- a/src/pages/keys/List.vue +++ b/src/pages/keys/List.vue @@ -36,6 +36,7 @@ import { useToaster } from '@/composables/useToaster' import { useCopyEventHandlers } from '@/composables/useCopyEventHandlers' import { useI18n } from '@/composables/useI18n' import { useDocsLink } from '@/composables/useDocsLink' +import { EntityType } from '@/types' defineOptions({ name: 'KeyList', @@ -45,7 +46,7 @@ const { createRedirectRouteQuery } = useListRedirect() const toaster = useToaster() const route = useRoute() const { t } = useI18n() -const docsLink = useDocsLink('keys') +const docsLink = useDocsLink(EntityType.Key) const keySetId = computed(() => (route.params?.id ?? '') as string) const cacheIdentifier = computed(() => `routes-${keySetId.value}`) diff --git a/src/pages/plugins/List.vue b/src/pages/plugins/List.vue index b10f9c51..c1e7f5c8 100644 --- a/src/pages/plugins/List.vue +++ b/src/pages/plugins/List.vue @@ -31,7 +31,7 @@