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

Port forward: ui fixes and better error handling #56

Merged
merged 6 commits into from
Oct 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type NeComboboxOption,
getAxiosErrorMessage
} from '@nethserver/vue-tailwind-lib'
import { toRefs, ref, onMounted } from 'vue'
import { toRefs, ref, watch } from 'vue'
import type {
CreateEditPortForwardPayload,
PortForward
Expand Down Expand Up @@ -165,14 +165,26 @@ watchEffect(() => {
})

function close() {
error.value.notificationTitle = ''
error.value.notificationDescription = ''
validationErrorBag.value.clear()
restrictIPValidationErrors.value = []

resetForm()
emit('close')
}

onMounted(() => {
fetchOptions()
firewallConfig.fetch()
})
watch(
() => props.isShown,
() => {
if (props.isShown) {
fetchOptions()
if (firewallConfig.loading || firewallConfig.error) {
firewallConfig.fetch()
}
}
}
)

function resetRestrictIPValidationErrors() {
restrictIPValidationErrors.value = []
Expand Down Expand Up @@ -286,14 +298,18 @@ async function createOrEditPortForward() {
"
>
<NeInlineNotification
v-if="error.notificationTitle"
:title="error.notificationTitle"
:description="error.notificationDescription"
v-if="error.notificationTitle || firewallConfig.error"
:title="firewallConfig.error ? t('error.cannot_retrieve_zones') : error.notificationTitle"
:description="
firewallConfig.error
? t(getAxiosErrorMessage(firewallConfig.error))
: error.notificationDescription
"
class="mb-6"
kind="error"
/>
<NeSkeleton v-if="loading || firewallConfig.loading" :lines="10" />
<div v-else class="flex flex-col gap-y-6">
<div v-else-if="!firewallConfig.error" class="flex flex-col gap-y-6">
<NeToggle :label="t('standalone.port_forward.status')" v-model="enabled" />
<NeTextInput
:label="t('standalone.port_forward.name')"
Expand Down Expand Up @@ -327,13 +343,6 @@ async function createOrEditPortForward() {
></template
>
</NeTextInput>
<NeCombobox
:label="t('standalone.port_forward.destination_zone')"
:placeholder="t('standalone.port_forward.choose_zone')"
:options="supportedDestinationZones"
:selected-label="t('standalone.port_forward.any_zone')"
v-model="destinationZone"
/>
<NeTextInput
:label="t('standalone.port_forward.destination_port')"
v-model="destinationPort"
Expand All @@ -353,12 +362,18 @@ async function createOrEditPortForward() {
</NeButton>
</div>
<template v-if="showAdvancedSettings">
<NeCombobox
:label="t('standalone.port_forward.destination_zone')"
:placeholder="t('standalone.port_forward.choose_zone')"
:options="supportedDestinationZones"
:selected-label="t('standalone.port_forward.any_zone')"
v-model="destinationZone"
/>
<NeCombobox
:label="t('standalone.port_forward.wan_ip')"
:options="wanInterfaces"
v-model="wan"
/>

<NeMultiTextInput
:title="t('standalone.port_forward.restrict_access_to')"
:optional="true"
Expand Down
33 changes: 13 additions & 20 deletions src/views/standalone/firewall/PortForward.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
NeButton,
NeTextInput,
NeSkeleton,
NeInlineNotification
NeInlineNotification,
NeEmptyState
} from '@nethserver/vue-tailwind-lib'
import PortForwardTable from '@/components/standalone/firewall/PortForwardTable.vue'
import { onMounted, ref } from 'vue'
Expand Down Expand Up @@ -204,34 +205,26 @@ onMounted(() => {
/>
<NeSkeleton v-if="loading" :lines="10" />
<template v-else>
<div
<NeEmptyState
:title="t('standalone.port_forward.no_port_forward_configured')"
:icon="['fas', 'circle-info']"
v-if="Object.keys(portForwards).length == 0"
class="flex flex-col items-center justify-center rounded-md p-10 dark:bg-gray-800"
>
<p class="mb-4 text-sm">
<strong>{{ t('standalone.port_forward.no_port_forward_configured') }}</strong>
</p>
<NeButton kind="primary" @click="openCreateEditDrawer(null)"
><NeButton kind="primary" @click="openCreateEditDrawer(null)"
><template #prefix>
<font-awesome-icon
:icon="['fas', 'circle-plus']"
class="h-4 w-4"
aria-hidden="true"
/> </template
>{{ t('standalone.port_forward.add_port_forward') }}</NeButton
>
</div>
<div
v-else-if="Object.keys(filteredPortForwards).length == 0"
class="flex flex-col items-center justify-center rounded-md p-10 dark:bg-gray-800"
></NeEmptyState
>
<p class="mb-4 text-sm">
<strong>{{ t('standalone.port_forward.no_port_forward_found') }}</strong>
</p>
<p class="text-sm">
{{ t('standalone.port_forward.filter_change_suggestion') }}
</p>
</div>
<NeEmptyState
:title="t('standalone.port_forward.no_port_forward_found')"
:description="t('standalone.port_forward.filter_change_suggestion')"
:icon="['fas', 'circle-info']"
v-else-if="Object.keys(filteredPortForwards).length == 0"
/>
<PortForwardTable
v-else
v-for="(portForward, key) in filteredPortForwards"
Expand Down