Skip to content

Commit

Permalink
fix(chat): add flag for updating new conversation (Issue #2267) (#2607)
Browse files Browse the repository at this point in the history
Co-authored-by: Magomed-Elbi Dzhukalaev <magomed-elbi_dzhukalaev@epam.com>
Co-authored-by: Ilya Bondar <ilya_bondar@epam.com>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent 777a3a2 commit 5904018
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
12 changes: 9 additions & 3 deletions apps/chat/src/components/Chat/ModelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { SharingType } from '@/src/types/share';
import { Translation } from '@/src/types/translation';

import { ApplicationActions } from '@/src/store/application/application.reducers';
import { ConversationsSelectors } from '@/src/store/conversations/conversations.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { ModelsSelectors } from '@/src/store/models/models.reducers';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
Expand Down Expand Up @@ -84,6 +85,9 @@ const ModelGroup = ({
const { t } = useTranslation(Translation.Chat);

const recentModelsIds = useAppSelector(ModelsSelectors.selectRecentModelsIds);
const isNewConversationUpdating = useAppSelector(
ConversationsSelectors.selectIsNewConversationUpdating,
);

const [isOpened, setIsOpened] = useState(false);

Expand Down Expand Up @@ -129,7 +133,7 @@ const ModelGroup = ({
name: t('Edit'),
dataQa: 'edit',
display: !isPublicEntity,
disabled: isModifyDisabled,
disabled: isModifyDisabled || isNewConversationUpdating,
Icon: IconPencilMinus,
onClick: (e: React.MouseEvent) => {
e.stopPropagation();
Expand Down Expand Up @@ -162,7 +166,8 @@ const ModelGroup = ({
{
name: t('Delete'),
dataQa: 'delete',
disabled: isModifyDisabled && !isPublicEntity,
disabled:
(isModifyDisabled && !isPublicEntity) || isNewConversationUpdating,
display: !isPublicEntity,
Icon: IconTrashX,
onClick: (e: React.MouseEvent) => {
Expand All @@ -181,6 +186,7 @@ const ModelGroup = ({
handlePublish,
handleOpenDeleteConfirmModal,
isModifyDisabled,
isNewConversationUpdating,
],
);

Expand All @@ -201,7 +207,7 @@ const ModelGroup = ({
!disabled ? 'cursor-pointer' : 'cursor-not-allowed',
)}
onClick={(e) => {
if (disabled) {
if (disabled || isNewConversationUpdating) {
return;
}
if (
Expand Down
14 changes: 12 additions & 2 deletions apps/chat/src/store/conversations/conversations.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const initialState: ConversationsState = {
loadedCharts: [],
chartLoading: false,
isActiveNewConversationRequest: false,
isNewConversationUpdating: false,
isMessageSending: false,
loadedCustomAttachmentsData: [],
customAttachmentDataLoading: false,
Expand All @@ -76,6 +77,9 @@ export const conversationsSlice = createSlice({
if (state.isMessageSending) {
state.isMessageSending = false;
}
if (state.isNewConversationUpdating) {
state.isNewConversationUpdating = false;
}
},
saveConversationFail: (state, { payload }: PayloadAction<Conversation>) => {
state.conversations = state.conversations.map((conv) => {
Expand All @@ -88,11 +92,16 @@ export const conversationsSlice = createSlice({

return conv;
});
state.isNewConversationUpdating = false;
},
recreateConversation: (
state,
_action: PayloadAction<{ new: Conversation; old: Conversation }>,
) => state,
action: PayloadAction<{ new: Conversation; old: Conversation }>,
) => {
if (!action.payload.old.messages.length) {
state.isNewConversationUpdating = true;
}
},
recreateConversationFail: (
state,
{
Expand All @@ -102,6 +111,7 @@ export const conversationsSlice = createSlice({
oldConversation: Conversation;
}>,
) => {
state.isNewConversationUpdating = false;
state.conversations = state.conversations.map((conv) => {
if (conv.id === payload.newId) {
const conversation = conv as Conversation;
Expand Down
7 changes: 7 additions & 0 deletions apps/chat/src/store/conversations/conversations.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,3 +835,10 @@ export const selectChosenFolderIds = createSelector(
return { fullyChosenFolderIds, partialChosenFolderIds };
},
);

export const selectIsNewConversationUpdating = createSelector(
[rootSelector],
(state) => {
return state.isNewConversationUpdating;
},
);
1 change: 1 addition & 0 deletions apps/chat/src/store/conversations/conversations.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ConversationsState {
foldersStatus: UploadStatus;
loadingFolderIds: string[];
isActiveNewConversationRequest: boolean;
isNewConversationUpdating: boolean;
isMessageSending: boolean;
loadedCharts: { url: string; data: PlotParams }[];
chartLoading: boolean;
Expand Down

0 comments on commit 5904018

Please sign in to comment.