Skip to content

Commit

Permalink
shell: Use Status type from pkg/lib/notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer authored and martinpitt committed Dec 18, 2024
1 parent dff61a6 commit 11a740c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
9 changes: 5 additions & 4 deletions pkg/shell/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import { SearchInput } from "@patternfly/react-core/dist/esm/components/SearchIn
import { Tooltip, TooltipPosition } from "@patternfly/react-core/dist/esm/components/Tooltip/index.js";
import { ContainerNodeIcon, ExclamationCircleIcon, ExclamationTriangleIcon, InfoCircleIcon } from '@patternfly/react-icons';

import { Status } from "notifications";
import { Location, encode_location, ManifestItem } from "./util.jsx";
import { ShellState, PageStatus } from "./state";
import { ShellState } from "./state";
import { ManifestKeyword } from "./manifests";

const _ = cockpit.gettext;
Expand Down Expand Up @@ -227,10 +228,10 @@ export class CockpitNav extends React.Component {
}
}

function PageStatus({ status, name } : { status: PageStatus, name: string }) {
function PageStatus({ status, name } : { status: Status, name: string }) {
// Generate name for the status
const desc_parts = name.toLowerCase().split(" ");
desc_parts.push(status.type);
desc_parts.push(status.type || "");
const desc = desc_parts.join("-");

return (
Expand Down Expand Up @@ -265,7 +266,7 @@ export function CockpitNavItem(props : {
header?: string;
className?: string;
active: boolean;
status: PageStatus | null;
status: Status | null;
keyword: string;
term: string;
href: string;
Expand Down
15 changes: 4 additions & 11 deletions pkg/shell/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import cockpit from "cockpit";

import { EventEmitter } from "cockpit/event";
import { Status } from "notifications";

import { Router } from "./router.jsx";
import {
Expand Down Expand Up @@ -55,14 +56,6 @@ export interface ShellStateEvents {
connect: () => void;
}

// NOTE - this is defined in pkg/lib/notifications.js and should be
// imported from there once that file has been typed.
//
export interface PageStatus {
type: string;
title: string;
}

export class ShellState extends EventEmitter<ShellStateEvents> {
constructor() {
super();
Expand Down Expand Up @@ -316,13 +309,13 @@ export class ShellState extends EventEmitter<ShellStateEvents> {
* individual pages have access to all collected statuses.
*/

page_status: { [host: string]: { [page: string]: PageStatus } } = { };
page_status: { [host: string]: { [page: string]: Status } } = { };

#init_page_status() {
sessionStorage.removeItem("cockpit:page_status");
}

#notify_page_status(host: string, page: string, status: PageStatus) {
#notify_page_status(host: string, page: string, status: Status) {
if (!this.page_status[host])
this.page_status[host] = { };
this.page_status[host][page] = status;
Expand Down Expand Up @@ -400,7 +393,7 @@ export class ShellState extends EventEmitter<ShellStateEvents> {
* "well-known name" of a page, such as "system",
* "network/firewall", or "updates".
*/
handle_notifications: (host: string, page: string, data: { page_status?: PageStatus }) => {
handle_notifications: (host: string, page: string, data: { page_status?: Status }) => {
if (data.page_status !== undefined)
this.#notify_page_status(host, page, data.page_status);
},
Expand Down

0 comments on commit 11a740c

Please sign in to comment.