Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions frontend/app/block/blockframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { TypeAheadModal } from "@/app/modals/typeaheadmodal";
import { ContextMenuModel } from "@/app/store/contextmenu";
import {
atoms,
createBlock,
getApi,
getBlockComponentModel,
getConnStatusAtom,
getHostName,
Expand Down Expand Up @@ -182,6 +184,9 @@ const BlockFrame_Header = ({
const prevMagifiedState = React.useRef(magnified);
const manageConnection = util.useAtomValueSafe(viewModel?.manageConnection);
const dragHandleRef = preview ? null : nodeModel.dragHandleRef;
const connName = blockData?.meta?.connection;
const allSettings = jotai.useAtomValue(atoms.fullConfigAtom);
const wshEnabled = allSettings?.connections?.[connName]?.["conn:wshenabled"] ?? true;

React.useEffect(() => {
if (!magnified || preview || prevMagifiedState.current) {
Expand Down Expand Up @@ -239,6 +244,11 @@ const BlockFrame_Header = ({
</div>
);
}
const wshInstallButton: IconButtonDecl = {
elemtype: "iconbutton",
icon: "link-slash",
title: "wsh is not installed for this connection",
};

return (
<div className="block-frame-default-header" ref={dragHandleRef} onContextMenu={onContextMenu}>
Expand All @@ -256,6 +266,9 @@ const BlockFrame_Header = ({
changeConnModalAtom={changeConnModalAtom}
/>
)}
{manageConnection && !wshEnabled && (
<IconButton decl={wshInstallButton} className="block-frame-header-iconbutton" />
)}
<div className="block-frame-textelems-wrapper">{headerTextElems}</div>
<div className="block-frame-end-icons">{endIconsElem}</div>
</div>
Expand Down Expand Up @@ -568,6 +581,10 @@ const ChangeConnectionBlockModal = React.memo(
const allConnStatus = jotai.useAtomValue(atoms.allConnStatus);
const [rowIndex, setRowIndex] = React.useState(0);
const connStatusMap = new Map<string, ConnStatus>();
const fullConfig = jotai.useAtomValue(atoms.fullConfigAtom);
const connectionsConfig = fullConfig.connections;
let filterOutNowsh = util.useAtomValueSafe(viewModel.filterOutNowsh) || true;

let maxActiveConnNum = 1;
for (const conn of allConnStatus) {
if (conn.activeconnnum > maxActiveConnNum) {
Expand Down Expand Up @@ -638,7 +655,12 @@ const ChangeConnectionBlockModal = React.memo(
if (conn === connSelected) {
createNew = false;
}
if (conn.includes(connSelected)) {
if (
conn.includes(connSelected) &&
connectionsConfig[conn]?.["display:hidden"] != true &&
(connectionsConfig[conn]?.["conn:wshenabled"] != false || !filterOutNowsh)
// != false is necessary because of defaults
) {
filteredList.push(conn);
}
}
Expand All @@ -647,7 +669,12 @@ const ChangeConnectionBlockModal = React.memo(
if (conn === connSelected) {
createNew = false;
}
if (conn.includes(connSelected)) {
if (
conn.includes(connSelected) &&
connectionsConfig[conn]?.["display:hidden"] != true &&
(connectionsConfig[conn]?.["conn:wshenabled"] != false || !filterOutNowsh)
// != false is necessary because of defaults
) {
filteredWslList.push(conn);
}
}
Expand Down Expand Up @@ -734,9 +761,38 @@ const ChangeConnectionBlockModal = React.memo(
};
return item;
});
const connectionsEditItem: SuggestionConnectionItem = {
status: "disconnected",
icon: "gear",
iconColor: "var(--grey-text-color",
value: "Edit Connections",
label: "Edit Connections",
onSelect: () => {
util.fireAndForget(async () => {
globalStore.set(changeConnModalAtom, false);
const path = `${getApi().getConfigDir()}/connections.json`;
const blockDef: BlockDef = {
meta: {
view: "preview",
file: path,
},
};
await createBlock(blockDef, false, true);
});
},
};
const sortedRemoteItems = remoteItems.sort(
(itemA: SuggestionConnectionItem, itemB: SuggestionConnectionItem) => {
const connNameA = itemA.value;
const connNameB = itemB.value;
const valueA = connectionsConfig[connNameA]?.["display:order"] ?? 0;
const valueB = connectionsConfig[connNameB]?.["display:order"] ?? 0;
return valueA - valueB;
}
);
const remoteSuggestions: SuggestionConnectionScope = {
headerText: "Remote",
items: remoteItems,
items: [...sortedRemoteItems, connectionsEditItem],
};

let suggestions: Array<SuggestionsType> = [];
Expand Down
31 changes: 31 additions & 0 deletions frontend/app/store/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ function useBlockMetaKeyAtom<T extends keyof MetaType>(blockId: string, key: T):
return useAtomValue(getBlockMetaKeyAtom(blockId, key));
}

function getConnConfigKeyAtom<T extends keyof ConnKeywords>(connName: string, key: T): Atom<ConnKeywords[T]> {
let connCache = getSingleConnAtomCache(connName);
const keyAtomName = "#conn-" + key;
let keyAtom = connCache.get(keyAtomName);
if (keyAtom != null) {
return keyAtom;
}
keyAtom = atom((get) => {
let fullConfig = get(atoms.fullConfigAtom);
return fullConfig.connections[connName]?.[key];
});
connCache.set(keyAtomName, keyAtom);
return keyAtom;
}

const settingsAtomCache = new Map<string, Atom<any>>();

function getOverrideConfigAtom<T extends keyof SettingsType>(blockId: string, key: T): Atom<SettingsType[T]> {
Expand All @@ -261,6 +276,13 @@ function getOverrideConfigAtom<T extends keyof SettingsType>(blockId: string, ke
if (metaKeyVal != null) {
return metaKeyVal;
}
const connNameAtom = getBlockMetaKeyAtom(blockId, "connection");
const connName = get(connNameAtom);
const connConfigKeyAtom = getConnConfigKeyAtom(connName, key as any);
const connConfigKeyVal = get(connConfigKeyAtom);
if (connConfigKeyVal != null) {
return connConfigKeyVal;
}
const settingsKeyAtom = getSettingsKeyAtom(key);
const settingsVal = get(settingsKeyAtom);
if (settingsVal != null) {
Expand Down Expand Up @@ -322,6 +344,15 @@ function getSingleBlockAtomCache(blockId: string): Map<string, Atom<any>> {
return blockCache;
}

function getSingleConnAtomCache(connName: string): Map<string, Atom<any>> {
let blockCache = blockAtomCache.get(connName);
if (blockCache == null) {
blockCache = new Map<string, Atom<any>>();
blockAtomCache.set(connName, blockCache);
}
return blockCache;
}

function useBlockAtom<T>(blockId: string, name: string, makeFn: () => Atom<T>): Atom<T> {
const blockCache = getSingleBlockAtomCache(blockId);
let atom = blockCache.get(name);
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/view/preview/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class PreviewModel implements ViewModel {
loadableSpecializedView: Atom<Loadable<{ specializedView?: string; errorStr?: string }>>;
manageConnection: Atom<boolean>;
connStatus: Atom<ConnStatus>;
filterOutNowsh?: Atom<boolean>;

metaFilePath: Atom<string>;
statFilePath: Atom<Promise<string>>;
Expand Down Expand Up @@ -164,6 +165,7 @@ export class PreviewModel implements ViewModel {
this.manageConnection = atom(true);
this.blockAtom = WOS.getWaveObjectAtom<Block>(`block:${blockId}`);
this.markdownShowToc = atom(false);
this.filterOutNowsh = atom(true);
this.monacoRef = createRef();
this.viewIcon = atom((get) => {
const blockData = get(this.blockAtom);
Expand Down
4 changes: 3 additions & 1 deletion frontend/app/view/sysinfo/sysinfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function convertWaveEventToDataItem(event: WaveEvent): DataItem {
return dataItem;
}

class SysinfoViewModel {
class SysinfoViewModel implements ViewModel {
viewType: string;
blockAtom: jotai.Atom<Block>;
termMode: jotai.Atom<string>;
Expand All @@ -109,6 +109,7 @@ class SysinfoViewModel {
metrics: jotai.Atom<string[]>;
connection: jotai.Atom<string>;
manageConnection: jotai.Atom<boolean>;
filterOutNowsh: jotai.Atom<boolean>;
connStatus: jotai.Atom<ConnStatus>;
plotMetaAtom: jotai.PrimitiveAtom<Map<string, TimeSeriesMeta>>;
endIconButtons: jotai.Atom<IconButtonDecl[]>;
Expand Down Expand Up @@ -176,6 +177,7 @@ class SysinfoViewModel {
});
this.plotMetaAtom = jotai.atom(new Map(Object.entries(DefaultPlotMeta)));
this.manageConnection = jotai.atom(true);
this.filterOutNowsh = jotai.atom(true);
this.loadingAtom = jotai.atom(true);
this.numPoints = jotai.atom((get) => {
const blockData = get(this.blockAtom);
Expand Down
15 changes: 11 additions & 4 deletions frontend/app/view/term/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type InitialLoadDataType = {
heldData: Uint8Array[];
};

class TermViewModel {
class TermViewModel implements ViewModel {
viewType: string;
nodeModel: BlockNodeModel;
connected: boolean;
Expand All @@ -54,6 +54,7 @@ class TermViewModel {
viewText: jotai.Atom<HeaderElem[]>;
blockBg: jotai.Atom<MetaType>;
manageConnection: jotai.Atom<boolean>;
filterOutNowsh?: jotai.Atom<boolean>;
connStatus: jotai.Atom<ConnStatus>;
termWshClient: TermWshClient;
vdomBlockId: jotai.Atom<string>;
Expand Down Expand Up @@ -196,6 +197,7 @@ class TermViewModel {
}
return true;
});
this.filterOutNowsh = jotai.atom(false);
this.termThemeNameAtom = useBlockAtom(blockId, "termthemeatom", () => {
return jotai.atom<string>((get) => {
return get(getOverrideConfigAtom(this.blockId, "term:theme")) ?? DefaultTermTheme;
Expand All @@ -221,7 +223,10 @@ class TermViewModel {
const blockData = get(this.blockAtom);
const fsSettingsAtom = getSettingsKeyAtom("term:fontsize");
const settingsFontSize = get(fsSettingsAtom);
const rtnFontSize = blockData?.meta?.["term:fontsize"] ?? settingsFontSize ?? 12;
const connName = blockData?.meta?.connection;
const fullConfig = get(atoms.fullConfigAtom);
const connFontSize = fullConfig?.connections?.[connName]?.["term:fontsize"];
const rtnFontSize = blockData?.meta?.["term:fontsize"] ?? connFontSize ?? settingsFontSize ?? 12;
if (typeof rtnFontSize != "number" || isNaN(rtnFontSize) || rtnFontSize < 4 || rtnFontSize > 64) {
return 12;
}
Expand Down Expand Up @@ -725,6 +730,8 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
const termModeRef = React.useRef(termMode);

const termFontSize = jotai.useAtomValue(model.fontSizeAtom);
const fullConfig = globalStore.get(atoms.fullConfigAtom);
const connFontFamily = fullConfig.connections?.[blockData?.meta?.connection]?.["term:fontfamily"];

React.useEffect(() => {
const fullConfig = globalStore.get(atoms.fullConfigAtom);
Expand All @@ -750,7 +757,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
{
theme: termTheme,
fontSize: termFontSize,
fontFamily: termSettings?.["term:fontfamily"] ?? "Hack",
fontFamily: termSettings?.["term:fontfamily"] ?? connFontFamily ?? "Hack",
drawBoldTextInBrightColors: false,
fontWeight: "normal",
fontWeightBold: "bold",
Expand Down Expand Up @@ -784,7 +791,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
termWrap.dispose();
rszObs.disconnect();
};
}, [blockId, termSettings, termFontSize]);
}, [blockId, termSettings, termFontSize, connFontFamily]);

React.useEffect(() => {
if (termModeRef.current == "vdom" && termMode == "term") {
Expand Down
1 change: 1 addition & 0 deletions frontend/types/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ declare global {
blockBg?: jotai.Atom<MetaType>;
manageConnection?: jotai.Atom<boolean>;
noPadding?: jotai.Atom<boolean>;
filterOutNowsh?: jotai.Atom<boolean>;

onBack?: () => void;
onForward?: () => void;
Expand Down
10 changes: 8 additions & 2 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,14 @@ declare global {

// wshrpc.ConnKeywords
type ConnKeywords = {
wshenabled?: boolean;
askbeforewshinstall?: boolean;
"conn:wshenabled"?: boolean;
"conn:askbeforewshinstall"?: boolean;
"display:hidden"?: boolean;
"display:order"?: number;
"term:*"?: boolean;
"term:fontsize"?: number;
"term:fontfamily"?: string;
"term:theme"?: string;
"ssh:user"?: string;
"ssh:hostname"?: string;
"ssh:port"?: string;
Expand Down
Loading