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

Improve mwan rule form #333

Merged
merged 2 commits into from
Aug 7, 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
10 changes: 4 additions & 6 deletions public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -970,16 +970,14 @@
"protocol_udp": "UDP",
"protocol_icmp": "ICMP",
"protocol_all": "All",
"address_options": {
"any": "Any",
"address": "Address",
"object": "Object"
},
"address_options_address": "Enter an address",
"address_options_object": "Select an object",
"address_options_any_src": "Any source address",
"address_options_any_dst": "Any destination address",
"source_type": "Source type",
"destination_type": "Destination type",
"source_object": "Source object",
"enter_address": "Enter an address",
"select_an_object": "Select an object",
"destination_object": "Destination object"
},
"dns_dhcp": {
Expand Down
21 changes: 15 additions & 6 deletions src/components/standalone/multi-wan/RuleCreator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const {
sticky,
validationErrors,
isValid,
addressOptions,
srcAddressOptions,
dstAddressOptions,
srcType,
dstType,
objectsLoading,
Expand All @@ -71,6 +72,11 @@ function cleanForm() {
destinationAddress.value = ''
destinationPort.value = ''
validationErrors.value.clear()
sticky.value = false
srcType.value = 'address'
dstType.value = 'address'
srcObject.value = ''
dstObject.value = ''
}

type Payload = {
Expand Down Expand Up @@ -128,7 +134,10 @@ function save() {
error.value = reason
}
})
.finally(() => (saving.value = false))
.finally(() => {
saving.value = false
cleanForm()
})
}
}
</script>
Expand Down Expand Up @@ -182,7 +191,7 @@ function save() {
v-model="srcType"
:disabled="saving"
:label="t('standalone.multi_wan.source_type')"
:options="addressOptions"
:options="srcAddressOptions"
/>
<NeTextInput
v-if="srcType == 'address'"
Expand All @@ -196,7 +205,7 @@ function save() {
v-if="srcType == 'object'"
v-model="srcObject"
:disabled="saving"
:label="t('standalone.multi_wan.select_an_object')"
:label="t('standalone.multi_wan.source_object')"
:options="srcObjectOptions"
:placeholder="objectsLoading ? t('common.loading') : t('ne_combobox.choose')"
:invalid-message="t(validationErrors.getFirstI18nKeyFor('ns_src'))"
Expand Down Expand Up @@ -228,7 +237,7 @@ function save() {
v-model="dstType"
:disabled="saving"
:label="t('standalone.multi_wan.destination_type')"
:options="addressOptions"
:options="dstAddressOptions"
/>
<NeTextInput
v-if="dstType == 'address'"
Expand All @@ -242,7 +251,7 @@ function save() {
v-if="dstType == 'object'"
v-model="dstObject"
:disabled="saving"
:label="t('standalone.multi_wan.select_an_object')"
:label="t('standalone.multi_wan.destination_object')"
:options="dstObjectOptions"
:placeholder="objectsLoading ? t('common.loading') : t('ne_combobox.choose')"
:invalid-message="t(validationErrors.getFirstI18nKeyFor('ns_dst'))"
Expand Down
12 changes: 8 additions & 4 deletions src/components/standalone/multi-wan/RuleEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const {
sticky,
validationErrors,
isValid,
addressOptions,
srcAddressOptions,
dstAddressOptions,
srcType,
dstType,
objectsLoading,
Expand Down Expand Up @@ -134,7 +135,10 @@ function save() {
error.value = reason
}
})
.finally(() => (saving.value = false))
.finally(() => {
saving.value = false
cleanForm()
})
}
}
</script>
Expand Down Expand Up @@ -188,7 +192,7 @@ function save() {
v-model="srcType"
:disabled="saving"
:label="t('standalone.multi_wan.source_type')"
:options="addressOptions"
:options="srcAddressOptions"
/>
<NeTextInput
v-if="srcType == 'address'"
Expand Down Expand Up @@ -235,7 +239,7 @@ function save() {
v-model="dstType"
:disabled="saving"
:label="t('standalone.multi_wan.destination_type')"
:options="addressOptions"
:options="dstAddressOptions"
/>
<NeTextInput
v-if="dstType == 'address'"
Expand Down
21 changes: 14 additions & 7 deletions src/composables/useRuleForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@ export function useRuleForm(policies: Ref<Policy[]>, rule?: Ref<Rule | undefined

type AddressType = 'any' | 'address' | 'object'

const addressOptions: { id: AddressType; label: string }[] = [
{ id: 'any', label: t('standalone.multi_wan.address_options.any') },
{ id: 'address', label: t('standalone.multi_wan.address_options.address') },
{ id: 'object', label: t('standalone.multi_wan.address_options.object') }
const srcAddressOptions: { id: AddressType; label: string }[] = [
{ id: 'address', label: t('standalone.multi_wan.address_options_address') },
{ id: 'any', label: t('standalone.multi_wan.address_options_any_src') },
{ id: 'object', label: t('standalone.multi_wan.address_options_object') }
]

const srcType = ref<AddressType>('any')
const dstType = ref<AddressType>('any')
const dstAddressOptions: { id: AddressType; label: string }[] = [
{ id: 'address', label: t('standalone.multi_wan.address_options_address') },
{ id: 'any', label: t('standalone.multi_wan.address_options_any_dst') },
{ id: 'object', label: t('standalone.multi_wan.address_options_object') }
]

const srcType = ref<AddressType>('address')
const dstType = ref<AddressType>('address')

type ObjectResponse = {
objects: {
Expand Down Expand Up @@ -210,7 +216,8 @@ export function useRuleForm(policies: Ref<Policy[]>, rule?: Ref<Rule | undefined
isValid,
srcType,
dstType,
addressOptions,
srcAddressOptions,
dstAddressOptions,
objectsLoading,
objectsError,
srcObject,
Expand Down
Loading