Skip to content

Commit

Permalink
feat(redis): redis configuration form [KM-235]
Browse files Browse the repository at this point in the history
  • Loading branch information
2eha0 committed Nov 18, 2024
1 parent 4e39040 commit 4173bb1
Show file tree
Hide file tree
Showing 7 changed files with 534 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<template>
<div>
<KLabel
:info="t('form.cluster_nodes.tooltip')"
:tooltip-attributes="{ maxWidth: '400' }"
>
{{ t('form.cluster_nodes.title') }}
</KLabel>
<div>
<FieldArrayCardContainer
v-for="(item, index) of items"
:key="`${index}`"
@remove-item="items.splice(index, 1)"
>
<div
class="cluster-node-items"
>
<KInput
:label="t('form.fields.cluster_node_ip.label')"
:label-attributes="{
info: t('form.fields.cluster_node_ip.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
required
/>
<KInput
:label="t('form.fields.cluster_node_port.label')"
:label-attributes="{
info: t('form.fields.cluster_node_port.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="number"
/>
</div>
</FieldArrayCardContainer>
<KButton
appearance="tertiary"
@click="addItem"
>
<AddCircleIcon />
<span>{{ t('form.cluster_nodes.add_button') }}</span>
</KButton>
</div>
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { AddCircleIcon } from '@kong/icons'
import FieldArrayCardContainer from './FieldArrayCardContainer.vue'
import composables from '../composables'
const { i18n: { t } } = composables.useI18n()
type Item = {
ip: string
port: number
}
const items = ref<Item[]>([{ ip: '', port: 0 }])
const addItem = () => {
items.value.push({ ip: '', port: 0 })
}
</script>

<style lang="scss" scoped>
.cluster-node-items {
display: flex;
flex-direction: column;
gap: $kui-space-80;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<div class="array-card-container">
<KCard class="card">
<slot />
</KCard>

<KButton
appearance="tertiary"
class="array-card-remove-button"
@click="$emit('remove-item')"
>
<TrashIcon />
</KButton>
</div>
</template>

<script lang="ts" setup>
import { TrashIcon } from '@kong/icons'
defineProps({
model: {
type: Object,
default: () => null,
},
schema: {
type: Object,
default: () => null,
},
index: {
type: Number,
default: undefined,
},
})
defineEmits<{
(e: 'remove-item'): void,
}>()
</script>

<style lang='scss'>
.array-card-container-wrapper {
width: 100%;
}
</style>

<style lang="scss" scoped>
.array-card-container {
align-items: center;
display: flex;
.card {
margin-bottom: $kui-space-40;
}
.array-card-remove-button {
margin-left: $kui-space-50;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,216 @@
:title="t('form.sections.type.title')"
>
<KSelect
:items="[]"
v-model="form.fields.type"
:items="typeOptions"
:label="t('form.fields.type.label')"
required
/>
>
<template #selected-item-template="{ item }">
{{ getSelectedText(item) }}
</template>
</KSelect>
</EntityFormSection>

<EntityFormSection
:description="t('form.sections.general.description')"
:title="t('form.sections.general.title')"
>
<KInput
v-model.trim="form.fields.name"
:label="t('form.fields.name.label')"
:placeholder="t('form.fields.name.placeholder')"
required
/>
</EntityFormSection>

<EntityFormSection
v-if="form.fields.type === RedisType.SENTINEL"
:description="t('form.sections.sentinel_configuration.description')"
:title="t('form.sections.sentinel_configuration.title')"
>
<KInput
:label="t('form.fields.sentinel_master.label')"
:label-attributes="{
info: t('form.fields.sentinel_master.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
required
/>
<KInput
:label="t('form.fields.sentinel_role.label')"
:label-attributes="{
info: t('form.fields.sentinel_role.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
required
/>
<ClusterNodes />
<KInput
:label="t('form.fields.sentinel_username.label')"
:label-attributes="{
info: t('form.fields.sentinel_username.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
/>
<KInput
:label="t('form.fields.sentinel_password.label')"
:label-attributes="{
info: t('form.fields.sentinel_password.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="password"
/>
</EntityFormSection>

<EntityFormSection
v-if="form.fields.type === RedisType.CLUSTER"
:description="t('form.sections.cluster.description')"
:title="t('form.sections.cluster.title')"
>
<ClusterNodes />
<KInput
:label="t('form.fields.cluster_max_redirections.label')"
:label-attributes="{
info: t('form.fields.cluster_max_redirections.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="number"
/>
</EntityFormSection>

<EntityFormSection
:description="t('form.sections.connection.description')"
:title="t('form.sections.connection.title')"
>
<KInput
v-if="form.fields.type === RedisType.HOST_PORT_OPEN_SOURCE || form.fields.type === RedisType.HOST_PORT_ENTERPRISE"
:label="t('form.fields.host.label')"
:label-attributes="{
info: t('form.fields.host.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
required
/>
<KInput
v-if="form.fields.type === RedisType.HOST_PORT_OPEN_SOURCE || form.fields.type === RedisType.HOST_PORT_ENTERPRISE"
:label="t('form.fields.port.label')"
:label-attributes="{
info: t('form.fields.port.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="number"
/>

<KInput
v-if="form.fields.type === RedisType.HOST_PORT_ENTERPRISE"
:label="t('form.fields.connection_is_proxied.label')"
:label-attributes="{
info: t('form.fields.connection_is_proxied.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="number"
/>

<KInput
v-if="form.fields.type === RedisType.HOST_PORT_ENTERPRISE"
:label="t('form.fields.timeout.label')"
:label-attributes="{
info: t('form.fields.timeout.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="number"
/>

<KInput
:label="t('form.fields.database.label')"
:label-attributes="{
info: t('form.fields.database.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="number"
/>
<KInput
:label="t('form.fields.username.label')"
:label-attributes="{
info: t('form.fields.username.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
/>
<KInput
:label="t('form.fields.password.label')"
:label-attributes="{
info: t('form.fields.password.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="password"
/>
</EntityFormSection>

<EntityFormSection
:description="t('form.sections.tls.description')"
:title="t('form.sections.tls.title')"
>
<KCheckbox
:description="t('form.fields.ssl.description')"
:label="t('form.fields.ssl.label')"
:model-value="false"
/>
<KCheckbox
:description="t('form.fields.ssl_verify.description')"
:label="t('form.fields.ssl_verify.label')"
:model-value="false"
/>
<KInput
:label="t('form.fields.server_name.label')"
:label-attributes="{
info: t('form.fields.server_name.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
/>
</EntityFormSection>

<EntityFormSection
v-if="form.fields.type !== RedisType.HOST_PORT_OPEN_SOURCE"
:description="t('form.sections.keepalive.description')"
:title="t('form.sections.keepalive.title')"
>
<KInput
:label="t('form.fields.keepalive_backlog.label')"
:label-attributes="{
info: t('form.fields.keepalive_backlog.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="number"
/>
<KInput
:label="t('form.fields.keepalive_pool_size.label')"
:label-attributes="{
info: t('form.fields.keepalive_pool_size.tooltip'),
tooltipAttributes: { maxWidth: '400' },
}"
type="number"
/>
</EntityFormSection>

<EntityFormSection
v-if="form.fields.type !== RedisType.HOST_PORT_OPEN_SOURCE"
:description="t('form.sections.read_write_configuration.description')"
:title="t('form.sections.read_write_configuration.title')"
>
<KInput
:label="t('form.fields.read_timeout.label')"
type="number"
/>
<KInput
:label="t('form.fields.send_timeout.label')"
type="number"
/>
<KInput
:label="t('form.fields.connect_timeout.label')"
type="number"
/>
</EntityFormSection>
</EntityBaseForm>
</div>
</template>
Expand All @@ -46,11 +240,17 @@ import {
EntityFormSection,
SupportedEntityType,
} from '@kong-ui-public/entities-shared'
import type { KonnectRedisConfigurationFormConfig } from 'src/types'
import type { PropType } from 'vue'
import '@kong-ui-public/entities-shared/dist/style.css'
import composables from '../composables'
import ClusterNodes from '../components/ClusterNodes.vue'
import { useRedisConfigurationForm } from '../composables/useRedisConfigurationForm'
import type { PropType } from 'vue'
import {
RedisType,
type KonnectRedisConfigurationFormConfig,
} from '../types'
const props = defineProps({
config: {
Expand All @@ -67,9 +267,25 @@ const props = defineProps({
},
})
const { i18nT, i18n: { t } } = composables.useI18n()
const { i18n: { t } } = composables.useI18n()
const typeOptions = [
{ label: t('form.options.type.host_port'), group: ` ${t('form.options.type.open_source')}`, value: RedisType.HOST_PORT_OPEN_SOURCE }, // the space before the group name is intentional, it makes the group to be the first one
{ label: t('form.options.type.host_port'), group: t('form.options.type.enterprise'), value: RedisType.HOST_PORT_ENTERPRISE },
{ label: t('form.options.type.cluster'), group: t('form.options.type.enterprise'), value: RedisType.CLUSTER },
{ label: t('form.options.type.sentinel'), group: t('form.options.type.enterprise'), value: RedisType.SENTINEL },
]
const noop = () => {}
const getSelectedText = (item: any) => {
const suffix = item.value === RedisType.HOST_PORT_OPEN_SOURCE
? t('form.options.type.suffix_open_source')
: t('form.options.type.suffix_enterprise')
return `${item.label}${suffix}`
}
const { form } = useRedisConfigurationForm()
</script>

<style lang="scss" scoped>
Expand Down
Loading

0 comments on commit 4173bb1

Please sign in to comment.