Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/epam/ai-dial-chat in…
Browse files Browse the repository at this point in the history
…to fix/2021-delete-app-tost
  • Loading branch information
Magomed-Elbi Dzhukalaev committed Sep 10, 2024
2 parents c8025e6 + a5befa4 commit 0d6b874
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 37 deletions.
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/ModelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export const ModelList = ({

const modelsMapKeys = Object.keys(modelsMap);

onSelect(recentModelsIds[1] ?? modelsMap[modelsMapKeys[0]]);
onSelect(recentModelsIds[1] ?? modelsMap[modelsMapKeys[0]]?.reference);
}, [currentEntity, modelsMap, onSelect, recentModelsIds, dispatch]);

const handleConfirmDialogClose = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chatbar/ChatFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const ChatFolderTemplate = ({
if (folder.sharedWithMe) {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: folder.id,
resourceIds: [folder.id],
isFolder: true,
featureType: FeatureType.Chat,
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chatbar/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export const ConversationComponent = ({
if (conversation.sharedWithMe) {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: conversation.id,
resourceIds: [conversation.id],
featureType: FeatureType.Chat,
}),
);
Expand Down
27 changes: 24 additions & 3 deletions apps/chat/src/components/Files/FileManagerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ export const FileManagerModal = ({
[canAttachFiles, dispatch, forceShowSelectCheckBox],
);

const handleDeleteFolder = useCallback(
const handleDiscardSharedWithMeFolder = useCallback(
(folderId: string) => {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: folderId,
resourceIds: [folderId],
featureType: FeatureType.File,
isFolder: true,
}),
Expand All @@ -562,6 +562,16 @@ export const FileManagerModal = ({
return;
}
if (deletingFileIds.length) {
const sharedWithMeFilesIds = sharedWithMeRootFiles
.filter(({ id }) => deletingFileIds.includes(id))
.map(({ id }) => id);

dispatch(
ShareActions.discardSharedWithMe({
resourceIds: sharedWithMeFilesIds,
featureType: FeatureType.File,
}),
);
dispatch(FilesActions.deleteFilesList({ fileIds: deletingFileIds }));
if (selectedFilesIds === deletingFileIds) {
setSelectedFilesIds([]);
Expand All @@ -570,6 +580,15 @@ export const FileManagerModal = ({
if (deletingFolderIds.length) {
// TODO: implement
// dispatch(FilesActions.deleteFolderList({ folderIds: deletingFolderIds }));
const sharedWithMeFoldersIds = sharedWithMeRootFolders
.filter(({ id }) => deletingFolderIds.includes(id))
.map(({ id }) => id);
dispatch(
ShareActions.discardSharedWithMe({
resourceIds: sharedWithMeFoldersIds,
featureType: FeatureType.File,
}),
);
if (selectedFolderIds === deletingFolderIds) {
setSelectedFolderIds([]);
}
Expand All @@ -580,6 +599,8 @@ export const FileManagerModal = ({
dispatch,
selectedFilesIds,
selectedFolderIds,
sharedWithMeRootFiles,
sharedWithMeRootFolders,
]);

const handleDownloadMultipleFiles = useCallback(() => {
Expand Down Expand Up @@ -759,7 +780,7 @@ export const FileManagerModal = ({
canSelectFolders={canAttachFolders}
showTooltip={showTooltip}
onSelectFolder={handleFolderToggle}
onDeleteFolder={handleDeleteFolder}
onDeleteFolder={handleDiscardSharedWithMeFolder}
/>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Promptbar/components/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const PromptComponent = ({
if (prompt.sharedWithMe) {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: prompt.id,
resourceIds: [prompt.id],
featureType: FeatureType.Prompt,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const PromptFolderTemplate = ({
if (folder.sharedWithMe) {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: folder.id,
resourceIds: [folder.id],
isFolder: true,
featureType: FeatureType.Prompt,
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/store/conversations/conversations.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ const createNewConversationsEpic: AppEpic = (action$, state$) =>
),
messages: [],
model: {
id: model.id,
id: model.reference,
},
prompt: DEFAULT_SYSTEM_PROMPT,
temperature:
Expand Down
10 changes: 0 additions & 10 deletions apps/chat/src/store/files/files.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { FeatureType, UploadStatus } from '@/src/types/common';
import { AppEpic } from '@/src/types/store';

import { PublicationActions } from '../publication/publication.reducers';
import { ShareActions } from '../share/share.reducers';
import { UIActions, UISelectors } from '../ui/ui.reducers';
import { FilesActions, FilesSelectors } from './files.reducers';

Expand Down Expand Up @@ -169,15 +168,6 @@ const deleteFileEpic: AppEpic = (action$, state$) =>
(file) => file.id === payload.fileId,
);

if (file && file.sharedWithMe) {
return of(
ShareActions.discardSharedWithMe({
resourceId: file.id,
featureType: FeatureType.File,
}),
);
}

if (!file?.serverSynced) {
return concat(
of(
Expand Down
11 changes: 7 additions & 4 deletions apps/chat/src/store/overlay/overlay.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,19 @@ const setOverlayOptionsEpic: AppEpic = (action$, state$) =>
if (currentConversation) {
const models = ModelsSelectors.selectModels(state$.value);

const newAiEntity = models.find(({ id }) => id === finalModelId) as
| DialAIEntityModel
| undefined;
const newAiEntity = models.find(
({ reference, id }) =>
id === finalModelId || reference === finalModelId,
) as DialAIEntityModel | undefined;

actions.push(
of(
ConversationsActions.updateConversation({
id: currentConversation.id,
values: {
model: { id: finalModelId },
model: {
id: newAiEntity?.reference ?? finalModelId,
},
},
}),
),
Expand Down
37 changes: 24 additions & 13 deletions apps/chat/src/store/share/share.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,31 @@ const discardSharedWithMeEpic: AppEpic = (action$) =>
action$.pipe(
filter(ShareActions.discardSharedWithMe.match),
switchMap(({ payload }) => {
const resourceUrl = payload.isFolder
? ApiUtils.encodeApiUrl(payload.resourceId) + '/'
: ApiUtils.encodeApiUrl(payload.resourceId);
const resourceUrls = payload.isFolder
? payload.resourceIds.map(
(resourceId) => ApiUtils.encodeApiUrl(resourceId) + '/',
)
: payload.resourceIds.map((resourceId) =>
ApiUtils.encodeApiUrl(resourceId),
);

return ShareService.shareDiscard([resourceUrl]).pipe(
map(() => ShareActions.discardSharedWithMeSuccess(payload)),
return ShareService.shareDiscard(resourceUrls).pipe(
switchMap(() => {
if (!payload.isFolder && payload.featureType === FeatureType.File) {
return EMPTY;
}
const actions: Observable<AnyAction>[] = payload.resourceIds.map(
(resourceId) =>
of(
ShareActions.discardSharedWithMeSuccess({
resourceId,
featureType: payload.featureType,
isFolder: payload.isFolder,
}),
),
);
return concat(...actions);
}),
catchError(() => of(ShareActions.discardSharedWithMeFail())),
);
}),
Expand Down Expand Up @@ -970,14 +989,6 @@ const discardSharedWithMeSuccessEpic: AppEpic = (action$, state$) =>
}

if (payload.featureType === FeatureType.File) {
if (!payload.isFolder) {
return of(
FilesActions.deleteFileSuccess({
fileId: payload.resourceId,
}),
);
}

const folders = FilesSelectors.selectFolders(state$.value);
return concat(
of(
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/store/share/share.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const shareSlice = createSlice({
discardSharedWithMe: (
state,
_action: PayloadAction<{
resourceId: string;
resourceIds: string[];
featureType: FeatureType;
isFolder?: boolean;
}>,
Expand Down

0 comments on commit 0d6b874

Please sign in to comment.