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

systemd: Open path in terminal #21162

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ashley-cui
Copy link
Contributor

@ashley-cui ashley-cui commented Oct 25, 2024

Allow opening of a path from a URL option, path=path. If the terminal is busy, then warn the user and prompt them to continue.

WIP: changing to a path that does not exist should result in an alert, but there's some css magic that's preventing the alert from showing, and I can't figure out what it is. Also needs tests, but thought I would draft it for feedback so far 😌

Prerequisites:

pkg/systemd/terminal.jsx Fixed Show fixed Hide fixed
@martinpitt martinpitt added the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Oct 25, 2024
pkg/systemd/overview.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Show resolved Hide resolved
pkg/systemd/terminal.jsx Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Fixed Show fixed Hide fixed
pkg/systemd/terminal.jsx Fixed Show fixed Hide fixed
pkg/systemd/terminal.jsx Fixed Show fixed Hide fixed
@ashley-cui
Copy link
Contributor Author

ashley-cui commented Oct 30, 2024

Currently in a workable state! Here's what it looks like, both errors are alerts:

Screenshot from 2024-10-30 01-28-27
Screenshot from 2024-10-30 01-26-49

@martinpitt If you have any feedback before I polish it and do some URL stuff and write tests, let me know.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Very cool @ashley-cui ! I did a first review round. I can try to help you a bit with the styling, but that's my weak point as well. But until @garrett has time to look at this, we can sort out the code, functionality, and tests.

pkg/systemd/overview.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
Comment on lines +46 to +44
ch.addEventListener("ready", (_, msg) => this.setState({ pid: msg.pid }), { once: true });
ch.addEventListener("close", () => this.setState({ pid: null }), { once: true });
Copy link
Member

Choose a reason for hiding this comment

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

once doesn't actually work, please drop. Marius also said that the handlers clean up themselves once the object (channel in this case) gets destroyed, so should be fine.

Copy link
Member

Choose a reason for hiding this comment

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

You resolved this thread, but it's still in the latest push. Reopening.

pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
@@ -186,6 +263,30 @@ const _ = cockpit.gettext;
</ToolbarContent>
</Toolbar>
</div>
<div className={"warn"}>
Copy link
Member

Choose a reason for hiding this comment

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

Does this class do anything? I don't see it referenced anywhere. But indeed the alert will need some styling, it should at least have some margin to the terminal and the toolbar. If you plan to keep it, please make it a bit more unique, like ct-terminal-dir-alert

pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
pkg/systemd/terminal.jsx Outdated Show resolved Hide resolved
grid-template-rows: auto 1fr;
grid-template-rows: auto auto 1fr;
Copy link
Member

Choose a reason for hiding this comment

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

I don't know enough about grids to see what that does. I figure it's about accomodating the alert, but what if the alert isn't rendered?

@ashley-cui
Copy link
Contributor Author

@martinpitt Here's what's broken, and I can't figure out why. Currently all calls to createChannel() are commented out other than the initial call. Pressing the temporary testing button causes the terminal to disconnect, and doing it several times causes cockpit to disconnect for me.

@martinpitt

This comment was marked as resolved.

@martinpitt

This comment was marked as outdated.

@garrett
Copy link
Member

garrett commented Nov 6, 2024

I don't really have time right now to properly test this, but I was looking through my mentions, and it looks pretty good from the screenshots, provided the alerts aren't covering up the terminal content.

The continue action should probably look like a secondary small button.

Allow opening of a path from a URL option, path=path.
If the terminal is busy, then warn the user and prompt them to
continue.

Signed-off-by: Ashley Cui <[email protected]>
@ashley-cui
Copy link
Contributor Author

@martinpitt One more issue: when running with the tests rebased, it fails with error: "Machine" has no attribute "ws_container", it was introduced here, but I don't know how to get it working.

Other than that, should be ready for another review, thanks for bearing with me on this one!

@ashley-cui ashley-cui marked this pull request as ready for review November 7, 2024 05:13
@martinpitt
Copy link
Member

@ashley-cui Most likely you have an ancient bots/ checkout. Keeping that up to date is our team's morning gymnastics 😆 git -C bots pull. Triggering fedora-40/other here to get an official test run.

@martinpitt martinpitt self-requested a review November 7, 2024 05:26
@martinpitt martinpitt changed the title [WIP] terminal: Open path in terminal systemd: Open path in terminal Nov 7, 2024
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks @ashley-cui! Nice work with fixing the issues and adding tests, they look fairly happy. I have a lot of really small stuff, should be quite fast to fix. But let me know if anything is unclear, happy to help!

There's also some outstanding threads from my previous review.

@@ -7,6 +7,9 @@ import { createRoot } from "react-dom/client";
import { FormSelect, FormSelectOption } from "@patternfly/react-core/dist/esm/components/FormSelect/index.js";
Copy link
Member

Choose a reason for hiding this comment

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

Please clean up the commit message:

  • Should be prefixed by the page ("systemd:" in this case).
  • Please drop S-o-b, we don't use that in cockpit (and frankly, I don't see the point -- From: is just fine)

Comment on lines +100 to +112
let dir;
if (cockpit.location.options.path) {
try {
const info = await fsinfo(String(cockpit.location.options.path), ['type']);
if (info.type === "dir") {
dir = cockpit.location.options.path;
} else {
this.setState({ pathError: cockpit.format(_("$0 is not a directory"), cockpit.location.options.path) });
}
} catch (err) {
this.setState({ pathError: cockpit.format(_("$0 does not exist"), cockpit.location.options.path) });
}
}
Copy link
Member

Choose a reason for hiding this comment

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

DRY ("don't repeat yourself") -- please just call this.onNavigate() here.

Comment on lines +137 to +146
dismissError() {
this.setState({ pathError: null });
cockpit.location.replace("");
}

dismissChange() {
this.setState({ changePathBusy: false });
cockpit.location.replace("");
}

Copy link
Member

Choose a reason for hiding this comment

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

This could just be a single dismiss() which resets both states. These errors can't happen at the same time.

However, this is a matter of preference, and I leave this up to you -- feel free to just resolve this thread.

Comment on lines +148 to +149
// Clear old path errors
this.setState({ pathError: null });
Copy link
Member

Choose a reason for hiding this comment

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

If this can happen, then changePathBusy could also still be active -- this should probably reset it, too?

Comment on lines +170 to +173
cockpit.script(cmmd, [], { err: "message" })
.then(() => {
this.setState({ changePathBusy: true });
})
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid the unnecessary {} wrappers for arrows, just say () => this.setState(...).

But moreover, this is an async function and you are using await above, so please let's be consistent and also try{ await cockpit.script() } catch {...} here.

Also, personal favour: Please spell "cmmd" as "command", or avoid the const altogether and just inline it into the cockpit.script call.

b.wait_not_present(".pf-v5-c-alert.pf-m-danger")

# Error on change to non-dir
m.execute("touch /tmp/thisisafile")
Copy link
Member

Choose a reason for hiding this comment

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

Let's please clean up after ourselves, and use self.write_file("/tmp/thisisafile", "") instead (that has an addCleanup to restore or remove it after the test). Or just use an existing file such as /etc/os-release.

@@ -186,6 +268,22 @@ const _ = cockpit.gettext;
</ToolbarContent>
</Toolbar>
</div>
<div className="ct-terminal-dir-alert">
{this.state.pathError && <Alert isInline variant='danger'
Copy link
Member

Choose a reason for hiding this comment

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

This isn't really a "danger", there's no potential data loss here. Please change to "warning".

title={cockpit.format(_("Error opening directory: $0"), this.state.pathError)}
actionClose={<AlertActionCloseButton onClose={this.dismissError} />} />}
{this.state.changePathBusy && <Alert title={_("There is still a process running in this terminal. Changing the directory will kill it.")}
variant="warning"
Copy link
Member

Choose a reason for hiding this comment

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

This on the other hand should be "danger", as killing a running process may lead to some data loss.

b.wait_js_cond('window.location.hash == "#/"')

# Prompt for change if terminal busy
b.input_text("vi busybusybusy\n")
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if all our images have vi (I only triggered on fedora-40 so far). Let's just use "sleep 100"?

# Cancel change
b.click("button:contains('Cancel')")
b.wait_not_present(".pf-v5-c-alert.pf-m-danger")
b.wait_js_cond('window.location.hash == "#/"')
Copy link
Member

Choose a reason for hiding this comment

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

Please check here that the "busy" process is still running, and the terminal still shows it. This changes the location hash, so it could very well accidentally destroy the process anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-test For doc/workflow changes, or experiments which don't need a full CI run,
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants