-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(entities-plugins): support
route-by-header
(#952)
- Loading branch information
1 parent
d494c15
commit 2b8578f
Showing
11 changed files
with
200 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
packages/core/forms/src/generator/fields/advanced/FieldKeyValuePairs.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<template> | ||
<div class="key-value-pairs-editor"> | ||
<div | ||
v-for="(pair, index) in pairs" | ||
:key="index" | ||
class="pair-item" | ||
> | ||
<input | ||
class="form-control" | ||
:data-testid="`${getFieldID(schema)}-pair-key-${index}`" | ||
:placeholder="schema.keyInputPlaceholder ?? 'Key'" | ||
type="text" | ||
:value="pair.key" | ||
@input="(e) => { onInput(e, index, 'key') }" | ||
> | ||
<input | ||
class="form-control" | ||
:data-testid="`${getFieldID(schema)}-pair-value-${index}`" | ||
:placeholder="schema.valueInputPlaceholder ?? 'Value'" | ||
type="text" | ||
:value="pair.value" | ||
@input="(e) => { onInput(e, index, 'value') }" | ||
> | ||
<KButton | ||
appearance="tertiary" | ||
:data-testid="`${getFieldID(schema)}-remove-pair-${index}`" | ||
@click="() => { removePair(index) }" | ||
> | ||
<TrashIcon /> | ||
</KButton> | ||
</div> | ||
<KButton | ||
appearance="tertiary" | ||
:class="schema.newElementButtonLabelClasses" | ||
:data-testid="`${getFieldID(schema)}-add-pair`" | ||
type="button" | ||
@click="addPair" | ||
> | ||
{{ schema.newElementButtonLabel ?? '+ Add Pair' }} | ||
</KButton> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import abstractField from '../abstractField' | ||
import { TrashIcon } from '@kong/icons' | ||
export default { | ||
name: 'FieldKeyValuePairs', | ||
components: { TrashIcon }, | ||
mixins: [abstractField], | ||
data() { | ||
return { | ||
pairs: [], | ||
} | ||
}, | ||
watch: { | ||
pairs: { | ||
handler() { | ||
this.updateValue() | ||
}, | ||
deep: true, | ||
}, | ||
}, | ||
created() { | ||
if (!this.value) { | ||
this.value = {} | ||
} | ||
const modelPairs = this.model?.[this.schema?.model] ?? {} | ||
Object.keys(modelPairs).forEach((key) => { | ||
this.pairs.push({ | ||
key, | ||
value: modelPairs[key], | ||
}) | ||
}) | ||
}, | ||
methods: { | ||
onInput(e, index, type) { | ||
this.pairs[index][type] = e.target.value | ||
}, | ||
updateValue() { | ||
this.value = this.pairs.reduce((acc, { key, value }) => ({ | ||
...acc, | ||
...(key && value ? { [key]: value } : null), | ||
}), {}) | ||
}, | ||
addPair() { | ||
this.pairs.push({ | ||
key: '', | ||
value: '', | ||
}) | ||
}, | ||
removePair(index) { | ||
this.pairs.splice(index, 1) | ||
}, | ||
}, | ||
} | ||
</script> | ||
<style lang="scss" scoped> | ||
.key-value-pairs-editor { | ||
width: 100%; | ||
.pair-item { | ||
display: flex; | ||
&:not(:first-child) { | ||
margin-top: 12px; | ||
} | ||
input { | ||
margin-right: 12px; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/entities/entities-plugins/src/composables/plugin-schemas/RouteByHeader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { RouteByHeaderSchema } from '../../types/plugins/route-by-header' | ||
import { arrayCardContainerFieldSchema } from './ArrayCardContainerFields' | ||
|
||
export const routeByHeaderSchema: RouteByHeaderSchema = { | ||
'config-rules': { | ||
...arrayCardContainerFieldSchema, | ||
newElementButtonLabel: '+ Add Rule', | ||
items: { | ||
type: 'object', | ||
schema: { | ||
fields: [{ | ||
label: 'Upstream Name', | ||
model: 'upstream_name', | ||
type: 'input', | ||
help: 'Target hostname where traffic will be routed in case of condition match', | ||
placeholder: 'Hostname', | ||
inputType: 'text', | ||
}, { | ||
label: 'Condition', | ||
model: 'condition', | ||
type: 'keyValuePairs', | ||
help: 'List of headers name and value pairs', | ||
newElementButtonLabelClasses: 'kong-form-new-element-button-label', | ||
newElementButtonLabel: '+ Add Condition', | ||
keyInputPlaceholder: 'Header name', | ||
valueInputPlaceholder: 'Header value', | ||
}], | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/entities/entities-plugins/src/types/plugins/route-by-header.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { Field, ItemsSchema, CommonSchemaFields } from '../../types/plugins/shared' | ||
|
||
type FieldForKeyValuePairs = Field & { | ||
newElementButtonLabelClasses?: string | ||
newElementButtonLabel?: string | ||
keyInputPlaceholder?: string | ||
valueInputPlaceholder?: string | ||
} | ||
|
||
type ItemsSchemaForKeyValuePairs = Omit<ItemsSchema, 'schema'> & { | ||
schema: { | ||
fields: FieldForKeyValuePairs[] | ||
} | ||
} | ||
|
||
export interface RouteByHeaderSchema extends CommonSchemaFields { | ||
'config-rules': { | ||
type: string | ||
showRemoveButton: boolean | ||
newElementButtonLabelClasses: string | ||
itemContainerComponent: string | ||
fieldClasses: string | ||
|
||
newElementButtonLabel: string | ||
items: ItemsSchemaForKeyValuePairs | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters