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

Duplicate Budget #3847

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
11 changes: 11 additions & 0 deletions packages/desktop-client/src/components/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { KeyboardShortcutModal } from './modals/KeyboardShortcutModal';
import { LoadBackupModal } from './modals/LoadBackupModal';
import { ConfirmChangeDocumentDirModal } from './modals/manager/ConfirmChangeDocumentDir';
import { DeleteFileModal } from './modals/manager/DeleteFileModal';
import { DuplicateFileModal } from './modals/manager/DuplicateFileModal';
import { FilesSettingsModal } from './modals/manager/FilesSettingsModal';
import { ImportActualModal } from './modals/manager/ImportActualModal';
import { ImportModal } from './modals/manager/ImportModal';
Expand Down Expand Up @@ -586,6 +587,16 @@ export function Modals() {
return <BudgetListModal key={name} />;
case 'delete-budget':
return <DeleteFileModal key={name} file={options.file} />;
case 'duplicate-budget':
return (
<DuplicateFileModal
key={name}
file={options.file}
managePage={options?.managePage}
loadBudget={options?.loadBudget}
onComplete={options?.onComplete}
/>
);
case 'import':
return <ImportModal key={name} />;
case 'files-settings':
Expand Down
48 changes: 43 additions & 5 deletions packages/desktop-client/src/components/manager/BudgetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ function getFileDescription(file: File, t: (key: string) => string) {
function FileMenu({
onDelete,
onClose,
onDuplicate,
}: {
onDelete: () => void;
onClose: () => void;
onDuplicate?: () => void;
}) {
function onMenuSelect(type: string) {
onClose();
Expand All @@ -75,18 +77,30 @@ function FileMenu({
case 'delete':
onDelete();
break;
case 'duplicate':
if (onDuplicate) onDuplicate();
break;
default:
}
}

const { t } = useTranslation();

const items = [{ name: 'delete', text: t('Delete') }];
const items = [
...(onDuplicate ? [{ name: 'duplicate', text: t('Duplicate') }] : []),
{ name: 'delete', text: t('Delete') },
];

return <Menu onMenuSelect={onMenuSelect} items={items} />;
}

function FileMenuButton({ onDelete }: { onDelete: () => void }) {
function FileMenuButton({
onDelete,
onDuplicate,
}: {
onDelete: () => void;
onDuplicate?: () => void;
}) {
const triggerRef = useRef(null);
const [menuOpen, setMenuOpen] = useState(false);

Expand All @@ -108,7 +122,11 @@ function FileMenuButton({ onDelete }: { onDelete: () => void }) {
isOpen={menuOpen}
onOpenChange={() => setMenuOpen(false)}
>
<FileMenu onDelete={onDelete} onClose={() => setMenuOpen(false)} />
<FileMenu
onDelete={onDelete}
onClose={() => setMenuOpen(false)}
onDuplicate={onDuplicate}
/>
</Popover>
</View>
);
Expand Down Expand Up @@ -169,11 +187,13 @@ function FileItem({
quickSwitchMode,
onSelect,
onDelete,
onDuplicate,
}: {
file: File;
quickSwitchMode: boolean;
onSelect: (file: File) => void;
onDelete: (file: File) => void;
onDuplicate: (file: File) => void;
}) {
const { t } = useTranslation();

Expand Down Expand Up @@ -239,7 +259,10 @@ function FileItem({
)}

{!quickSwitchMode && (
<FileMenuButton onDelete={() => onDelete(file)} />
<FileMenuButton
onDelete={() => onDelete(file)}
onDuplicate={'id' in file ? () => onDuplicate(file) : undefined}
tlesicka marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
</View>
</View>
Expand All @@ -252,11 +275,13 @@ function BudgetFiles({
quickSwitchMode,
onSelect,
onDelete,
onDuplicate,
}: {
files: File[];
quickSwitchMode: boolean;
onSelect: (file: File) => void;
onDelete: (file: File) => void;
onDuplicate: (file: File) => void;
}) {
function isLocalFile(file: File): file is LocalFile {
return file.state === 'local';
Expand Down Expand Up @@ -292,6 +317,7 @@ function BudgetFiles({
quickSwitchMode={quickSwitchMode}
onSelect={onSelect}
onDelete={onDelete}
onDuplicate={onDuplicate}
/>
))
)}
Expand Down Expand Up @@ -467,7 +493,19 @@ export function BudgetList({ showHeader = true, quickSwitchMode = false }) {
files={files}
quickSwitchMode={quickSwitchMode}
onSelect={onSelect}
onDelete={file => dispatch(pushModal('delete-budget', { file }))}
onDelete={(file: File) =>
dispatch(pushModal('delete-budget', { file }))
}
onDuplicate={(file: File) => {
if (file && 'id' in file) {
dispatch(pushModal('duplicate-budget', { file, managePage: true }));
} else {
console.error(
'Attempted to duplicate a cloud file - only local files are supported. Cloud file:',
file,
);
}
}}
/>
{!quickSwitchMode && (
<View
Expand Down
Loading