From beae00a170a16bf3d02fe814659b284187bc5f3a Mon Sep 17 00:00:00 2001 From: Bonfire <5704760+Bonfire@users.noreply.github.com> Date: Fri, 26 Aug 2022 19:52:20 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20ping=20service=20toggle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../en/layout/add-service-app-shelf.json | 3 ++ src/components/AppShelf/AddAppShelfItem.tsx | 49 ++++++++++++------- src/components/AppShelf/AppShelfItem.tsx | 16 +++--- src/tools/types.ts | 1 + 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/public/locales/en/layout/add-service-app-shelf.json b/public/locales/en/layout/add-service-app-shelf.json index d13119302..936fddf18 100644 --- a/public/locales/en/layout/add-service-app-shelf.json +++ b/public/locales/en/layout/add-service-app-shelf.json @@ -97,6 +97,9 @@ "advancedOptions": { "title": "Advanced Options", "form": { + "ping": { + "label": "Ping Service" + }, "httpStatusCodes": { "label": "HTTP Status Codes", "placeholder": "Select valid status codes", diff --git a/src/components/AppShelf/AddAppShelfItem.tsx b/src/components/AppShelf/AddAppShelfItem.tsx index efeba042a..8689cd8d8 100644 --- a/src/components/AppShelf/AddAppShelfItem.tsx +++ b/src/components/AppShelf/AddAppShelfItem.tsx @@ -10,6 +10,7 @@ import { MultiSelect, PasswordInput, Select, + Space, Stack, Switch, Tabs, @@ -18,13 +19,13 @@ import { Tooltip, } from '@mantine/core'; import { useForm } from '@mantine/form'; +import { useDebouncedValue } from '@mantine/hooks'; import { IconApps } from '@tabler/icons'; +import { useTranslation } from 'next-i18next'; import { useEffect, useState } from 'react'; import { v4 as uuidv4 } from 'uuid'; -import { useDebouncedValue } from '@mantine/hooks'; -import { useTranslation } from 'next-i18next'; import { useConfig } from '../../tools/state'; -import { tryMatchPort, ServiceTypeList, StatusCodes } from '../../tools/types'; +import { ServiceTypeList, StatusCodes, tryMatchPort } from '../../tools/types'; import Tip from '../layout/Tip'; export function AddItemShelfButton(props: any) { @@ -109,6 +110,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & username: props.username ?? undefined, password: props.password ?? undefined, openedUrl: props.openedUrl ?? undefined, + ping: props.ping ?? true, status: props.status ?? ['200'], newTab: props.newTab ?? true, }, @@ -177,7 +179,11 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & if (newForm.newTab === true) newForm.newTab = undefined; if (newForm.openedUrl === '') newForm.openedUrl = undefined; if (newForm.category === null) newForm.category = undefined; - if (newForm.status.length === 1 && newForm.status[0] === '200') { + if (newForm.ping === true) newForm.ping = undefined; + if ( + (newForm.status.length === 1 && newForm.status[0] === '200') || + newForm.ping === false + ) { delete newForm.status; } // If service already exists, update it. @@ -210,6 +216,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & {t('modal.tabs.advancedOptions.title')} + void } & + - + {form.values.ping && ( + + )} ({ item: { @@ -134,7 +134,7 @@ export function AppShelfItem(props: any) { - + {service.ping !== false && } diff --git a/src/tools/types.ts b/src/tools/types.ts index e08b491e4..1c9c5f6f0 100644 --- a/src/tools/types.ts +++ b/src/tools/types.ts @@ -183,5 +183,6 @@ export interface serviceItem { username?: string; openedUrl?: string; newTab?: boolean; + ping?: boolean; status?: string[]; }