Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: release 0.5 hotfixes #711

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 37 additions & 18 deletions apps/chat/src/components/Chatbar/ChatFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { DragEvent, useCallback, useEffect, useMemo, useState } from 'react';

import { useTranslation } from 'next-i18next';

import { isEntityNameOnSameLevelUnique } from '@/src/utils/app/common';
import { compareEntitiesByName } from '@/src/utils/app/folders';
import { isRootId } from '@/src/utils/app/id';
import { getRootId, isRootId } from '@/src/utils/app/id';
import { MoveType } from '@/src/utils/app/move';
import {
PublishedWithMeFilter,
SharedWithMeFilter,
} from '@/src/utils/app/search';
import { isEntityOrParentsExternal } from '@/src/utils/app/share';
import { ApiKeys } from '@/src/utils/server/api';

import { Conversation } from '@/src/types/chat';
import { FeatureType } from '@/src/types/common';
Expand All @@ -23,7 +25,7 @@ import {
} from '@/src/store/conversations/conversations.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';
import { UIActions, UISelectors } from '@/src/store/ui/ui.reducers';

import {
MAX_CHAT_AND_PROMPT_FOLDERS_DEPTH,
Expand Down Expand Up @@ -51,6 +53,8 @@ const ChatFolderTemplate = ({
filters,
includeEmpty = false,
}: ChatFolderProps) => {
const { t } = useTranslation(Translation.SideBar);

const dispatch = useAppDispatch();

const searchTerm = useAppSelector(ConversationsSelectors.selectSearchTerm);
Expand Down Expand Up @@ -122,15 +126,40 @@ const ChatFolderTemplate = ({
[dispatch],
);
const onDropBetweenFolders = useCallback(
(folder: FolderInterface, parentFolderId: string | undefined) => {
(folder: FolderInterface) => {
const folderId = getRootId({ apiKey: ApiKeys.Conversations });

if (
!isEntityNameOnSameLevelUnique(
folder.name,
{ ...folder, folderId },
allFolders,
)
) {
dispatch(
UIActions.showToast({
message: t(
'Folder with name "{{name}}" already exists at the root.',
{
ns: 'folder',
name: folder.name,
},
),
type: 'error',
}),
);

return;
}

dispatch(
ConversationsActions.updateFolder({
folderId: folder.id,
values: { folderId: parentFolderId },
values: { folderId },
}),
);
},
[dispatch],
[allFolders, dispatch, t],
);

const handleFolderClick = useCallback(
Expand All @@ -145,7 +174,6 @@ const ChatFolderTemplate = ({
<BetweenFoldersLine
level={0}
onDrop={onDropBetweenFolders}
parentFolderId={folder.folderId}
featureType={FeatureType.Chat}
denyDrop={isExternal}
/>
Expand Down Expand Up @@ -181,7 +209,6 @@ const ChatFolderTemplate = ({
<BetweenFoldersLine
level={0}
onDrop={onDropBetweenFolders}
parentFolderId={folder.folderId}
featureType={FeatureType.Chat}
denyDrop={isExternal}
/>
Expand Down Expand Up @@ -302,7 +329,6 @@ export function ChatFolders() {
const isFilterEmpty = useAppSelector(
ConversationsSelectors.selectIsEmptySearchFilter,
);
const searchTerm = useAppSelector(ConversationsSelectors.selectSearchTerm);
const commonItemFilter = useAppSelector(
ConversationsSelectors.selectMyItemsFilters,
);
Expand All @@ -324,15 +350,15 @@ export function ChatFolders() {
filters: PublishedWithMeFilter,
displayRootFiles: true,
dataQa: 'published-with-me',
openByDefault: !!searchTerm.length,
openByDefault: true,
},
{
hidden: !isSharingEnabled || !isFilterEmpty,
name: t('Shared with me'),
filters: SharedWithMeFilter,
displayRootFiles: true,
dataQa: 'shared-with-me',
openByDefault: !!searchTerm.length,
openByDefault: true,
},
{
name: t('Pinned chats'),
Expand All @@ -342,14 +368,7 @@ export function ChatFolders() {
dataQa: 'pinned-chats',
},
].filter(({ hidden }) => !hidden),
[
commonItemFilter,
isFilterEmpty,
isPublishingEnabled,
isSharingEnabled,
searchTerm.length,
t,
],
[commonItemFilter, isFilterEmpty, isPublishingEnabled, isSharingEnabled, t],
);

return (
Expand Down
39 changes: 36 additions & 3 deletions apps/chat/src/components/Chatbar/Chatbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { DragEvent, useCallback } from 'react';

import { useTranslation } from 'next-i18next';

import { isEntityNameOnSameLevelUnique } from '@/src/utils/app/common';
import { getRootId } from '@/src/utils/app/id';
import { MoveType } from '@/src/utils/app/move';
import { ApiKeys } from '@/src/utils/server/api';

import { ConversationInfo } from '@/src/types/chat';
import { FeatureType } from '@/src/types/common';
Expand All @@ -14,7 +17,7 @@ import {
ConversationsSelectors,
} from '@/src/store/conversations/conversations.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { UISelectors } from '@/src/store/ui/ui.reducers';
import { UIActions, UISelectors } from '@/src/store/ui/ui.reducers';

import { DEFAULT_CONVERSATION_NAME } from '@/src/constants/default-settings';

Expand Down Expand Up @@ -54,10 +57,15 @@ const ChatActionsBlock = () => {
};

export const Chatbar = () => {
const { t } = useTranslation(Translation.Chat);

const dispatch = useAppDispatch();

const showChatbar = useAppSelector(UISelectors.selectShowChatbar);
const searchTerm = useAppSelector(ConversationsSelectors.selectSearchTerm);
const allConversations = useAppSelector(
ConversationsSelectors.selectConversations,
);
const areEntitiesUploaded = useAppSelector(
ConversationsSelectors.areConversationsUploaded,
);
Expand All @@ -82,17 +90,42 @@ export const Chatbar = () => {
const conversationData = e.dataTransfer.getData(MoveType.Conversation);
if (conversationData) {
const conversation = JSON.parse(conversationData);
const folderId = getRootId({ apiKey: ApiKeys.Conversations });

if (
!isEntityNameOnSameLevelUnique(
conversation.name,
{ ...conversation, folderId },
allConversations,
)
) {
dispatch(
UIActions.showToast({
message: t(
'Prompt with name "{{name}}" already exists at the root.',
{
ns: 'prompt',
name: conversation.name,
},
),
type: 'error',
}),
);

return;
}

dispatch(
ConversationsActions.updateConversation({
id: conversation.id,
values: { folderId: undefined },
values: { folderId },
}),
);
dispatch(ConversationsActions.resetSearch());
}
}
},
[dispatch],
[allConversations, dispatch, t],
);

return (
Expand Down
37 changes: 28 additions & 9 deletions apps/chat/src/components/Chatbar/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
FeatureType,
isNotLoaded,
} from '@/src/types/common';
import { MoveToFolderProps } from '@/src/types/folder';
import { SharingType } from '@/src/types/share';
import { Translation } from '@/src/types/translation';

Expand Down Expand Up @@ -372,14 +373,32 @@ export const ConversationComponent = ({ item: conversation, level }: Props) => {
}, []);

const handleMoveToFolder = useCallback(
({
folderId,
isNewFolder,
}: {
folderId?: string;
isNewFolder?: boolean;
}) => {
const folderPath = isNewFolder ? newFolderName : folderId;
({ folderId, isNewFolder }: MoveToFolderProps) => {
const folderPath = (isNewFolder ? newFolderName : folderId) as string;

if (
!isEntityNameOnSameLevelUnique(
conversation.name,
{ ...conversation, folderId: folderPath },
allConversations,
)
) {
dispatch(
UIActions.showToast({
message: t(
'Conversation with name "{{name}}" already exists in this folder.',
{
ns: 'chat',
name: conversation.name,
},
),
type: 'error',
}),
);

return;
}

if (isNewFolder) {
dispatch(
ConversationsActions.createFolder({
Expand All @@ -402,7 +421,7 @@ export const ConversationComponent = ({ item: conversation, level }: Props) => {
}),
);
},
[conversation.id, dispatch, newFolderName],
[allConversations, conversation, dispatch, newFolderName, t],
);
const handleOpenExportModal = useCallback(() => {
setIsShowExportModal(true);
Expand Down
40 changes: 35 additions & 5 deletions apps/chat/src/components/Promptbar/Promptbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { DragEvent, useCallback } from 'react';

import { useTranslation } from 'next-i18next';

import { isEntityNameOnSameLevelUnique } from '@/src/utils/app/common';
import { getRootId } from '@/src/utils/app/id';
import { MoveType } from '@/src/utils/app/move';
import { ApiKeys } from '@/src/utils/server/api';

import { FeatureType } from '@/src/types/common';
import { PromptInfo } from '@/src/types/prompt';
Expand All @@ -14,7 +17,7 @@ import {
PromptsActions,
PromptsSelectors,
} from '@/src/store/prompts/prompts.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';
import { UIActions, UISelectors } from '@/src/store/ui/ui.reducers';

import { PromptFolders } from './components/PromptFolders';
import { PromptbarSettings } from './components/PromptbarSettings';
Expand Down Expand Up @@ -46,8 +49,11 @@ const PromptActionsBlock = () => {
};

const Promptbar = () => {
const { t } = useTranslation(Translation.PromptBar);

const dispatch = useAppDispatch();
const showPromptbar = useAppSelector(UISelectors.selectShowPromptbar);
const allPrompts = useAppSelector(PromptsSelectors.selectPrompts);
const searchTerm = useAppSelector(PromptsSelectors.selectSearchTerm);
const myItemsFilters = useAppSelector(PromptsSelectors.selectMyItemsFilters);
const areEntitiesUploaded = useAppSelector(
Expand All @@ -64,20 +70,44 @@ const Promptbar = () => {
(e: DragEvent<HTMLDivElement>) => {
if (e.dataTransfer) {
const promptData = e.dataTransfer.getData(MoveType.Prompt);
const folderId = getRootId({ apiKey: ApiKeys.Prompts });

if (promptData) {
const prompt = JSON.parse(promptData);

if (
!isEntityNameOnSameLevelUnique(
prompt.name,
{ ...prompt, folderId },
allPrompts,
)
) {
dispatch(
UIActions.showToast({
message: t(
'Prompt with name "{{name}}" already exists at the root.',
{
ns: 'prompt',
name: prompt.name,
},
),
type: 'error',
}),
);

return;
}

dispatch(
PromptsActions.updatePrompt({
id: prompt.id,
values: {
folderId: e.currentTarget.dataset.folderId,
},
values: { folderId },
}),
);
}
}
},
[dispatch],
[allPrompts, dispatch, t],
);

return (
Expand Down
Loading
Loading