mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00

* typedef for ImportBatchBuilder * feat: first pass, fork conversations * feat: fork - getMessagesUpToTargetLevel * fix: additional tests and fix getAllMessagesUpToParent * chore: arrow function return * refactor: fork 3 options * chore: remove unused genbuttons * chore: remove unused hover buttons code * feat: fork first pass * wip: fork remember setting * style: user icon * chore: move clear chats to data tab * WIP: fork UI options * feat: data-provider fork types/services/vars and use generic MutationOptions * refactor: use single param for fork option, use enum, fix mongo errors, use Date.now(), add records flag for testing, use endpoint from original convo and messages, pass originalConvo to finishConversation * feat: add fork mutation hook and consolidate type imports * refactor: use enum * feat: first pass, fork mutation * chore: add enum for target level fork option * chore: add enum for target level fork option * show toast when checking remember selection * feat: splitAtTarget * feat: split at target option * feat: navigate to new fork, show toasts, set result query data * feat: hover info for all fork options * refactor: add Messages settings tab * fix(Fork): remember text info * ci: test for single message and is target edge case * feat: additional tests for getAllMessagesUpToParent * ci: additional tests and cycle detection for getMessagesUpToTargetLevel * feat: circular dependency checks for getAllMessagesUpToParent * fix: getMessagesUpToTargetLevel circular dep. check * ci: more tests for getMessagesForConversation * style: hover text for checkbox fork items * refactor: add statefulness to conversation import
127 lines
3.7 KiB
TypeScript
127 lines
3.7 KiB
TypeScript
import * as Tabs from '@radix-ui/react-tabs';
|
|
import {
|
|
useRevokeUserKeyMutation,
|
|
useRevokeAllUserKeysMutation,
|
|
useClearConversationsMutation,
|
|
} from 'librechat-data-provider/react-query';
|
|
import { SettingsTabValues } from 'librechat-data-provider';
|
|
import React, { useState, useCallback, useRef } from 'react';
|
|
import { useConversation, useConversations, useOnClickOutside } from '~/hooks';
|
|
import ImportConversations from './ImportConversations';
|
|
import { ClearChatsButton } from './ClearChats';
|
|
import DangerButton from '../DangerButton';
|
|
|
|
export const RevokeKeysButton = ({
|
|
showText = true,
|
|
endpoint = '',
|
|
all = false,
|
|
disabled = false,
|
|
}: {
|
|
showText?: boolean;
|
|
endpoint?: string;
|
|
all?: boolean;
|
|
disabled?: boolean;
|
|
}) => {
|
|
const [confirmRevoke, setConfirmRevoke] = useState(false);
|
|
|
|
const revokeKeysMutation = useRevokeAllUserKeysMutation();
|
|
const revokeKeyMutation = useRevokeUserKeyMutation(endpoint);
|
|
|
|
const revokeContentRef = useRef(null);
|
|
useOnClickOutside(revokeContentRef, () => confirmRevoke && setConfirmRevoke(false), []);
|
|
|
|
const revokeAllUserKeys = useCallback(() => {
|
|
if (confirmRevoke) {
|
|
revokeKeysMutation.mutate({});
|
|
setConfirmRevoke(false);
|
|
} else {
|
|
setConfirmRevoke(true);
|
|
}
|
|
}, [confirmRevoke, revokeKeysMutation]);
|
|
|
|
const revokeUserKey = useCallback(() => {
|
|
if (!endpoint) {
|
|
return;
|
|
} else if (confirmRevoke) {
|
|
revokeKeyMutation.mutate({});
|
|
setConfirmRevoke(false);
|
|
} else {
|
|
setConfirmRevoke(true);
|
|
}
|
|
}, [confirmRevoke, revokeKeyMutation, endpoint]);
|
|
|
|
const onClick = all ? revokeAllUserKeys : revokeUserKey;
|
|
|
|
return (
|
|
<DangerButton
|
|
ref={revokeContentRef}
|
|
showText={showText}
|
|
onClick={onClick}
|
|
disabled={disabled}
|
|
confirmClear={confirmRevoke}
|
|
id={'revoke-all-user-keys'}
|
|
actionTextCode={'com_ui_revoke'}
|
|
infoTextCode={'com_ui_revoke_info'}
|
|
dataTestIdInitial={'revoke-all-keys-initial'}
|
|
dataTestIdConfirm={'revoke-all-keys-confirm'}
|
|
mutation={all ? revokeKeysMutation : revokeKeyMutation}
|
|
/>
|
|
);
|
|
};
|
|
|
|
function Data() {
|
|
const dataTabRef = useRef(null);
|
|
const [confirmClearConvos, setConfirmClearConvos] = useState(false);
|
|
useOnClickOutside(dataTabRef, () => confirmClearConvos && setConfirmClearConvos(false), []);
|
|
|
|
const { newConversation } = useConversation();
|
|
const { refreshConversations } = useConversations();
|
|
const clearConvosMutation = useClearConversationsMutation();
|
|
|
|
const clearConvos = () => {
|
|
if (confirmClearConvos) {
|
|
console.log('Clearing conversations...');
|
|
setConfirmClearConvos(false);
|
|
clearConvosMutation.mutate(
|
|
{},
|
|
{
|
|
onSuccess: () => {
|
|
newConversation();
|
|
refreshConversations();
|
|
},
|
|
},
|
|
);
|
|
} else {
|
|
setConfirmClearConvos(true);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Tabs.Content
|
|
value={SettingsTabValues.DATA}
|
|
role="tabpanel"
|
|
className="w-full md:min-h-[300px]"
|
|
ref={dataTabRef}
|
|
>
|
|
<div className="flex flex-col gap-3 text-sm text-gray-600 dark:text-gray-50">
|
|
<div className="border-b pb-3 last-of-type:border-b-0 dark:border-gray-700">
|
|
<ImportConversations />
|
|
</div>
|
|
<div className="border-b pb-3 last-of-type:border-b-0 dark:border-gray-700">
|
|
<RevokeKeysButton all={true} />
|
|
</div>
|
|
|
|
<div className="border-b pb-3 last-of-type:border-b-0 dark:border-gray-700">
|
|
<ClearChatsButton
|
|
confirmClear={confirmClearConvos}
|
|
onClick={clearConvos}
|
|
showText={true}
|
|
mutation={clearConvosMutation}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</Tabs.Content>
|
|
);
|
|
}
|
|
|
|
export default React.memo(Data);
|