Skip to content

Commit 16e17c3

Browse files
GimirMagomed-Elbi_Dzhukalaev
andauthored
fix(chat): disable editing main fields of a logged-in toolset (Issue #5109) (#7124)
Co-authored-by: Magomed-Elbi_Dzhukalaev <magomed-elbi_dzhukalaev@epam.com>
1 parent 7025ccb commit 16e17c3

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

apps/chat/public/locales/en/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,6 @@
235235
"Limit exceeded": "Limit exceeded",
236236
"\"{{name}}\" has already been shared with the maximum specified number of users.": "\"{{name}}\" has already been shared with the maximum specified number of users.",
237237
"\"{{name}}\" version {{version}} has already been shared with the maximum specified number of users.": "\"{{name}}\" version {{version}} has already been shared with the maximum specified number of users.",
238-
"Sharing failed. You are only allowed to share applications with resources from \"My files\"": "Sharing failed. You are only allowed to share applications with resources from \"My files\""
238+
"Sharing failed. You are only allowed to share applications with resources from \"My files\"": "Sharing failed. You are only allowed to share applications with resources from \"My files\"",
239+
"Log out before editing toolset": "Log out before editing toolset"
239240
}

apps/chat/src/components/ToolsetEditor/EditorForm/SettingsForm.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react';
1+
import React, { useEffect, useMemo } from 'react';
22
import {
33
Controller,
44
useFormContext,
@@ -10,6 +10,8 @@ import classNames from 'classnames';
1010

1111
import { useTranslation } from '@/src/hooks/useTranslation';
1212

13+
import { isToolsetSignedIn } from '@/src/utils/app/toolsets';
14+
1315
import { DropdownSelectorOption } from '@/src/types/common';
1416
import { Translation } from '@/src/types/translation';
1517

@@ -104,6 +106,7 @@ export const SettingsForm = ({ isToolsetPublic }: SettingsFormProps) => {
104106
const { t } = useTranslation(Translation.Common);
105107

106108
const toolset = useAppSelector(ToolsetSelectors.selectToolsetDetails);
109+
const isLoggedIn = toolset && isToolsetSignedIn(toolset);
107110
const { register, clearErrors, setValue, control } =
108111
useFormContext<ToolsetEditorForm>();
109112
const { errors } = useFormState<ToolsetEditorForm>({ control });
@@ -119,6 +122,13 @@ export const SettingsForm = ({ isToolsetPublic }: SettingsFormProps) => {
119122
}
120123
}, [clearErrors, endpointField, setValue]);
121124

125+
const disabledReason = useMemo(() => {
126+
if (isToolsetPublic) return PUBLIC_TOOLSET_TOOLTIP;
127+
if (isLoggedIn) return t(CommonI18nKeys.LogOutBeforeEditingToolset);
128+
129+
return undefined;
130+
}, [isLoggedIn, isToolsetPublic, t]);
131+
122132
return (
123133
<div
124134
className="flex size-full grow flex-col space-y-4 divide-y divide-tertiary overflow-hidden overflow-y-auto bg-layer-2 py-4 xl:py-5"
@@ -135,8 +145,8 @@ export const SettingsForm = ({ isToolsetPublic }: SettingsFormProps) => {
135145
placeholder={t(CommonI18nKeys.EnterEndpoint)}
136146
id="endpoint"
137147
error={errors.endpoint?.message}
138-
tooltip={isToolsetPublic ? PUBLIC_TOOLSET_TOOLTIP : undefined}
139-
disabled={isToolsetPublic}
148+
tooltip={disabledReason}
149+
disabled={!!disabledReason}
140150
/>
141151
<Controller
142152
name="protocol"
@@ -155,8 +165,8 @@ export const SettingsForm = ({ isToolsetPublic }: SettingsFormProps) => {
155165
id="protocol"
156166
options={protocolOptions}
157167
closeMenuOnSelect
158-
tooltip={isToolsetPublic ? PUBLIC_TOOLSET_TOOLTIP : undefined}
159-
isDisabled={isToolsetPublic}
168+
tooltip={disabledReason}
169+
isDisabled={!!disabledReason}
160170
/>
161171
)}
162172
/>

apps/chat/src/constants/i18n.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ export enum CommonI18nKeys {
325325
ShareLimitExceeded = '"{{name}}" has already been shared with the maximum specified number of users.',
326326
ShareLimitExceededWithVersion = '"{{name}}" version {{version}} has already been shared with the maximum specified number of users.',
327327
ShareApplicationWithPublicResourcesFailed = 'Sharing failed. You are only allowed to share applications with resources from "My files"',
328+
LogOutBeforeEditingToolset = 'Log out before editing toolset',
328329
}
329330

330331
// errors.json

0 commit comments

Comments
 (0)