components/StaffControls/StaffControls.jsxjavascript
import { StaffMenu, OfflineStatusInfo, hardReloadAction, reloadAction } from "@tracking/staff-menu";
import { flushTracking, getDeviceId, track } from "../../services/tracking/events";

import "@tracking/staff-menu/styles.css";

// placed in the stage (see Stage.jsx): the corner is in the stage's corner, the menu is placed in its
// coordinates and sized with --staff-menu-scale (set by Stage.jsx)
const getStage = () => document.querySelector(".stage-inner");

// both reloads stay on the current page with its kiosk params (stageDevice, hideAppSwitch, … in the
// hash), as the screensaver's session reset does
const ACTIONS = [reloadAction(), hardReloadAction()];

// sent before every reload: a reset of the visit ("staff-reload" / "staff-hard-reload"), flushed so
// the reload doesn't lose it (or send it twice)
const beforeReload = async (reason) => {
  track("reset", { reason });
  await flushTracking();
};

/**
 * Hidden controls for the exhibit staff, on every page (@tracking/staff-menu): holding the
 * bottom-left corner opens the staff menu with reload and hard reload, the offline status and the
 * device id. The screensaver deliberately isn't in the menu, the navigation has its own buttons.
 *
 * Mounted in HashRouter.jsx outside the ErrorBoundary, so a crashing page can still be reloaded.
 */
const StaffControls = () => (
  <StaffMenu
    container={getStage}
    actions={ACTIONS}
    info={[
      <OfflineStatusInfo key="offline" />,
      { text: `Device ID: ${getDeviceId() ?? "– (tracking off)"}` },
    ]}
    beforeReload={beforeReload}
  />
);

export default StaffControls;