Skip to content

Commit

Permalink
fix(chat): add sharing revoke if change code app source folder (Issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kezik committed Jan 28, 2025
1 parent b2f78e0 commit df7f014
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ApplicationType,
CustomApplicationModel,
} from '@/src/types/applications';
import { FeatureType } from '@/src/types/common';
import { Translation } from '@/src/types/translation';

import { ApplicationActions } from '@/src/store/application/application.reducers';
Expand All @@ -24,6 +25,7 @@ import { FilesSelectors } from '@/src/store/files/files.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { ModelsSelectors } from '@/src/store/models/models.reducers';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
import { ShareActions } from '@/src/store/share/share.reducers';
import { UIActions } from '@/src/store/ui/ui.reducers';

import { IMAGE_TYPES } from '@/src/constants/chat';
Expand Down Expand Up @@ -54,6 +56,7 @@ import { MultipleComboBox } from '@/src/components/Common/MultipleComboBox';
import { OptionsDialog } from '@/src/components/Common/OptionsDialog';
import { CustomLogoSelect } from '@/src/components/Settings/CustomLogoSelect';

import { ConfirmDialog } from '../../ConfirmDialog';
import { ViewProps } from '../view-props';
import { CodeEditor } from './CodeEditor';
import { RuntimeVersionSelector } from './RuntimeVersionSelector';
Expand Down Expand Up @@ -91,6 +94,10 @@ export const CodeAppView: FC<ViewProps> = ({
const isCodeEditorDirty = useAppSelector(CodeEditorSelectors.selectIsDirty);

const [editorConfirmation, setEditorConfirmation] = useState<FormData>();
const [confirmSharingRevoke, setConfirmSharingRevoke] = useState<{
description: string;
heading: string;
}>();

useEffect(() => {
return () => {
Expand Down Expand Up @@ -130,6 +137,40 @@ export const CodeAppView: FC<ViewProps> = ({
[files],
);

const handleEdit = useCallback(() => {
const preparedData = getApplicationData(data, type);

const applicationData: CustomApplicationModel = {
...preparedData,
reference: currentReference,
id: selectedApplication.id,
sharedWithMe: isSharedWithMe,
};

dispatch(
ApplicationActions.update({
oldApplicationId: selectedApplication.id,
applicationData,
}),
);

if (isAppDeployed) {
dispatch(
UIActions.showWarningToast(
t('Saved changes will be applied during next deployment'),
),
);
}
}, [
currentReference,
dispatch,
isAppDeployed,
isSharedWithMe,
selectedApplication.id,
t,
type,
]);

const handleSubmit = useCallback(
(data: FormData) => {
const preparedData = getApplicationData(data, type);
Expand All @@ -144,25 +185,21 @@ export const CodeAppView: FC<ViewProps> = ({
currentReference &&
selectedApplication.id
) {
const applicationData: CustomApplicationModel = {
...preparedData,
reference: currentReference,
id: selectedApplication.id,
sharedWithMe: isSharedWithMe,
};

dispatch(
ApplicationActions.update({
oldApplicationId: selectedApplication.id,
applicationData,
}),
);
isAppDeployed &&
dispatch(
UIActions.showWarningToast(
t('Saved changes will be applied during next deployment'),
),
);
if (
type === ApplicationType.CODE_APP &&
preparedData.function?.sourceFolder !==
selectedApplication?.function?.sourceFolder &&
selectedApplication
) {
setConfirmSharingRevoke({
description:
'Changing of source folder will stop sharing and other users will no longer see this application.',
heading: 'Confirm changing source folder',
});
return;
}

handleEdit();
} else {
dispatch(ApplicationActions.create(preparedData));
}
Expand All @@ -172,12 +209,10 @@ export const CodeAppView: FC<ViewProps> = ({
[
currentReference,
dispatch,
isAppDeployed,
handleEdit,
isEdit,
isSharedWithMe,
onClose,
selectedApplication,
t,
type,
],
);
Expand Down Expand Up @@ -378,6 +413,29 @@ export const CodeAppView: FC<ViewProps> = ({
/>
</div>

{confirmSharingRevoke && (
<ConfirmDialog
isOpen={false}
heading={t(confirmSharingRevoke.description)}
description={t(confirmSharingRevoke.description)}
confirmLabel={t('Confirm')}
cancelLabel={t('Cancel')}
onClose={(result) => {
setConfirmSharingRevoke(undefined);

if (result) {
dispatch(
ShareActions.revokeAccess({
resourceId: selectedApplication.id,
featureType: FeatureType.Application,
}),
);
handleSave();
}
}}
/>
)}

<OptionsDialog
isOpen={!!editorConfirmation}
heading={t('Do you want to save changes in the code editor?')}
Expand Down
1 change: 0 additions & 1 deletion apps/chat/src/pages/marketplace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { Feature } from '@epam/ai-dial-shared';

function Marketplace() {
const isProfileOpen = useAppSelector(UISelectors.selectIsProfileOpen);

const isMarketplaceEnabled = useAppSelector((state) =>
SettingsSelectors.isFeatureEnabled(state, Feature.Marketplace),
);
Expand Down

0 comments on commit df7f014

Please sign in to comment.