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

Refactor Navigator Card Body for global event listeners #237

Merged
merged 11 commits into from
Feb 5, 2024

Conversation

jelly
Copy link
Member

@jelly jelly commented Feb 1, 2024

This PR aims to move the ContextMenu into the NavigatorCardBody as it has no place in app.jsx plus remove the context menu related event listeners to the NavigatorCardBody and stop having a per Item event listener for the Context Menu.

This is now so far all preparation work, I have a patch to make it use on onContextMenu but that requires more work to handle the folder switching breaks contextMenu bug.

@jelly jelly added the no-test label Feb 1, 2024
jelly added 2 commits February 1, 2024 15:37
The ContextMenu has nothing to do with the main app, it appears in the
`CardBody` or better said DirectoryView. This allows us to later to
consolidate the event listeners and if the ContextMenu should be shown
to the NavigatorCardBody instead of the app itself.

Note: later rename CardBody to DirectoryView.
The context menu handling is Card body specific and does not have to
live in the app code.
@jelly jelly force-pushed the redo-event-listeners branch from 9a35053 to 7bcb584 Compare February 1, 2024 14:38
@jelly jelly changed the title Redo event listeners Refactor event listener handling in the Folder view Feb 1, 2024
jelly added 9 commits February 1, 2024 15:56
Selected item was being passed along to the create directory dialog,
which seems to indicate we wanted to support creating a directory in a
selected directory. As the UI does not support this nor this is wanted
drop it. (Note: icons_cnt also doesn't exists at all)
selectedContext is the same as selected so we can fallback to selected.
The sidebar allowed to delete the currently shown directory which is a
bit evil and an easy mistake to make. Don't allow users to make such
trivial mistakes.
Simplify deletion by only taking the selected files and the current
directory the files are in. Not only does it make the code more clear
but it also opens up a way to drop selectedContext.
It's the same as selectedContext but an Array.
When no folder is selected null is passed which crashes the dialog
instead pass the currentDirectory object, which apparently does not know
about the filetype so the dialog shows "unknown type". This is yet
another bug to resolve later.
Just as renameItem, selectedContext is the same as selected except
selected is an array.
Same as rename/edit permissions it's the same thing as selectedContext.
This piece of state is now completely replaced by selected and the
ContextMenu itself handles when it is visible or not.
@jelly jelly removed the no-test label Feb 1, 2024
@jelly jelly marked this pull request as ready for review February 1, 2024 17:23
Comment on lines +91 to +94
const _copyItem = () => {
copyItem(setClipboard, selected.length > 1
? selected.map(s => currentDir + s.name)
: [currentDir + selected[0].name]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 4 added lines are not executed by any test. Details

? selected.map(s => currentDir + s.name)
: [currentDir + selected[0].name]);
};
const _pasteItem = (targetPath, asSymlink) => pasteItem(clipboard, targetPath.join("/") + "/", asSymlink, addAlert);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

};

if (selected.length === 0)
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

// items and not the current path. Refactor this later.
if (selected.length === 1 && selected[0].name === path[path.length - 1]) {
menuItems.push(
{ title: _("Paste"), onClick: () => _pasteItem(path, false), isDisabled: clipboard === undefined },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

{ title: _("Paste"), onClick: () => _pasteItem(path, false), isDisabled: clipboard === undefined },
{
title: _("Paste as symlink"),
onClick: () => _pasteItem(path, true),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

? [
{
title: _("Paste into directory"),
onClick: () => _pasteItem([...path, selected[0].name], false),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

{ type: "divider" },
{ title: cockpit.format(_("Delete")), onClick: _deleteItem, className: "pf-m-danger" },
);
} else if (selected.length > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

@@ -222,6 +327,11 @@
}
};

const handleContextMenu = () => {
const sel = path ? path[path.length - 1] : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

selected: selected.length === 0
? null
: selected[0],
selected: selected[0] || currentDirectory,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

@jelly jelly changed the title Refactor event listener handling in the Folder view Refactor Navigator Card Body for global event listeners Feb 1, 2024
Copy link
Member

@allisonkarlitskaya allisonkarlitskaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a real nice cleanup, thanks.

@allisonkarlitskaya allisonkarlitskaya merged commit 2b52013 into cockpit-project:main Feb 5, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants