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

feat: implement file view for publishing request wizard (Issue #331) #514

Merged
merged 75 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
a525ea6
feat: implement change path dialog (Issue #330)
Alexander-Kezik Jan 9, 2024
d065160
remove unnecessary code from renameTemporaryFolder reducer
Alexander-Kezik Jan 9, 2024
d8055f7
remove unnecessary code from renameTemporaryFolder reducer
Alexander-Kezik Jan 9, 2024
4647a31
remove unnecessary imports
Alexander-Kezik Jan 9, 2024
c10a53a
fix the ability to update publishing and select the same folder as th…
Alexander-Kezik Jan 10, 2024
f28fbd3
refactoring
IlyaBondar Jan 10, 2024
81c471d
Merge branch 'feat/330-publish-need-to-implement-change-path-dialog' …
IlyaBondar Jan 10, 2024
1be6eff
vertical scroll
IlyaBondar Jan 10, 2024
6157ae6
Update PublishModal.tsx
IlyaBondar Jan 10, 2024
631b6ab
modal layout
IlyaBondar Jan 10, 2024
ebb5874
cursor pointer for some parts
IlyaBondar Jan 10, 2024
126bb72
file view
IlyaBondar Jan 10, 2024
d82743f
layout
IlyaBondar Jan 10, 2024
207a477
correct entity term
IlyaBondar Jan 10, 2024
4d3bf60
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 11, 2024
6c377a5
fix infinity nesting/folders search/rename mode after folder creation…
Alexander-Kezik Jan 11, 2024
959a19f
remove unnecessary dependency
Alexander-Kezik Jan 11, 2024
a005c20
Merge branch 'feat/330-publish-need-to-implement-change-path-dialog' …
IlyaBondar Jan 11, 2024
0a94f27
fix layout and scroll
IlyaBondar Jan 11, 2024
74fda90
fix layout for mobile
IlyaBondar Jan 11, 2024
021c96a
fix layout
IlyaBondar Jan 11, 2024
a7c4805
publishing attachments
IlyaBondar Jan 11, 2024
0d24e76
resolve comments
Alexander-Kezik Jan 12, 2024
ffb7423
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 12, 2024
9d425f4
Merge branch 'feat/330-publish-need-to-implement-change-path-dialog' …
IlyaBondar Jan 12, 2024
9b65eff
publish attachments
IlyaBondar Jan 12, 2024
62fee42
feat: implement change path dialog (Issue #330)
Alexander-Kezik Jan 9, 2024
bdf1b5f
remove unnecessary code from renameTemporaryFolder reducer
Alexander-Kezik Jan 9, 2024
fcb9088
remove unnecessary code from renameTemporaryFolder reducer
Alexander-Kezik Jan 9, 2024
6c6c5a9
remove unnecessary imports
Alexander-Kezik Jan 9, 2024
65a0211
fix the ability to update publishing and select the same folder as th…
Alexander-Kezik Jan 10, 2024
10844db
fix infinity nesting/folders search/rename mode after folder creation…
Alexander-Kezik Jan 11, 2024
4bef0b1
remove unnecessary dependency
Alexander-Kezik Jan 11, 2024
895811e
resolve comments
Alexander-Kezik Jan 12, 2024
3450238
Merge remote-tracking branch 'origin/feat/330-publish-need-to-impleme…
IlyaBondar Jan 12, 2024
3660c6c
resolve comments
Alexander-Kezik Jan 12, 2024
5994a75
resolve lint issues
Alexander-Kezik Jan 12, 2024
8a3c37f
context menu, download files and refactoring
IlyaBondar Jan 12, 2024
bd2f2b5
Merge remote-tracking branch 'origin/feat/330-publish-need-to-impleme…
IlyaBondar Jan 12, 2024
8838ece
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 12, 2024
3fafc30
Merge branch 'development' into feat/330-publish-need-to-implement-ch…
IlyaBondar Jan 12, 2024
ed5fded
Merge branch 'feat/330-publish-need-to-implement-change-path-dialog' …
IlyaBondar Jan 12, 2024
80b1b65
add reusable SelectFolder component
Alexander-Kezik Jan 15, 2024
b56ed7c
Merge remote-tracking branch 'origin/feat/330-publish-need-to-impleme…
IlyaBondar Jan 15, 2024
7a07820
PUBLISHING_FOLDER_NAME
IlyaBondar Jan 15, 2024
146a9df
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 15, 2024
27672c3
fix folders highlight
Alexander-Kezik Jan 15, 2024
f8863e7
remove unnecesery imports
Alexander-Kezik Jan 15, 2024
9be1d87
fix folders highlight/unique all levels folders when create/folders s…
Alexander-Kezik Jan 16, 2024
50af0f5
Merge branch 'development' into feat/330-publish-need-to-implement-ch…
Alexander-Kezik Jan 16, 2024
b831d00
file rename
IlyaBondar Jan 16, 2024
a978edc
Merge remote-tracking branch 'origin/feat/330-publish-need-to-impleme…
IlyaBondar Jan 16, 2024
47dcc8b
select on begin of renaming
IlyaBondar Jan 16, 2024
f23a146
reset when switch renaming
IlyaBondar Jan 16, 2024
1bfb780
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 17, 2024
39ab0b5
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 17, 2024
4d86a4d
hide file extension on renaming
IlyaBondar Jan 17, 2024
c6ebfc5
context menu and rename
IlyaBondar Jan 17, 2024
1940f38
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 17, 2024
29c27d0
fix lint issues
IlyaBondar Jan 17, 2024
117df7d
correct tooltip position
IlyaBondar Jan 17, 2024
737bdd4
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 17, 2024
cc86596
fix mapping
IlyaBondar Jan 17, 2024
f0af751
file name validation
IlyaBondar Jan 17, 2024
2d2ce95
pass file mapping
IlyaBondar Jan 17, 2024
59f06b0
applying of file name renaming
IlyaBondar Jan 18, 2024
dc644c6
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 18, 2024
4d8f1a3
remove lodash-es
IlyaBondar Jan 18, 2024
0e87118
code review comment resolving
IlyaBondar Jan 18, 2024
3ab868c
refactoring
IlyaBondar Jan 18, 2024
aa18868
remove "max-h-full"
IlyaBondar Jan 18, 2024
6b89760
Merge branch 'development' into feat/331_publish_files
IlyaBondar Jan 18, 2024
b0c50fd
show close icon, hide cancel button
IlyaBondar Jan 18, 2024
5bebeba
redesign based on review
IlyaBondar Jan 18, 2024
33da21b
fix text start
IlyaBondar Jan 18, 2024
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
226 changes: 226 additions & 0 deletions src/components/Chat/PublishAttachment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import { useDismiss, useFloating, useInteractions } from '@floating-ui/react';
import {
IconCheck,
IconDots,
IconDownload,
IconFile,
IconPencilMinus,
IconX,
} from '@tabler/icons-react';
import {
KeyboardEvent,
MouseEvent,
MouseEventHandler,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';

import { useTranslation } from 'next-i18next';

import classNames from 'classnames';

import {
constructPath,
getFileNameExtension,
getFileNameWithoutExtension,
} from '@/src/utils/app/file';

import { DialFile } from '@/src/types/files';
import { DisplayMenuItemProps } from '@/src/types/menu';
import { Translation } from '@/src/types/translation';

import { stopBubbling } from '@/src/constants/chat';
import { PUBLISHING_FOLDER_NAME } from '@/src/constants/folders';

import SidebarActionButton from '../Buttons/SidebarActionButton';
import ContextMenu from '../Common/ContextMenu';
import Tooltip from '../Common/Tooltip';
import DownloadRenderer from '../Files/Download';

interface Props {
file: DialFile;
isRenaming: boolean;
onRename: (newName: string, cancel?: boolean) => void;
onStartRename: (file: DialFile) => void;
}

export const PublishAttachment = ({
file,
onRename,
onStartRename,
isRenaming,
}: Props) => {
const { t } = useTranslation(Translation.Chat);
const inputRef = useRef<HTMLInputElement>(null);
const [nameWithoutExtension, setName] = useState(
getFileNameWithoutExtension(file.name),
);
const fileExtension = getFileNameExtension(file.name);
const fileName = `${nameWithoutExtension}${fileExtension}`;
const [isContextMenu, setIsContextMenu] = useState(false);

const { refs, context } = useFloating({
open: isContextMenu,
onOpenChange: setIsContextMenu,
});
const dismiss = useDismiss(context);
const { getFloatingProps } = useInteractions([dismiss]);

useEffect(() => {
if (isRenaming) {
setTimeout(() => {
inputRef.current?.focus();
inputRef.current?.select();
}); // set auto-focus
}
}, [isRenaming]);

useEffect(() => {
if (!isRenaming) {
setName(getFileNameWithoutExtension(file.name));
}
}, [file.name, isRenaming]);

const handleCancel: MouseEventHandler<HTMLButtonElement> = useCallback(
(e) => {
e.stopPropagation();
onRename(file.name, true);
setName(getFileNameWithoutExtension(file.name));
},
[file, onRename],
);

const handleEnterDown = useCallback(
(e: KeyboardEvent<HTMLDivElement>) => {
e.stopPropagation();
if (e.key === 'Enter') {
e.preventDefault();
onRename(fileName);
}
},
[fileName, onRename],
);

const handleConfirm: MouseEventHandler<HTMLButtonElement> = useCallback(
(e) => {
e.stopPropagation();
onRename(fileName);
},
[fileName, onRename],
);

const menuItems: DisplayMenuItemProps[] = useMemo(
() => [
{
name: t('Rename'),
dataQa: 'rename',
Icon: IconPencilMinus,
onClick: () => onStartRename(file),
},
{
name: t('Download'),
dataQa: 'download',
Icon: IconDownload,
display: file.status !== 'UPLOADING' && file.status !== 'FAILED',
onClick: (e: MouseEvent) => stopBubbling(e),
className: 'flex gap-3',
customTriggerData: file,
CustomTriggerRenderer: DownloadRenderer,
},
],
[file, onStartRename, t],
);

if (!file) return null;

const fullPath = constructPath(t(PUBLISHING_FOLDER_NAME), file.relativePath);

const handleContextMenuOpen = (e: MouseEvent) => {
if (isRenaming) {
return;
}
e.preventDefault();
e.stopPropagation();
setIsContextMenu(true);
};

return (
<div
className={classNames(
'group relative flex h-[56px] w-full max-w-full items-center rounded px-3 py-2 hover:bg-accent-primary-alpha',
!isRenaming ? 'hover:pr-10' : 'bg-accent-primary-alpha',
)}
onContextMenu={handleContextMenuOpen}
>
<IconFile className="mr-2 shrink-0 text-secondary" size={18} />
<div
className={classNames(
'flex min-w-0 shrink grow flex-col',
!isRenaming && 'items-start',
)}
>
{!isRenaming ? (
<>
<Tooltip
isTriggerClickable
tooltip={fileName}
triggerClassName="block truncate max-w-full"
hideTooltip={isContextMenu}
>
{fileName}
</Tooltip>
<Tooltip
tooltip={fullPath}
triggerClassName="block max-w-full truncate text-secondary"
hideTooltip={isContextMenu}
>
{fullPath}
</Tooltip>
</>
) : (
<div className="relative flex grow items-center">
<input
className="mr-14 grow text-ellipsis rounded bg-transparent p-2 pl-0 placeholder:text-secondary focus:outline-none"
type="text"
value={nameWithoutExtension}
onChange={(e) => setName(e.target.value)}
onKeyDown={handleEnterDown}
autoFocus
ref={inputRef}
/>
<div className="absolute right-0 z-10 flex">
<SidebarActionButton handleClick={handleConfirm}>
<IconCheck size={18} className="hover:text-accent-primary" />
</SidebarActionButton>
<SidebarActionButton handleClick={handleCancel}>
<IconX
size={18}
strokeWidth="2"
className="hover:text-accent-primary"
/>
</SidebarActionButton>
</div>
</div>
)}
</div>
{!isRenaming && (
<div
ref={refs.setFloating}
{...getFloatingProps()}
className="invisible absolute right-4 h-[18px] group-hover:visible"
>
<ContextMenu
menuItems={menuItems}
TriggerIcon={IconDots}
triggerIconHighlight
triggerIconSize={18}
isOpen={isContextMenu}
/>
</div>
)}
</div>
);
};
Loading
Loading