From bdf5e0fc09c59ee238ce099a1b3914a48f9e6649 Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 31 Aug 2022 12:00:53 -0700 Subject: [PATCH] filter history by remote --- src/main.tsx | 79 ++++++++++++++++++++++++++++++++++++++++------------ src/model.ts | 29 +++++++++++-------- src/sh2.less | 33 ++++++++++++++++++++-- src/types.ts | 13 ++++++++- 4 files changed, 120 insertions(+), 34 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index 02c0b4981..5942b6793 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -8,7 +8,7 @@ import dayjs from 'dayjs' import {If, For, When, Otherwise, Choose} from "tsx-control-statements/components"; import cn from "classnames" import {TermWrap} from "./term"; -import type {SessionDataType, LineType, CmdDataType, RemoteType, RemoteStateType, RemoteInstanceType, RemotePtrType, HistoryItem} from "./types"; +import type {SessionDataType, LineType, CmdDataType, RemoteType, RemoteStateType, RemoteInstanceType, RemotePtrType, HistoryItem, HistoryQueryOpts} from "./types"; import localizedFormat from 'dayjs/plugin/localizedFormat'; import {GlobalModel, GlobalCommandRunner, Session, Cmd, Window, Screen, ScreenWindow, riToRPtr} from "./model"; @@ -547,6 +547,22 @@ class TextAreaInput extends React.Component<{}, {}> { let opts = mobx.toJS(inputModel.historyQueryOpts.get()); opts.includeMeta = !opts.includeMeta; inputModel.setHistoryQueryOpts(opts); + return; + } + if (e.code == "KeyR" && (e.getModifierState("Meta") && !e.getModifierState("Shift"))) { + console.log("meta-r"); + e.preventDefault(); + let opts = mobx.toJS(inputModel.historyQueryOpts.get()); + if (opts.limitRemote) { + opts.limitRemote = false; + opts.limitRemoteInstance = false; + } + else { + opts.limitRemote = true; + opts.limitRemoteInstance = true; + } + inputModel.setHistoryQueryOpts(opts); + return; } if (e.code == "Tab") { e.preventDefault(); @@ -602,6 +618,9 @@ class TextAreaInput extends React.Component<{}, {}> { displayLines = 5; } let disabled = inputModel.historyShow.get(); + if (disabled) { + displayLines = 1; + } return (
@@ -649,13 +668,36 @@ class HistoryInfo extends React.Component<{}, {}> { }, 3000); } - renderHItem(hitem : HistoryItem, isSelected : boolean) : any { + renderRemote(hitem : HistoryItem) : any { + if (hitem.remote == null || isBlank(hitem.remote.remoteid)) { + return sprintf("%-15s ", "") + } + let r = GlobalModel.getRemote(hitem.remote.remoteid); + if (r == null) { + return sprintf("%-15s ", "???") + } + let rname = ""; + if (!isBlank(r.remotealias)) { + rname = r.remotealias; + } + else { + rname = r.remotecanonicalname; + } + if (!isBlank(hitem.remote.name)) { + rname = rname + ":" + hitem.remote.name; + } + let rtn = sprintf("%-15s ", "[" + rname + "]") + return rtn; + } + + renderHItem(hitem : HistoryItem, opts : HistoryQueryOpts, isSelected : boolean) : any { let lines = hitem.cmdstr.split("\n"); let line : string = ""; let idx = 0; + let limitRemote = opts.limitRemote; return (
this.handleItemClick(hitem)}> -
{(isSelected ? "*" : " ")}{sprintf("%5s", hitem.historynum)} {lines[0]}
+
{(isSelected ? "*" : " ")}{sprintf("%5s", hitem.historynum)} {!limitRemote ? this.renderRemote(hitem) : ""}{lines[0]}
{line}
@@ -679,26 +721,26 @@ class HistoryInfo extends React.Component<{}, {}> { return (
- history - {" "} - [containing '{opts.queryStr}'] - {" "} - [this session ⌘S] - {" "} - [this window ⌘W] - {" "} - [this remote ⌘R] - {" "} - [{opts.includeMeta ? "including" : "excluding"} metacmds ⌘M] - {" "} (close ESC) +
history
+
+
[for window ⌘W]
+
+
[containing '{opts.queryStr}']
+
+
[{opts.limitRemote ? "this" : "any"} remote ⌘R]
+
+
[{opts.includeMeta ? "" : "no "}metacmds ⌘M]
+
+
(ESC)
+
-
+
[no history] 0}> - {this.renderHItem(hitem, (hitem == selItem))} + {this.renderHItem(hitem, opts, (hitem == selItem))}
@@ -749,8 +791,9 @@ class CmdInput extends React.Component<{}, {}> { let line : string = null; let idx : number = 0; return ( -
+
+
diff --git a/src/model.ts b/src/model.ts index b4d21e111..52c50c218 100644 --- a/src/model.ts +++ b/src/model.ts @@ -4,7 +4,7 @@ import {boundMethod} from "autobind-decorator"; import {handleJsonFetchResponse, base64ToArray, genMergeData, genMergeSimpleData} from "./util"; import {TermWrap} from "./term"; import {v4 as uuidv4} from "uuid"; -import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, RemotePtrType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType, UIContextType, HistoryInfoType} from "./types"; +import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, RemotePtrType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType, UIContextType, HistoryInfoType, HistoryQueryOpts} from "./types"; import {WSControl} from "./ws"; var GlobalUser = "sawka"; @@ -560,17 +560,6 @@ class Session { } } -type HistoryQueryOpts = { - queryType : "global" | "session" | "window"; - limitRemote : boolean, - limitRemoteInstance : boolean, - limitUser : boolean, - queryStr : string, - maxItems : number, - includeMeta : boolean, - fromTs : number, -}; - function getDefaultHistoryQueryOpts() : HistoryQueryOpts { return { queryType: "window", @@ -591,6 +580,7 @@ class InputModel { historyLoading : mobx.IObservableValue = mobx.observable.box(false); historyAfterLoadIndex : number = 0; historyItems : mobx.IObservableValue = mobx.observable.box(null, {name: "history-items", deep: false}); // sorted in reverse (most recent is index 0) + filteredHistoryItems : mobx.IComputedValue = null; historyIndex : mobx.IObservableValue = mobx.observable.box(0, {name: "history-index"}); // 1-indexed (because 0 is current) modHistory : mobx.IObservableArray = mobx.observable.array([""], {name: "mod-history"}); historyQueryOpts : OV = mobx.observable.box(getDefaultHistoryQueryOpts()); @@ -598,6 +588,12 @@ class InputModel { infoMsg : OV = mobx.observable.box(null); infoTimeoutId : any = null; + constructor() { + this.filteredHistoryItems = mobx.computed(() => { + return this._getFilteredHistoryItems(); + }); + } + _focusCmdInput() : void { let elem = document.getElementById("main-cmd-input"); if (elem != null) { @@ -776,6 +772,10 @@ class InputModel { } getFilteredHistoryItems() : HistoryItem[] { + return this.filteredHistoryItems.get(); + } + + _getFilteredHistoryItems() : HistoryItem[] { let hitems : HistoryItem[] = this.historyItems.get() ?? []; let rtn : HistoryItem[] = []; let opts = mobx.toJS(this.historyQueryOpts.get()); @@ -784,6 +784,7 @@ class InputModel { if (curRemote == null) { curRemote : RemotePtrType = {ownerid: "", name: "", remoteid: ""}; } + curRemote = mobx.toJS(curRemote); for (let i=0; i