returns tabid
(ctx context.Context, workspaceId string, tabName string, activateTab bool, isInitialLaunch bool)
| 221 | |
| 222 | // returns tabid |
| 223 | func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, isInitialLaunch bool) (string, error) { |
| 224 | if tabName == "" { |
| 225 | ws, err := GetWorkspace(ctx, workspaceId) |
| 226 | if err != nil { |
| 227 | return "", fmt.Errorf("workspace %s not found: %w", workspaceId, err) |
| 228 | } |
| 229 | tabNames := make([]string, 0, len(ws.TabIds)) |
| 230 | for _, tabId := range ws.TabIds { |
| 231 | tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, tabId) |
| 232 | if err != nil || tab == nil { |
| 233 | continue |
| 234 | } |
| 235 | tabNames = append(tabNames, tab.Name) |
| 236 | } |
| 237 | tabName = getNextTabName(tabNames) |
| 238 | } |
| 239 | |
| 240 | tab, err := createTabObj(ctx, workspaceId, tabName, nil) |
| 241 | if err != nil { |
| 242 | return "", fmt.Errorf("error creating tab: %w", err) |
| 243 | } |
| 244 | if activateTab { |
| 245 | err = SetActiveTab(ctx, workspaceId, tab.OID) |
| 246 | if err != nil { |
| 247 | return "", fmt.Errorf("error setting active tab: %w", err) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // No need to apply an initial layout for the initial launch, since the starter layout will get applied after onboarding modal dismissal |
| 252 | if !isInitialLaunch { |
| 253 | err = ApplyPortableLayout(ctx, tab.OID, GetNewTabLayout(), true) |
| 254 | if err != nil { |
| 255 | return tab.OID, fmt.Errorf("error applying new tab layout: %w", err) |
| 256 | } |
| 257 | tabBg := getTabBackground() |
| 258 | if tabBg != "" { |
| 259 | tabORef := waveobj.ORefFromWaveObj(tab) |
| 260 | wstore.UpdateObjectMeta(ctx, *tabORef, waveobj.MetaMapType{waveobj.MetaKey_TabBackground: tabBg}, false) |
| 261 | } |
| 262 | } |
| 263 | telemetry.GoUpdateActivityWrap(wshrpc.ActivityUpdate{NewTab: 1}, "createtab") |
| 264 | telemetry.GoRecordTEventWrap(&telemetrydata.TEvent{ |
| 265 | Event: "action:createtab", |
| 266 | }) |
| 267 | return tab.OID, nil |
| 268 | } |
| 269 | |
| 270 | func createTabObj(ctx context.Context, workspaceId string, name string, meta waveobj.MetaMapType) (*waveobj.Tab, error) { |
| 271 | ws, err := GetWorkspace(ctx, workspaceId) |
no test coverage detected