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(chat): fix files unpublish, remove version selector from original entities, remove version postfix for files and apps, remove delete button from public prompts (Issues #2065, #2085, #2066, #2084) #2087

Merged
merged 4 commits into from
Sep 10, 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
20 changes: 15 additions & 5 deletions apps/chat/src/components/Chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getSelectedAddons,
getValidEntitiesFromIds,
} from '@/src/utils/app/conversation';
import { getRootId } from '@/src/utils/app/id';
import { isSmallScreen } from '@/src/utils/app/mobile';

import { Conversation } from '@/src/types/chat';
Expand All @@ -28,6 +29,8 @@ import { ModelsSelectors } from '@/src/store/models/models.reducers';
import { PublicationActions } from '@/src/store/publication/publication.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';

import { PUBLIC_URL_PREFIX } from '@/src/constants/public';

import { ConfirmDialog } from '@/src/components/Common/ConfirmDialog';

import { ModelIcon } from '../Chatbar/ModelIcon';
Expand Down Expand Up @@ -329,11 +332,18 @@ export const ChatHeader = ({
{isSmallScreen() ? t('Stop') : t('Stop playback')}
</button>
)}
<VersionSelector
entity={conversation}
onChangeSelectedVersion={handleChangeSelectedVersion}
featureType={FeatureType.Chat}
/>
{conversation.id.startsWith(
getRootId({
featureType: FeatureType.Chat,
bucket: PUBLIC_URL_PREFIX,
}),
) && (
<VersionSelector
entity={conversation}
onChangeSelectedVersion={handleChangeSelectedVersion}
featureType={FeatureType.Chat}
/>
)}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,16 @@ export const PublicationItemsList = memo(
ConversationsSelectors.selectFolders,
);

const memoizedItems = useMemo(
() => [...promptFolders, ...conversationFolders],
[conversationFolders, promptFolders],
);

const { fullyChosenFolderIds, partialChosenFolderIds } = useAppSelector(
(state) =>
PublicationSelectors.selectChosenFolderIds(
state,
[...promptFolders, ...conversationFolders],
memoizedItems,
entities,
),
);
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/Publish/PublishWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ export function PublishModal({
type === SharingType.PromptFolder
? item.id.replace(folderOldPathPartsRegExp, '')
: item.id,
versionsRef.current[item.id],
type,
versionsRef.current[item.id],
),
}))),
...(publishAction === PublishActions.DELETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { useTranslation } from 'next-i18next';

import classNames from 'classnames';

import { getRootId } from '@/src/utils/app/id';

import { FeatureType } from '@/src/types/common';
import { ModalState } from '@/src/types/modal';
import { Prompt } from '@/src/types/prompt';
Expand All @@ -22,6 +24,8 @@ import {
PublicationSelectors,
} from '@/src/store/publication/publication.reducers';

import { PUBLIC_URL_PREFIX } from '@/src/constants/public';

import { NotFoundEntity } from '@/src/components/Common/NotFoundEntity';
import Tooltip from '@/src/components/Common/Tooltip';

Expand Down Expand Up @@ -99,6 +103,13 @@ export const PreviewPromptModal = ({
</Tooltip>
);

const isPublicPrompt = prompt.id.startsWith(
getRootId({
featureType: FeatureType.Prompt,
bucket: PUBLIC_URL_PREFIX,
}),
);

return (
<Modal
portalId="theme-main"
Expand Down Expand Up @@ -165,26 +176,31 @@ export const PreviewPromptModal = ({
<>
<div className="flex h-[34px] gap-2">
{exportButton}
<Tooltip
placement="top"
isTriggerClickable
tooltip={t('Delete prompt')}
>
<button
onClick={onDelete}
className="flex cursor-pointer items-center justify-center rounded p-[5px] text-secondary hover:bg-accent-primary-alpha hover:text-accent-primary"
data-qa="delete-prompt"
{!isPublicPrompt && (
<Tooltip
placement="top"
isTriggerClickable
tooltip={t('Delete prompt')}
>
<IconTrashX size={24} strokeWidth="1.5" />
</button>
</Tooltip>
<button
onClick={onDelete}
className="flex cursor-pointer items-center justify-center rounded p-[5px] text-secondary hover:bg-accent-primary-alpha hover:text-accent-primary"
data-qa="delete-prompt"
>
<IconTrashX size={24} strokeWidth="1.5" />
</button>
</Tooltip>
)}
</div>
<div className="flex items-center gap-4">
<VersionSelector
entity={prompt}
onChangeSelectedVersion={handleChangeSelectedVersion}
featureType={FeatureType.Prompt}
/>
{isPublicPrompt && (
<VersionSelector
entity={prompt}
onChangeSelectedVersion={handleChangeSelectedVersion}
featureType={FeatureType.Prompt}
/>
)}

<button
className="button button-secondary"
data-qa="duplicate-prompt"
Expand Down
8 changes: 6 additions & 2 deletions apps/chat/src/utils/app/publications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const createTargetUrl = (
featureType: FeatureType,
publicPath: string,
id: string,
version: string | undefined,
type?: SharingType,
type: SharingType,
version?: string,
) => {
const baseElements =
type === SharingType.PromptFolder || type === SharingType.ConversationFolder
Expand All @@ -45,6 +45,10 @@ export const createTargetUrl = (
...lastElement,
);

if (featureType !== FeatureType.Chat && featureType !== FeatureType.Prompt) {
IlyaBondar marked this conversation as resolved.
Show resolved Hide resolved
return constructedUrlWithoutVersion;
}

if (version && isVersionValid(version)) {
return addVersionToId(constructedUrlWithoutVersion, version);
}
Expand Down