-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
Currently in a workable state! Here's what it looks like, both errors are alerts: @martinpitt If you have any feedback before I polish it and do some URL stuff and write tests, let me know. |
There was a problem hiding this 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.
ch.addEventListener("ready", (_, msg) => this.setState({ pid: msg.pid }), { once: true }); | ||
ch.addEventListener("close", () => this.setState({ pid: null }), { once: true }); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@@ -186,6 +263,30 @@ const _ = cockpit.gettext; | |||
</ToolbarContent> | |||
</Toolbar> | |||
</div> | |||
<div className={"warn"}> |
There was a problem hiding this comment.
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
grid-template-rows: auto 1fr; | ||
grid-template-rows: auto auto 1fr; |
There was a problem hiding this comment.
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?
@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. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
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]>
@martinpitt One more issue: when running with the tests rebased, it fails with Other than that, should be ready for another review, thanks for bearing with me on this one! |
@ashley-cui Most likely you have an ancient bots/ checkout. Keeping that up to date is our team's morning gymnastics 😆 |
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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)
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) }); | ||
} | ||
} |
There was a problem hiding this comment.
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.
dismissError() { | ||
this.setState({ pathError: null }); | ||
cockpit.location.replace(""); | ||
} | ||
|
||
dismissChange() { | ||
this.setState({ changePathBusy: false }); | ||
cockpit.location.replace(""); | ||
} | ||
|
There was a problem hiding this comment.
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.
// Clear old path errors | ||
this.setState({ pathError: null }); |
There was a problem hiding this comment.
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?
cockpit.script(cmmd, [], { err: "message" }) | ||
.then(() => { | ||
this.setState({ changePathBusy: true }); | ||
}) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 == "#/"') |
There was a problem hiding this comment.
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.
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: