Skip to content

Commit

Permalink
chore(*): update entity docs link (#89)
Browse files Browse the repository at this point in the history
* chore(*): update entity docs link

* chore(*): use EntityType

* chore(*): remove computed
  • Loading branch information
Leopoldthecoder authored Sep 8, 2023
1 parent 7fe9172 commit e424786
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 31 deletions.
52 changes: 34 additions & 18 deletions src/composables/useDocsLink.ts
Original file line number Diff line number Diff line change
@@ -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 <major>.<minor>.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 <major>.<minor>.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
}
3 changes: 2 additions & 1 deletion src/pages/ca-certificates/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' }
Expand Down
3 changes: 2 additions & 1 deletion src/pages/certificates/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' }
Expand Down
3 changes: 2 additions & 1 deletion src/pages/consumers/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' }
Expand Down
3 changes: 2 additions & 1 deletion src/pages/key-sets/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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<FilterSchema>(() => {
return {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/keys/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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}`)
Expand Down
7 changes: 4 additions & 3 deletions src/pages/plugins/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
<script setup lang="ts">
import { computed, reactive } from 'vue'
import { useRoute, type RouteLocationRaw } from 'vue-router'
import { PluginList, type EntityRow, type ViewRouteType, type EntityType } from '@kong-ui-public/entities-plugins'
import { PluginList, type EntityRow, type ViewRouteType, type EntityType as ScopedEntityType } from '@kong-ui-public/entities-plugins'
import type { FilterSchema } from '@kong-ui-public/entities-shared'
import { useListGeneralConfig } from '@/composables/useListGeneralConfig'
import { useListRedirect } from '@/composables/useListRedirect'
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: 'PluginList',
Expand All @@ -47,10 +48,10 @@ defineOptions({
const { createRedirectRouteQuery } = useListRedirect()
const toaster = useToaster()
const { t } = useI18n()
const docsLink = useDocsLink('plugin')
const docsLink = useDocsLink(EntityType.Plugin)
const route = useRoute()
const cacheIdentifier = computed(() => `plugins-${route.params?.id}`)
const entityType = computed(() => route.meta?.scopedIn as EntityType)
const entityType = computed(() => route.meta?.scopedIn as ScopedEntityType)
const scopedQuery = computed(() => {
switch (entityType.value) {
case 'services':
Expand Down
3 changes: 2 additions & 1 deletion src/pages/routes/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ 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: 'RouteList' })
const toaster = useToaster()
const route = useRoute()
const { t } = useI18n()
const docsLink = useDocsLink('route')
const docsLink = useDocsLink(EntityType.Route)
const { createRedirectRouteQuery } = useListRedirect()
const serviceId = computed(() => (route.params?.id ?? '') as string)
Expand Down
3 changes: 2 additions & 1 deletion src/pages/services/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'ServiceList',
Expand All @@ -39,7 +40,7 @@ defineOptions({
const { createRedirectRouteQuery } = useListRedirect()
const toaster = useToaster()
const { t } = useI18n()
const docsLink = useDocsLink('service')
const docsLink = useDocsLink(EntityType.GatewayService)
const createRoute = computed(() => {
return { name: 'service-create' }
Expand Down
3 changes: 2 additions & 1 deletion src/pages/snis/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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: 'SniList',
Expand All @@ -39,7 +40,7 @@ defineOptions({
const { createRedirectRouteQuery } = useListRedirect()
const toaster = useToaster()
const { t } = useI18n()
const docsLink = useDocsLink('sni')
const docsLink = useDocsLink(EntityType.SNI)
const createRoute = computed(() => {
return { name: 'sni-create' }
Expand Down
3 changes: 2 additions & 1 deletion src/pages/upstreams/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'UpstreamList',
Expand All @@ -39,7 +40,7 @@ defineOptions({
const { createRedirectRouteQuery } = useListRedirect()
const toaster = useToaster()
const { t } = useI18n()
const docsLink = useDocsLink('upstream')
const docsLink = useDocsLink(EntityType.Upstream)
const createRoute = computed(() => {
return { name: 'upstream-create' }
Expand Down
3 changes: 2 additions & 1 deletion src/pages/vaults/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'VaultList',
Expand All @@ -39,7 +40,7 @@ defineOptions({
const { createRedirectRouteQuery } = useListRedirect()
const toaster = useToaster()
const { t } = useI18n()
const docsLink = useDocsLink('vaults')
const docsLink = useDocsLink(EntityType.Vault)
const createRoute = computed(() => {
return { name: 'vault-create' }
Expand Down
15 changes: 15 additions & 0 deletions src/types/entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum EntityType {
GatewayService = 1,
Route,
Consumer,
ConsumerGroup,
Plugin,
Upstream,
Certificate,
CACertificate,
SNI,
Key,
KeySet,
Target,
Vault,
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './entity'

0 comments on commit e424786

Please sign in to comment.