Skip to content

Commit

Permalink
WIP - active pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Sep 20, 2024
1 parent ae6af7c commit 39ba1c5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
27 changes: 14 additions & 13 deletions pkg/shell/active-pages-modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ import { useInit } from "hooks";

const _ = cockpit.gettext;

export const ActivePagesDialog = ({ dialogResult, frames }) => {
export const ActivePagesDialog = ({ dialogResult, state }) => {
function get_pages() {
const result = [];
for (const address in frames.iframes) {
for (const component in frames.iframes[address]) {
const iframe = frames.iframes[address][component];
for (const f of state.frames) {
if (f) {
const active = state.last_fullpath_for_host(f.host) == f.fullpath;
result.push({
frame: iframe,
component,
address,
name: iframe.getAttribute("name"),
active: iframe.getAttribute("data-active") === 'true',
selected: iframe.getAttribute("data-active") === 'true',
displayName: address === "localhost" ? "/" + component : address + ":/" + component
frame: f,
component: f.fullpath,
address: f.host,
name: f.name,
active,
selected: active,
displayName: f.host === "localhost" ? "/" + f.fullpath : f.host + ":/" + f.fullpath,
});
}
}
Expand All @@ -61,8 +61,9 @@ export const ActivePagesDialog = ({ dialogResult, frames }) => {

function onRemove() {
pages.forEach(element => {
if (element.selected)
frames.remove(element.host, element.component);
if (element.selected) {
state.remove_frame(element.address, element.component);
}
});
dialogResult.resolve();
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/shell/base_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ function Index() {
return null;
}

const last_component_for_host = { };
self.last_component_for_host = { };

/* Jumps to a given navigate state */
self.jump = function (state, replace) {
Expand All @@ -718,13 +718,13 @@ function Index() {

// When switching hosts, check if we left from some page
if (!state.component && state.host !== current.host) {
state.component = last_component_for_host[state.host];
state.component = self.last_component_for_host[state.host];
}

if (!("component" in state))
state.component = current.component || "";

last_component_for_host[state.host] = state.component;
self.last_component_for_host[state.host] = state.component;

const history = window.history;
const frame_change = (state.host !== current.host ||
Expand Down
13 changes: 12 additions & 1 deletion pkg/shell/shell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function ShellState(machines, loader) {

function update() {
self.frames = index.frames.frame_array;
self.has_oops = index.has_oops;
self.dispatchEvent("update");
}

Expand Down Expand Up @@ -327,6 +328,16 @@ function ShellState(machines, loader) {
index.start();
});

self.last_fullpath_for_host = (host) => {
return index.last_component_for_host[host];
}

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (95% of all statements in
the enclosing function
have an explicit semicolon).

self.remove_frame = (host, component) => {
console.log("EXPLICIT REMOVE", host, component);
index.frames.remove(host, component);
update();
};

return self;
}

Expand Down Expand Up @@ -610,7 +621,7 @@ const Shell = ({ state, machines, loader }) => {
</div>

<div id="topnav" className="header">
<TopNav index={state.index}
<TopNav state={state}
loading={current_frame && !current_frame.ready}
machine={machine}
fullpath={fullpath}
Expand Down
4 changes: 2 additions & 2 deletions pkg/shell/topnav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class TopNav extends React.Component {
if (this.state.showActivePages)
main_menu.push(
<DropdownItem key="frames" id="active-pages" component="button"
onClick={() => Dialogs.run(ActivePagesDialog, { frames: this.props.index.frames })}>
onClick={() => Dialogs.run(ActivePagesDialog, { state: this.props.state })}>
{_("Active pages")}
</DropdownItem>);

Expand Down Expand Up @@ -217,7 +217,7 @@ export class TopNav extends React.Component {
<SuperuserIndicator proxy={this.superuser} host={this.props.machine.connection_string} />
</ToolbarItem>
}
{ this.props.index.has_oops &&
{ this.props.state.has_oops &&
<ToolbarItem>
<Button id="navbar-oops" variant="link" size="lg" isDanger
onClick={() => Dialogs.run(OopsModal, {})}>{_("Ooops!")}</Button>
Expand Down

0 comments on commit 39ba1c5

Please sign in to comment.