From 2e49b72ccf42e8b81897d72e2d6d09c08db21bff Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Wed, 4 Oct 2023 17:05:28 +0530 Subject: [PATCH] supported removal of subscription in teams (#13404) Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com> --- .../Team/TeamDetails/TeamDetailsV1.tsx | 10 ++++--- .../TeamsSubscription.component.tsx | 29 +++++++------------ .../Team/TeamDetails/team.interface.ts | 2 +- .../ui/src/constants/Teams.constants.ts | 4 +++ 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Team/TeamDetails/TeamDetailsV1.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Team/TeamDetails/TeamDetailsV1.tsx index aea5e9f1b7f..a358c71385c 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Team/TeamDetails/TeamDetailsV1.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Team/TeamDetails/TeamDetailsV1.tsx @@ -336,14 +336,16 @@ const TeamDetailsV1 = ({ } }; - const updateTeamSubscription = async (data: SubscriptionWebhook) => { + const updateTeamSubscription = async (data?: SubscriptionWebhook) => { if (currentTeam) { const updatedData: Team = { ...currentTeam, profile: { - subscription: { - [data.webhook]: { endpoint: data.endpoint }, - }, + subscription: isEmpty(data) + ? undefined + : { + [data?.webhook ?? '']: { endpoint: data?.endpoint }, + }, }, }; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Team/TeamDetails/TeamsHeaderSection/TeamsSubscription.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Team/TeamDetails/TeamsHeaderSection/TeamsSubscription.component.tsx index de514a63fdf..81ce561999d 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Team/TeamDetails/TeamsHeaderSection/TeamsSubscription.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Team/TeamDetails/TeamsHeaderSection/TeamsSubscription.component.tsx @@ -50,21 +50,7 @@ const TeamsSubscription = ({ }, []); // Watchers - const webhooks: { - webhook: string; - endpoint: string; - }[] = Form.useWatch(['subscriptions'], form); - - // Run time values needed for conditional rendering - const subscriptionOptions = useMemo(() => { - const exitingWebhook = webhooks?.map((f) => f?.webhook) ?? []; - - return SUBSCRIPTION_WEBHOOK_OPTIONS.map((func) => ({ - label: func.label, - value: func.value, - disabled: exitingWebhook.includes(func.value), - })); - }, [webhooks]); + const isWebhookEmpty = isEmpty(Form.useWatch('webhook', form)); const cellItem = useCallback( (key: string, value: Webhook) => ( @@ -94,7 +80,7 @@ const TeamsSubscription = ({ setIsLoading(true); try { - await updateTeamSubscription(values); + await updateTeamSubscription(isWebhookEmpty ? undefined : values); } catch { // parent block will throw error } finally { @@ -103,6 +89,12 @@ const TeamsSubscription = ({ } }; + useEffect(() => { + if (isWebhookEmpty) { + form.setFieldValue('endpoint', ''); + } + }, [isWebhookEmpty]); + useEffect(() => { if (subscription) { const data = Object.entries(subscription)[0]; @@ -155,7 +147,7 @@ const TeamsSubscription = ({ onFinish={handleSave}> Promise; + updateTeamSubscription: (value?: SubscriptionWebhook) => Promise; } export interface SubscriptionWebhook { diff --git a/openmetadata-ui/src/main/resources/ui/src/constants/Teams.constants.ts b/openmetadata-ui/src/main/resources/ui/src/constants/Teams.constants.ts index 71fb429357c..009f2c505ba 100644 --- a/openmetadata-ui/src/main/resources/ui/src/constants/Teams.constants.ts +++ b/openmetadata-ui/src/main/resources/ui/src/constants/Teams.constants.ts @@ -30,6 +30,10 @@ export enum SUBSCRIPTION_WEBHOOK { } export const SUBSCRIPTION_WEBHOOK_OPTIONS = [ + { + label: t('label.none'), + value: '', + }, { label: t('label.ms-team-plural'), value: SUBSCRIPTION_WEBHOOK.MS_TEAMS,