mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Relax validator for installing charts Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak spacing between words in confirmation dialog Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add mocks for monaco editor and virtualized auto sizer to allow components to be rendered in unit tests Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Improve typing for a function Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove usage of shared global state from a component Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Provide a way to unit test usages of storages Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add way to get current value from select in behavioural unit tests Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Rework installation of helm charts to get rid of the majority of bugs Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Update snapshots Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove technical test for being covered in behaviours Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Split behaviour to smaller pieces Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add tests accidentally removed back Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Mark functions causing side effects Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove behaviour covered by other behaviours Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak naming Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove unused dependency Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import styles from "./editor-panel.module.scss";
|
|
import throttle from "lodash/throttle";
|
|
import React, { createRef, useEffect } from "react";
|
|
import { reaction } from "mobx";
|
|
import { observer } from "mobx-react";
|
|
import type { DockStore, TabId } from "./dock/store";
|
|
import { cssNames, disposer } from "../../utils";
|
|
import { MonacoEditor } from "../monaco-editor";
|
|
import type { MonacoEditorProps, MonacoEditorRef } from "../monaco-editor";
|
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
|
import dockStoreInjectable from "./dock/store.injectable";
|
|
|
|
export interface EditorPanelProps {
|
|
tabId: TabId;
|
|
value: string;
|
|
className?: string;
|
|
autoFocus?: boolean; // default: true
|
|
onChange: MonacoEditorProps["onChange"];
|
|
onError?: MonacoEditorProps["onError"];
|
|
hidden?: boolean;
|
|
}
|
|
|
|
interface Dependencies {
|
|
dockStore: DockStore;
|
|
}
|
|
|
|
const NonInjectedEditorPanel = observer(({
|
|
dockStore,
|
|
onChange,
|
|
tabId,
|
|
value,
|
|
autoFocus = true,
|
|
className,
|
|
onError,
|
|
hidden,
|
|
}: Dependencies & EditorPanelProps) => {
|
|
const editor = createRef<MonacoEditorRef>();
|
|
|
|
useEffect(() => disposer(
|
|
reaction(
|
|
() => dockStore.isOpen,
|
|
isOpen => isOpen && editor.current?.focus(),
|
|
{
|
|
fireImmediately: true,
|
|
},
|
|
),
|
|
dockStore.onResize(throttle(() => editor.current?.focus(), 250)),
|
|
));
|
|
|
|
if (!tabId) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<MonacoEditor
|
|
autoFocus={autoFocus}
|
|
id={tabId}
|
|
value={value}
|
|
className={cssNames(styles.EditorPanel, className, { hidden })}
|
|
onChange={onChange}
|
|
onError={onError}
|
|
ref={editor}
|
|
/>
|
|
);
|
|
});
|
|
|
|
export const EditorPanel = withInjectables<Dependencies, EditorPanelProps>(NonInjectedEditorPanel, {
|
|
getProps: (di, props) => ({
|
|
...props,
|
|
dockStore: di.inject(dockStoreInjectable),
|
|
}),
|
|
});
|