/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import React, { useState } from "react"; import { observer } from "mobx-react"; import { Select } from "../select"; import hotbarManagerInjectable from "../../../common/hotbar-store.injectable"; import { Input, InputValidator } from "../input"; import type { Hotbar } from "../../../common/hotbar-types"; import { withInjectables } from "@ogre-tools/injectable-react"; import commandOverlayInjectable from "../command-palette/command-overlay.injectable"; import uniqueHotbarNameInjectable from "../input/validators/unique-hotbar-name.injectable"; interface Dependencies { closeCommandOverlay: () => void; hotbarManager: { hotbars: Hotbar[]; getById: (id: string) => Hotbar | undefined; setHotbarName: (id: string, name: string) => void; getDisplayLabel: (hotbar: Hotbar) => string; }; uniqueHotbarName: InputValidator; } const NonInjectedHotbarRenameCommand = observer(({ closeCommandOverlay, hotbarManager, uniqueHotbarName }: Dependencies) => { const [hotbarId, setHotbarId] = useState(""); const [hotbarName, setHotbarName] = useState(""); const options = hotbarManager.hotbars.map(hotbar => ({ value: hotbar.id, label: hotbarManager.getDisplayLabel(hotbar), })); const onSelect = (id: string) => { setHotbarId(id); setHotbarName(hotbarManager.getById(id).name); }; const onSubmit = (name: string) => { if (!name.trim()) { return; } hotbarManager.setHotbarName(hotbarId, name); closeCommandOverlay(); }; if (hotbarId) { return ( <> Please provide a new hotbar name (Press "Enter" to confirm or "Escape" to cancel) ); } return (