╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
298 conflict_set = try DB.SortedSet(.read_only).init(cursor); 299 conflicts_map = try DB.SortedMap(.read_only).init(cursor); 300 } 301 302 // a named issue roots its own status's window at itself (the conflicts 303 // view's window instead); the other windows start at the beginning. 304 var resolved_view = empty.view; 305 var open_root: ?[]const u8 = null; 306 var closed_root: ?[]const u8 = null; 307 var conflicts_root: ?[]const u8 = null; 308 var conflict_data: ?Conflict = null; 309 if (rooted) { 310 const id_bytes = evt.parseEventId(empty.selected_id) catch return error.NotFound; 311 const issue_cursor = try event_id_to_issue.getCursor(hash.hashInt(repo_opts.hash, &id_bytes)) orelse return error.NotFound; 312 const issue_map = try DB.HashMap(.read_only).init(issue_cursor); 313 const issue_event = try evt.read(evt.Issue.Record, DB, repo_opts.hash, arena, issue_map); 314 const order_key = try aa.dupe(u8, &evt.orderKeyDesc(issue_event.created_order, &id_bytes)); 315 316 if (view == .conflicts) { 317 // the id roots the conflicts window, so it must be conflicted 318 const set = conflict_set orelse return error.NotFound; 319 if (!try set.contains(order_key)) return error.NotFound; 320 conflicts_root = order_key; 321 } else { 322 // the named issue must be in its windowed set (a label url can name 323 // an issue that doesn't carry the label). 324 const set = (switch (issue_event.event.status) { 325 .open => open_set, 326 .closed => closed_set, 327 }) orelse return error.NotFound; 328 if (!try set.contains(order_key)) return error.NotFound; 329 if (assignee_set) |assignee_issues| if (!try assignee_issues.contains(order_key)) return error.NotFound; 330 331 switch (issue_event.event.status) { 332 .open => open_root = order_key, 333 .closed => closed_root = order_key, 334 } 335 // form urls keep their view; otherwise the issue's status picks it. 336 if (view != .edit and view != .new_comment and view != .edit_comment and view != .remove) resolved_view = switch (issue_event.event.status) { 337 .open => .open, 338 .closed => .closed, 339 }; 340 341 // a resolve url shows the resolve view only while the issue still 342 // has a conflict entry; otherwise the status list stands. the 343 // wasm client renders from the snapshot, so the diff machinery 344 // this pulls in is gated out of its build. 345 if (comptime !wasm) { 346 if (view == .resolve) { 347 if (conflicts_map) |map| { 348 if (try map.getCursor(order_key)) |conflict_cursor| { 349 const conflict_entry = try DB.HashMap(.read_only).init(conflict_cursor); 350 conflict_data = try thread.readConflict(Self, repo_kind, repo_opts, arena, repo, io, admin_moment, haxy_moment, &id_bytes, issue_event, conflict_entry); 351 resolved_view = .resolve; 352 } 353 } 354 } 355 } 356 } 357 } 358 359 const thread_comments_start = if (empty.comment_id.len == 0) comments_start else 0; 360 const open_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, open_set, open_root, conflict_set, empty.selected_id, thread_comments_start, empty.search, assignee_set, viewer); 361 const closed_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, closed_set, closed_root, conflict_set, empty.selected_id, thread_comments_start, empty.search, assignee_set, viewer); 362 const conflicts_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, conflict_set, conflicts_root, conflict_set, empty.selected_id, thread_comments_start, null, null, viewer); 363 if (view == .conflicts and conflicts_window.count > 0) resolved_view = .conflicts; 364 365 const comment_page = if (empty.comment_id.len == 0) 366 null 367 else 368 try Comment.init(repo_opts.hash, arena, admin_moment, haxy_moment, empty.selected_id, empty.comment_id, comments_start, viewer); 369 370 const labels = try thread.loadLabels(Self, repo_opts.hash, arena, haxy_moment); 371 372 return .{ 373 .identity = empty.identity, 374 .label = empty.label, 375 .assignee = empty.assignee, 376 .assignee_found = assignee_found, 377 .search = empty.search, 378 .selected_id = empty.selected_id, 379 .comment_id = empty.comment_id, 380 .comments_start = comments_start, 381 .comment_page = comment_page, 382 .viewer = viewer, 383 .open = open_window, 384 .closed = closed_window, 385 .conflicts = conflicts_window, 386 .conflict = conflict_data, 387 .theirs_picks = empty.theirs_picks, 388 .view = resolved_view, 389 .description_page = empty.description_page, 390 .labels = labels, 391 }; 392 } 393 394 pub const View = thread.View(.issue, Self); 395 pub const Detail = thread.Detail(.issue, Self); 396 pub const detail_widget_name = "repo_issue_detail"; 397 398 pub const Header = thread.Header; 399 400 const open_tab_label = "open"; 401 const closed_tab_label = "closed"; 402 const labels_tab_label = "labels"; 403 const edit_tab_label = "edit"; 404 const reply_tab_label = "reply"; 405 const remove_tab_label = "remove"; 406 const resolve_tab_label = "resolve"; 407 const new_tab_label = "new"; 408 const conflicts_tab_label = "conflicts"; 409 410 // tabs switching between the issues page's views 411 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 412 var header = try Header.init(allocator, session, data.search, .{ 413 .label = if (data.assignee_found) " assignee " else " assignee (not found) ", 414 .text = std.Uri.percentDecodeInPlace(try session.page_arena.allocator().dupe(u8, data.assignee)), 415 }); 416 errdefer header.deinit(allocator); 417 const selected_index = View.viewIndex(data.view); 418 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_issues; 419 420 // a list tab per status, labeled with its listing's issue count 421 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label }; 422 for ([_]evt.Issue.Status{ .open, .closed }, status_labels, 0..) |status, status_label, index| { 423 const route = try thread.searchRoute(ui.RoutablePage.withEncodedAssignee(ui.RoutablePage.repoIssuesRoute(data.identity, status, data.label, ""), data.assignee), data.search); 424 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 425 var label_buf: [64]u8 = undefined; 426 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 427 try header.addTab(allocator, label, link, index); 428 } 429 430 // labels tab 431 { 432 const labels_route = try thread.searchRoute(ui.RoutablePage.withEncodedAssignee(ui.RoutablePage.repoThreadLabelsRoute(.issue, data.identity, data.label), data.assignee), data.search); 433 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 434 try header.addTab(allocator, labels_tab_label, labels_link, View.viewIndex(.labels)); 435 } 436 437 // new-issue tab; an edit or resolve url shows its tab in this place 438 { 439 const route = switch (data.view) { 440 .edit => ui.RoutablePage.repoThreadEditRoute(.issue, data.identity, data.selected_id) orelse return error.RouteTooLong, 441 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 442 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 443 .remove => ui.RoutablePage.repoThreadRemoveRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 444 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 445 else => ui.RoutablePage.repoThreadNewRoute(.issue, data.identity) orelse return error.RouteTooLong, 446 }; 447 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 448 const label: []const u8 = switch (data.view) { 449 .edit => edit_tab_label, 450 .new_comment => reply_tab_label, 451 .edit_comment => edit_tab_label, 452 .remove => remove_tab_label, 453 .resolve => resolve_tab_label, 454 else => new_tab_label, 455 }; 456 try header.addTab(allocator, label, link, View.viewIndex(.new)); 457 } 458 459 // conflicts tab, labeled with the conflict count 460 if (data.conflicts.count > 0) { 461 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 462 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 463 var label_buf: [64]u8 = undefined; 464 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 465 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 466 } 467 468 header.select(View.viewIndex(data.view)); 469 return header; 470 } 471