Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add clipboard debug #1981

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cypress/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { build, token } from '@/services/utils'
const $ = {
// cypress doesn't need i18n but this quietens TS temporarily
i18n: token('i18n'),
components: token('components'),
...DEV_TOKENS,
...TOKENS,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<ClipboardProvider v-slot="{ copyToClipboard }">
<slot
name="default"
:copy-to-clipboard="async (text: string) => {
const res = await copyToClipboard(text)
if(res) {
console.info(
`%cdebug-k-clipboard-provider: The following was copied to the clipboard:`, 'color: blue',
`
${text}`,
)
} else {
console.error(
`debug-k-clipboard-provider: The following wasn't copied to the clipboard:`,
`
${text}`,
)

}
return res;
}"
/>
</ClipboardProvider>
</template>
<script lang="ts" setup>
import { KClipboardProvider as ClipboardProvider } from '@kong/kongponents'
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# DebugKClipboardProvider

Wraps KClipboardProvider in a decorator to also `console.log` the text of any
copy (and also `console.error` the text if the copy fails).

The component should always be injected as a replacement for KClipboardProvider
in debug/dev modes only and never used directly.
8 changes: 4 additions & 4 deletions src/app/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export const services = (app: Record<string, Token>): ServiceDefinition[] => {
return async (App: Component) => {
const app = createApp(App)

components.forEach(([name, component]: [string, Component]) => {
app.component(name, component)
})

plugins.forEach(([...args]) => {
app.use(...args)
})

components.forEach(([name, component]: [string, Component]) => {
app.component(name, component)
})

return app
}
},
Expand Down
13 changes: 13 additions & 0 deletions src/services/development.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { setupWorker, MockedRequest } from 'msw'

import Logger from './logger/Logger'
import DebugKClipboardProvider from '@/app/application/components/debug-k-clipboard-provider/DebugKClipboardProvider.vue'
import debugI18n from '@/app/application/services/i18n/DebugI18n'
import { TOKENS as CONTROL_PLANES } from '@/app/control-planes'
import cookied from '@/services/env/CookiedEnv'
Expand Down Expand Up @@ -31,6 +32,7 @@ const $ = {

type SupportedTokens = typeof $ & {
i18n: Token
components: Token
logger: Token
env: Token<AEnv>
}
Expand Down Expand Up @@ -67,6 +69,17 @@ export const services: ServiceConfigurator<SupportedTokens> = (app) => [
decorates: app.i18n,
}],

[token('development.components'), {
service: () => {
return [
['KClipboardProvider', DebugKClipboardProvider],
]
},
labels: [
app.components,
],
}],

[token<AEnv>('env.debug'), {
service: (env: () => AEnv) => {
return cookied(env())
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export default ({ fake, env }: EndpointDependencies): MockResponder => (req) =>
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
name,
type: 'Mesh',
creationTime: '2020-06-19T12:18:02.097986-04:00',
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/circuit-breakers/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default (_deps: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'CircuitBreaker',
mesh: params.mesh,
name: params.name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/dataplanes/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default ({ fake, env }: EndpointDependencies): MockResponder => (req) =>
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'Dataplane',
mesh,
name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/external-services/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'ExternalService',
mesh,
name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/fault-injections/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'FaultInjection',
mesh: params.mesh,
name: params.name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/health-checks/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'HealthCheck',
mesh: params.mesh,
name: params.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'MeshFaultInjection',
mesh,
name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/meshgatewayroutes/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'MeshGatewayRoute',
mesh: params.mesh,
name: params.name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/meshgateways/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default (_deps: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'MeshGateway',
mesh: params.mesh,
name: params.name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/proxytemplates/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'ProxyTemplate',
mesh: params.mesh,
name: params.name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/traffic-logs/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'TrafficLog',
mesh: params.mesh,
name: params.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'TrafficPermission',
mesh: params.mesh,
name: params.name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/meshes/_/traffic-traces/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'TrafficTrace',
mesh: params.mesh,
name: params.name,
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/zone-ingresses/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'ZoneIngress',
name,
creationTime: '2021-07-13T08:40:59Z',
Expand Down
3 changes: 3 additions & 0 deletions src/test-support/mocks/src/zoneegresses/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export default ({ fake }: EndpointDependencies): MockResponder => (req) => {
return {
headers: {},
body: {
...(req.url.searchParams.get('format') === 'kubernetes' && {
apiVersion: 'kuma.io/v1alpha1',
}),
type: 'ZoneEgress',
name,
creationTime: '2021-07-13T08:40:59Z',
Expand Down
8 changes: 4 additions & 4 deletions test-support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export const services: ServiceConfigurator = (app) => [
components: ComponentDefinition[],
plugins: PluginDefinition[],
) => {
components.forEach(([name, component]: [string, Component]) => {
config.global.components[name] = component
})

plugins.forEach(([...args]) => {
config.global.plugins.push([...args])
})

components.forEach(([name, component]: [string, Component]) => {
config.global.components[name] = component
})

return async () => {
throw new Error('You shouldn\'t be calling $.app during testing, just get(\'$.app\') is fine')
}
Expand Down