Skip to content

Commit

Permalink
Merge branch 'development' of github.com:epam/ai-dial-chat into devel…
Browse files Browse the repository at this point in the history
…opment
  • Loading branch information
irinakartun committed Aug 26, 2024
2 parents d378a9e + 0293683 commit ad52731
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 70 deletions.
5 changes: 2 additions & 3 deletions apps/chat/src/components/Chat/ChatInput/PromptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ export const PromptList: FC<Props> = ({
},
});
const promptResources = useAppSelector((state) =>
PublicationSelectors.selectFilteredPublicationResources(
state,
PublicationSelectors.selectFilteredPublicationResources(state, [
FeatureType.Prompt,
),
]),
);

const dismiss = useDismiss(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export function PublicationControlsView<
dispatch(
PublicationActions.markResourceAsReviewed({
id: entity.id,
publicationUrl: resourceToReview.publicationUrl,
}),
);
}
Expand Down
60 changes: 47 additions & 13 deletions apps/chat/src/components/Chat/Publish/PublicationHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ import { Publication, PublicationRule } from '@/src/types/publication';
import { Translation } from '@/src/types/translation';

import { ApplicationActions } from '@/src/store/application/application.reducers';
import { ConversationsActions } from '@/src/store/conversations/conversations.reducers';
import {
ConversationsActions,
ConversationsSelectors,
} from '@/src/store/conversations/conversations.reducers';
import { FilesSelectors } from '@/src/store/files/files.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { PromptsActions } from '@/src/store/prompts/prompts.reducers';
import {
PromptsActions,
PromptsSelectors,
} from '@/src/store/prompts/prompts.reducers';
import {
PublicationActions,
PublicationSelectors,
Expand Down Expand Up @@ -108,6 +115,12 @@ export function PublicationHandler({ publication }: Props) {

const [isCompareModalOpened, setIsCompareModalOpened] = useState(false);

// TODO: reminder to include applications then
const files = useAppSelector(FilesSelectors.selectFiles);
const prompts = useAppSelector(PromptsSelectors.selectPrompts);
const conversations = useAppSelector(
ConversationsSelectors.selectConversations,
);
const resourcesToReview = useAppSelector((state) =>
PublicationSelectors.selectResourcesToReviewByPublicationUrl(
state,
Expand All @@ -127,6 +140,14 @@ export function PublicationHandler({ publication }: Props) {
PublicationSelectors.selectIsApplicationReview,
);

const mappedNotExistEntitiesIds = useMemo(
() =>
[...files, ...conversations, ...prompts]
.filter((entity) => entity.publicationInfo?.isNotExist)
.map((entity) => entity.id),
[conversations, files, prompts],
);

useEffect(() => {
if (publication.targetFolder !== PUBLIC_URL_PREFIX) {
dispatch(
Expand Down Expand Up @@ -155,19 +176,32 @@ export function PublicationHandler({ publication }: Props) {
useEffect(() => {
// we do not need to review files
const resourcesToReview = publication.resources.filter(
(r) => !isFileId(r.targetUrl),
(resource) => !isFileId(resource.targetUrl),
);

dispatch(
PublicationActions.setPublicationsToReview({
items: resourcesToReview.map((r) => ({
reviewed: false,
reviewUrl: r.reviewUrl,
publicationUrl: publication.url,
})),
}),
const resourcesToReviewIds = resourcesToReview.map(
(resource) => resource.reviewUrl,
);
}, [dispatch, publication.resources, publication.url]);
const isSomeResourceNotExist = resourcesToReviewIds.some((id) =>
mappedNotExistEntitiesIds.includes(id),
);

if (!isSomeResourceNotExist) {
dispatch(
PublicationActions.setPublicationsToReview({
items: resourcesToReview.map((r) => ({
reviewed: false,
reviewUrl: r.reviewUrl,
publicationUrl: publication.url,
})),
}),
);
}
}, [
dispatch,
mappedNotExistEntitiesIds,
publication.resources,
publication.url,
]);

const handlePublicationReview = useCallback(() => {
const conversationsToReviewIds = resourcesToReview.filter(
Expand Down
11 changes: 10 additions & 1 deletion apps/chat/src/components/Chatbar/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ export function ConversationView({
const isExternal = useAppSelector((state) =>
isEntityOrParentsExternal(state, conversation, FeatureType.Chat),
);
const selectedPublicationUrl = useAppSelector(
PublicationSelectors.selectSelectedPublicationUrl,
);
const resourceToReview = useAppSelector((state) =>
PublicationSelectors.selectResourceToReviewByReviewUrl(
PublicationSelectors.selectResourceToReviewByReviewAndPublicationUrls(
state,
conversation.id,
additionalItemData?.publicationUrl,
),
);
const selectedConversationIds = useAppSelector(
Expand All @@ -120,6 +124,10 @@ export function ConversationView({
});
}, [conversation.id]);

const isPartOfSelectedPublication =
!additionalItemData?.publicationUrl ||
selectedPublicationUrl === additionalItemData?.publicationUrl;

return (
<>
<div
Expand Down Expand Up @@ -159,6 +167,7 @@ export function ConversationView({
'group-hover/conversation-item:bg-accent-secondary-alpha',
(selectedConversationIds.includes(conversation.id) ||
isContextMenu) &&
isPartOfSelectedPublication &&
'bg-accent-secondary-alpha',
)}
/>
Expand Down
19 changes: 12 additions & 7 deletions apps/chat/src/components/Folder/Folder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ const Folder = <T extends ConversationInfo | PromptInfo | DialFile>({
);

const hasResourcesToReview = useAppSelector((state) =>
PublicationSelectors.selectIsFolderContainsResourcesToApprove(
PublicationSelectors.selectIsFolderContainsResourcesToReview(
state,
currentFolder.id,
additionalItemData?.publicationUrl,
),
);
const isNameInvalid = isEntityNameInvalid(currentFolder.name);
Expand Down Expand Up @@ -890,9 +891,11 @@ const Folder = <T extends ConversationInfo | PromptInfo | DialFile>({
: ''
}
>
{hasResourcesToReview && isSidePanelFolder && (
<ReviewDot className="group-hover/folder-item:bg-accent-primary-alpha" />
)}
{hasResourcesToReview &&
isSidePanelFolder &&
additionalItemData?.publicationUrl && (
<ReviewDot className="group-hover/folder-item:bg-accent-primary-alpha" />
)}
<IconFolder
size={18}
className={classNames(
Expand Down Expand Up @@ -1022,9 +1025,11 @@ const Folder = <T extends ConversationInfo | PromptInfo | DialFile>({
: ''
}
>
{hasResourcesToReview && isSidePanelFolder && (
<ReviewDot className="group-hover/folder-item:bg-accent-primary-alpha" />
)}
{hasResourcesToReview &&
isSidePanelFolder &&
additionalItemData?.publicationUrl && (
<ReviewDot className="group-hover/folder-item:bg-accent-primary-alpha" />
)}
<IconFolder size={18} className="mr-1 text-secondary" />
</ShareIcon>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ export const PreviewPromptModal = ({
onDuplicate,
onDelete,
onClose,
isPublicationPreview,
prompt,
}: Props) => {
const { t } = useTranslation(Translation.PromptBar);

const isLoading = useAppSelector(PromptsSelectors.isPromptLoading);
const selectedPublication = useAppSelector(
PublicationSelectors.selectSelectedPublication,
);
const resourceToReview = useAppSelector((state) =>
PublicationSelectors.selectResourceToReviewByReviewUrl(state, prompt.id),
);
Expand Down Expand Up @@ -130,31 +126,23 @@ export const PreviewPromptModal = ({
)}
</ul>
<div className="flex items-center justify-between px-3 md:p-6">
{!isPublicationPreview || !resourceToReview ? (
{!resourceToReview ? (
<>
<div className="flex h-[34px] gap-2">
{exportButton}
{(!selectedPublication ||
(selectedPublication &&
selectedPublication.resources.some((r) =>
prompt.id.startsWith(
r.sourceUrl ? r.sourceUrl : r.targetUrl,
),
))) && (
<Tooltip
placement="top"
isTriggerClickable
tooltip={t('Delete prompt')}
<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"
>
<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>
)}
<IconTrashX size={24} strokeWidth="1.5" />
</button>
</Tooltip>
</div>
<button
className="button button-secondary"
Expand Down
10 changes: 8 additions & 2 deletions apps/chat/src/components/Promptbar/components/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ export const PromptComponent = ({
PromptsSelectors.selectIsEditModalOpen,
);
const resourceToReview = useAppSelector((state) =>
PublicationSelectors.selectResourceToReviewByReviewUrl(state, prompt.id),
PublicationSelectors.selectResourceToReviewByReviewAndPublicationUrls(
state,
prompt.id,
additionalItemData?.publicationUrl,
),
);

const [isDeleting, setIsDeleting] = useState(false);
Expand Down Expand Up @@ -418,6 +422,9 @@ export const PromptComponent = ({
className={classNames(
'group-hover/prompt-item:bg-accent-tertiary-alpha',
(selectedPromptId === prompt.id || isContextMenu) &&
resourceToReview.publicationUrl ===
selectedPublicationUrl &&
isPartOfSelectedPublication &&
'bg-accent-tertiary-alpha',
)}
/>
Expand Down Expand Up @@ -499,7 +506,6 @@ export const PromptComponent = ({
<PreviewPromptModal
prompt={prompt}
isOpen
isPublicationPreview={!!resourceToReview}
onClose={handleClose}
onDuplicate={
!resourceToReview
Expand Down
9 changes: 8 additions & 1 deletion apps/chat/src/store/conversations/conversations.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,14 @@ const deleteFolderEpic: AppEpic = (action$, state$) =>
actions.push(
of(ConversationsActions.deleteConversations({ conversationIds })),
);
}
} else
actions.push(
of(
ConversationsActions.deleteConversationsComplete({
conversationIds: new Set([]),
}),
),
);

return concat(
of(
Expand Down
4 changes: 4 additions & 0 deletions apps/chat/src/store/prompts/prompts.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ const deleteFolderEpic: AppEpic = (action$, state$) =>

if (promptIds.length) {
actions.push(of(PromptsActions.deletePrompts({ promptIds })));
} else {
actions.push(
of(PromptsActions.deletePromptsComplete({ promptIds: new Set([]) })),
);
}

return concat(
Expand Down
5 changes: 5 additions & 0 deletions apps/chat/src/store/publication/publication.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ const uploadPublicationEpic: AppEpic = (action$) =>
!uploadedUnpublishEntitiesIds.includes(
r.reviewUrl,
),
publicationUrl: payload.url,
},
};
},
Expand Down Expand Up @@ -271,6 +272,7 @@ const uploadPublicationEpic: AppEpic = (action$) =>
!uploadedUnpublishEntitiesIds.includes(
r.reviewUrl,
),
publicationUrl: payload.url,
},
};
}),
Expand Down Expand Up @@ -326,6 +328,7 @@ const uploadPublicationEpic: AppEpic = (action$) =>
name: parsedApiKey.name,
publicationInfo: {
action: r.action,
publicationUrl: payload.url,
},
};
}),
Expand Down Expand Up @@ -402,6 +405,7 @@ const uploadPublicationEpic: AppEpic = (action$) =>
folderId: getFolderIdFromEntityId(r.reviewUrl),
publicationInfo: {
action: r.action,
publicationUrl: payload.url,
},
};
}),
Expand Down Expand Up @@ -446,6 +450,7 @@ const uploadPublicationEpic: AppEpic = (action$) =>
isPublicationFile: true,
publicationInfo: {
action: r.action,
publicationUrl: payload.url,
},
})),
}),
Expand Down
8 changes: 6 additions & 2 deletions apps/chat/src/store/publication/publication.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ export const publicationSlice = createSlice({
payload,
}: PayloadAction<{
id: string;
publicationUrl: string;
}>,
) => {
state.resourcesToReview = state.resourcesToReview.map((r) =>
r.reviewUrl === payload.id ? { ...r, reviewed: true } : r,
state.resourcesToReview = state.resourcesToReview.map((resource) =>
resource.reviewUrl === payload.id &&
resource.publicationUrl === payload.publicationUrl
? { ...resource, reviewed: true }
: resource,
);
},
uploadRules: (state, _action: PayloadAction<{ path: string }>) => {
Expand Down
Loading

0 comments on commit ad52731

Please sign in to comment.