Skip to content

Commit c912b89

Browse files
committed
remove pinned tabs from backend
1 parent 655d6af commit c912b89

7 files changed

Lines changed: 37 additions & 114 deletions

File tree

pkg/service/workspaceservice/workspaceservice.go

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (svc *WorkspaceService) ListWorkspaces() (waveobj.WorkspaceList, error) {
122122

123123
func (svc *WorkspaceService) CreateTab_Meta() tsgenmeta.MethodMeta {
124124
return tsgenmeta.MethodMeta{
125-
ArgNames: []string{"workspaceId", "tabName", "activateTab", "pinned"},
125+
ArgNames: []string{"workspaceId", "tabName", "activateTab"},
126126
ReturnDesc: "tabId",
127127
}
128128
}
@@ -147,11 +147,11 @@ func (svc *WorkspaceService) GetIcons() []string {
147147
return wcore.WorkspaceIcons[:]
148148
}
149149

150-
func (svc *WorkspaceService) CreateTab(workspaceId string, tabName string, activateTab bool, pinned bool) (string, waveobj.UpdatesRtnType, error) {
150+
func (svc *WorkspaceService) CreateTab(workspaceId string, tabName string, activateTab bool) (string, waveobj.UpdatesRtnType, error) {
151151
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
152152
defer cancelFn()
153153
ctx = waveobj.ContextWithUpdates(ctx)
154-
tabId, err := wcore.CreateTab(ctx, workspaceId, tabName, activateTab, pinned, false)
154+
tabId, err := wcore.CreateTab(ctx, workspaceId, tabName, activateTab, false)
155155
if err != nil {
156156
return "", nil, fmt.Errorf("error creating tab: %w", err)
157157
}
@@ -165,41 +165,18 @@ func (svc *WorkspaceService) CreateTab(workspaceId string, tabName string, activ
165165
return tabId, updates, nil
166166
}
167167

168-
func (svc *WorkspaceService) ChangeTabPinning_Meta() tsgenmeta.MethodMeta {
169-
return tsgenmeta.MethodMeta{
170-
ArgNames: []string{"ctx", "workspaceId", "tabId", "pinned"},
171-
}
172-
}
173-
174-
func (svc *WorkspaceService) ChangeTabPinning(ctx context.Context, workspaceId string, tabId string, pinned bool) (waveobj.UpdatesRtnType, error) {
175-
log.Printf("ChangeTabPinning %s %s %v\n", workspaceId, tabId, pinned)
176-
ctx = waveobj.ContextWithUpdates(ctx)
177-
err := wcore.ChangeTabPinning(ctx, workspaceId, tabId, pinned)
178-
if err != nil {
179-
return nil, fmt.Errorf("error toggling tab pinning: %w", err)
180-
}
181-
updates := waveobj.ContextGetUpdatesRtn(ctx)
182-
go func() {
183-
defer func() {
184-
panichandler.PanicHandler("WorkspaceService:ChangeTabPinning:SendUpdateEvents", recover())
185-
}()
186-
wps.Broker.SendUpdateEvents(updates)
187-
}()
188-
return updates, nil
189-
}
190-
191168
func (svc *WorkspaceService) UpdateTabIds_Meta() tsgenmeta.MethodMeta {
192169
return tsgenmeta.MethodMeta{
193-
ArgNames: []string{"uiContext", "workspaceId", "tabIds", "pinnedTabIds"},
170+
ArgNames: []string{"uiContext", "workspaceId", "tabIds"},
194171
}
195172
}
196173

197-
func (svc *WorkspaceService) UpdateTabIds(uiContext waveobj.UIContext, workspaceId string, tabIds []string, pinnedTabIds []string) (waveobj.UpdatesRtnType, error) {
198-
log.Printf("UpdateTabIds %s %v %v\n", workspaceId, tabIds, pinnedTabIds)
174+
func (svc *WorkspaceService) UpdateTabIds(uiContext waveobj.UIContext, workspaceId string, tabIds []string) (waveobj.UpdatesRtnType, error) {
175+
log.Printf("UpdateTabIds %s %v\n", workspaceId, tabIds)
199176
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
200177
defer cancelFn()
201178
ctx = waveobj.ContextWithUpdates(ctx)
202-
err := wcore.UpdateWorkspaceTabIds(ctx, workspaceId, tabIds, pinnedTabIds)
179+
err := wcore.UpdateWorkspaceTabIds(ctx, workspaceId, tabIds)
203180
if err != nil {
204181
return nil, fmt.Errorf("error updating workspace tab ids: %w", err)
205182
}

pkg/waveobj/wtype.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,14 @@ type ActiveTabUpdate struct {
169169
}
170170

171171
type Workspace struct {
172-
OID string `json:"oid"`
173-
Version int `json:"version"`
174-
Name string `json:"name,omitempty"`
175-
Icon string `json:"icon,omitempty"`
176-
Color string `json:"color,omitempty"`
177-
TabIds []string `json:"tabids"`
178-
PinnedTabIds []string `json:"pinnedtabids"`
179-
ActiveTabId string `json:"activetabid"`
180-
Meta MetaMapType `json:"meta"`
172+
OID string `json:"oid"`
173+
Version int `json:"version"`
174+
Name string `json:"name,omitempty"`
175+
Icon string `json:"icon,omitempty"`
176+
Color string `json:"color,omitempty"`
177+
TabIds []string `json:"tabids"`
178+
ActiveTabId string `json:"activetabid"`
179+
Meta MetaMapType `json:"meta"`
181180
}
182181

183182
func (*Workspace) GetOType() string {

pkg/wcore/window.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ func CheckAndFixWindow(ctx context.Context, windowId string) *waveobj.Window {
181181
CloseWindow(ctx, windowId, false)
182182
return nil
183183
}
184-
if len(ws.TabIds) == 0 && len(ws.PinnedTabIds) == 0 {
184+
if len(ws.TabIds) == 0 {
185185
log.Printf("fixing workspace with no tabs %q (in checkAndFixWindow)\n", ws.OID)
186-
_, err = CreateTab(ctx, ws.OID, "", true, false, false)
186+
_, err = CreateTab(ctx, ws.OID, "", true, false)
187187
if err != nil {
188188
log.Printf("error creating tab (in checkAndFixWindow): %v\n", err)
189189
}

pkg/wcore/workspace.go

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@ var WorkspaceIcons = [...]string{
5050

5151
func CreateWorkspace(ctx context.Context, name string, icon string, color string, applyDefaults bool, isInitialLaunch bool) (*waveobj.Workspace, error) {
5252
ws := &waveobj.Workspace{
53-
OID: uuid.NewString(),
54-
TabIds: []string{},
55-
PinnedTabIds: []string{},
56-
Name: "",
57-
Icon: "",
58-
Color: "",
53+
OID: uuid.NewString(),
54+
TabIds: []string{},
55+
Name: "",
56+
Icon: "",
57+
Color: "",
5958
}
6059
err := wstore.DBInsert(ctx, ws)
6160
if err != nil {
6261
return nil, fmt.Errorf("error inserting workspace: %w", err)
6362
}
64-
_, err = CreateTab(ctx, ws.OID, "", true, false, isInitialLaunch)
63+
_, err = CreateTab(ctx, ws.OID, "", true, isInitialLaunch)
6564
if err != nil {
6665
return nil, fmt.Errorf("error creating tab: %w", err)
6766
}
@@ -128,13 +127,12 @@ func DeleteWorkspace(ctx context.Context, workspaceId string, force bool) (bool,
128127
return false, "", fmt.Errorf("error retrieving workspaceList: %w", err)
129128
}
130129

131-
if workspace.Name != "" && workspace.Icon != "" && !force && (len(workspace.TabIds) > 0 || len(workspace.PinnedTabIds) > 0) {
130+
if workspace.Name != "" && workspace.Icon != "" && !force && len(workspace.TabIds) > 0 {
132131
log.Printf("Ignoring DeleteWorkspace for workspace %s as it is named\n", workspaceId)
133132
return false, "", nil
134133
}
135134

136-
// delete all pinned and unpinned tabs
137-
for _, tabId := range append(workspace.TabIds, workspace.PinnedTabIds...) {
135+
for _, tabId := range workspace.TabIds {
138136
log.Printf("deleting tab %s\n", tabId)
139137
_, err := DeleteTab(ctx, workspaceId, tabId, false)
140138
if err != nil {
@@ -198,17 +196,16 @@ func getTabPresetMeta() (waveobj.MetaMapType, error) {
198196
}
199197

200198
// returns tabid
201-
func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, pinned bool, isInitialLaunch bool) (string, error) {
199+
func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, isInitialLaunch bool) (string, error) {
202200
if tabName == "" {
203201
ws, err := GetWorkspace(ctx, workspaceId)
204202
if err != nil {
205203
return "", fmt.Errorf("workspace %s not found: %w", workspaceId, err)
206204
}
207-
tabName = "T" + fmt.Sprint(len(ws.TabIds)+len(ws.PinnedTabIds)+1)
205+
tabName = "T" + fmt.Sprint(len(ws.TabIds)+1)
208206
}
209207

210-
// The initial tab for the initial launch should be pinned
211-
tab, err := createTabObj(ctx, workspaceId, tabName, pinned || isInitialLaunch, nil)
208+
tab, err := createTabObj(ctx, workspaceId, tabName, nil)
212209
if err != nil {
213210
return "", fmt.Errorf("error creating tab: %w", err)
214211
}
@@ -240,7 +237,7 @@ func CreateTab(ctx context.Context, workspaceId string, tabName string, activate
240237
return tab.OID, nil
241238
}
242239

243-
func createTabObj(ctx context.Context, workspaceId string, name string, pinned bool, meta waveobj.MetaMapType) (*waveobj.Tab, error) {
240+
func createTabObj(ctx context.Context, workspaceId string, name string, meta waveobj.MetaMapType) (*waveobj.Tab, error) {
244241
ws, err := GetWorkspace(ctx, workspaceId)
245242
if err != nil {
246243
return nil, fmt.Errorf("workspace %s not found: %w", workspaceId, err)
@@ -256,11 +253,7 @@ func createTabObj(ctx context.Context, workspaceId string, name string, pinned b
256253
layoutState := &waveobj.LayoutState{
257254
OID: layoutStateId,
258255
}
259-
if pinned {
260-
ws.PinnedTabIds = append(ws.PinnedTabIds, tab.OID)
261-
} else {
262-
ws.TabIds = append(ws.TabIds, tab.OID)
263-
}
256+
ws.TabIds = append(ws.TabIds, tab.OID)
264257
wstore.DBInsert(ctx, tab)
265258
wstore.DBInsert(ctx, layoutState)
266259
wstore.DBUpdate(ctx, ws)
@@ -279,14 +272,10 @@ func DeleteTab(ctx context.Context, workspaceId string, tabId string, recursive
279272

280273
// ensure tab is in workspace
281274
tabIdx := utilfn.FindStringInSlice(ws.TabIds, tabId)
282-
tabIdxPinned := utilfn.FindStringInSlice(ws.PinnedTabIds, tabId)
283-
if tabIdx != -1 {
284-
ws.TabIds = append(ws.TabIds[:tabIdx], ws.TabIds[tabIdx+1:]...)
285-
} else if tabIdxPinned != -1 {
286-
ws.PinnedTabIds = append(ws.PinnedTabIds[:tabIdxPinned], ws.PinnedTabIds[tabIdxPinned+1:]...)
287-
} else {
275+
if tabIdx == -1 {
288276
return "", fmt.Errorf("tab %s not found in workspace %s", tabId, workspaceId)
289277
}
278+
ws.TabIds = append(ws.TabIds[:tabIdx], ws.TabIds[tabIdx+1:]...)
290279

291280
// close blocks (sends events + stops block controllers)
292281
tab, _ := wstore.DBGet[*waveobj.Tab](ctx, tabId)
@@ -303,13 +292,7 @@ func DeleteTab(ctx context.Context, workspaceId string, tabId string, recursive
303292
newActiveTabId := ws.ActiveTabId
304293
if ws.ActiveTabId == tabId {
305294
if len(ws.TabIds) > 0 {
306-
if tabIdx != -1 {
307-
newActiveTabId = ws.TabIds[max(0, min(tabIdx-1, len(ws.TabIds)-1))]
308-
} else {
309-
newActiveTabId = ws.TabIds[0]
310-
}
311-
} else if len(ws.PinnedTabIds) > 0 {
312-
newActiveTabId = ws.PinnedTabIds[0]
295+
newActiveTabId = ws.TabIds[max(0, min(tabIdx-1, len(ws.TabIds)-1))]
313296
} else {
314297
newActiveTabId = ""
315298
}
@@ -353,44 +336,19 @@ func SetActiveTab(ctx context.Context, workspaceId string, tabId string) error {
353336
return nil
354337
}
355338

356-
func ChangeTabPinning(ctx context.Context, workspaceId string, tabId string, pinned bool) error {
357-
if tabId != "" && workspaceId != "" {
358-
workspace, err := GetWorkspace(ctx, workspaceId)
359-
if err != nil {
360-
return fmt.Errorf("workspace %s not found: %w", workspaceId, err)
361-
}
362-
if pinned && utilfn.FindStringInSlice(workspace.PinnedTabIds, tabId) == -1 {
363-
if utilfn.FindStringInSlice(workspace.TabIds, tabId) == -1 {
364-
return fmt.Errorf("tab %s not found in workspace %s", tabId, workspaceId)
365-
}
366-
workspace.TabIds = utilfn.RemoveElemFromSlice(workspace.TabIds, tabId)
367-
workspace.PinnedTabIds = append(workspace.PinnedTabIds, tabId)
368-
} else if !pinned && utilfn.FindStringInSlice(workspace.PinnedTabIds, tabId) != -1 {
369-
if utilfn.FindStringInSlice(workspace.PinnedTabIds, tabId) == -1 {
370-
return fmt.Errorf("tab %s not found in workspace %s", tabId, workspaceId)
371-
}
372-
workspace.PinnedTabIds = utilfn.RemoveElemFromSlice(workspace.PinnedTabIds, tabId)
373-
workspace.TabIds = append([]string{tabId}, workspace.TabIds...)
374-
}
375-
wstore.DBUpdate(ctx, workspace)
376-
}
377-
return nil
378-
}
379-
380339
func SendActiveTabUpdate(ctx context.Context, workspaceId string, newActiveTabId string) {
381340
eventbus.SendEventToElectron(eventbus.WSEventType{
382341
EventType: eventbus.WSEvent_ElectronUpdateActiveTab,
383342
Data: &waveobj.ActiveTabUpdate{WorkspaceId: workspaceId, NewActiveTabId: newActiveTabId},
384343
})
385344
}
386345

387-
func UpdateWorkspaceTabIds(ctx context.Context, workspaceId string, tabIds []string, pinnedTabIds []string) error {
346+
func UpdateWorkspaceTabIds(ctx context.Context, workspaceId string, tabIds []string) error {
388347
ws, _ := wstore.DBGet[*waveobj.Workspace](ctx, workspaceId)
389348
if ws == nil {
390349
return fmt.Errorf("workspace not found: %q", workspaceId)
391350
}
392351
ws.TabIds = tabIds
393-
ws.PinnedTabIds = pinnedTabIds
394352
wstore.DBUpdate(ctx, ws)
395353
return nil
396354
}

pkg/wshrpc/wshserver/resolvers.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,13 @@ func resolveTabNum(ctx context.Context, data wshrpc.CommandResolveIdsData, value
156156
return nil, fmt.Errorf("error getting workspace: %v", err)
157157
}
158158

159-
numPinnedTabs := len(ws.PinnedTabIds)
160-
numTabs := len(ws.TabIds) + numPinnedTabs
159+
numTabs := len(ws.TabIds)
161160
if tabNum < 1 || tabNum > numTabs {
162161
return nil, fmt.Errorf("tab num out of range, workspace has %d tabs", numTabs)
163162
}
164163

165164
tabIdx := tabNum - 1
166-
var resolvedTabId string
167-
if tabIdx < numPinnedTabs {
168-
resolvedTabId = ws.PinnedTabIds[tabIdx]
169-
} else {
170-
resolvedTabId = ws.TabIds[tabIdx-numPinnedTabs]
171-
}
165+
resolvedTabId := ws.TabIds[tabIdx]
172166
return &waveobj.ORef{OType: waveobj.OType_Tab, OID: resolvedTabId}, nil
173167
}
174168

pkg/wshrpc/wshserver/wshserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ func (ws *WshServer) BlocksListCommand(
906906
log.Printf("error finding window for workspace %s: %v", wsID, err)
907907
}
908908

909-
for _, tabID := range append(wsData.PinnedTabIds, wsData.TabIds...) {
909+
for _, tabID := range wsData.TabIds {
910910
tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, tabID)
911911
if err != nil {
912912
return nil, err

pkg/wstore/wstore_dbops.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ func DBFindWorkspaceForTabId(ctx context.Context, tabId string) (string, error)
377377
SELECT 1
378378
FROM json_each(w.data, '$.tabids') AS je
379379
WHERE je.value = variable.value
380-
)
381-
OR EXISTS (
382-
SELECT 1
383-
FROM json_each(w.data, '$.pinnedtabids') AS je
384-
WHERE je.value = variable.value
385380
);
386381
`
387382
wsId := tx.GetString(query, tabId)

0 commit comments

Comments
 (0)