╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
230 // the sorted sets to window, per status: the tag's sets when filtered, 231 // else the top-level per-status sets. a missing set is an empty window. 232 var open_set: ?DB.SortedSet(.read_only) = null; 233 var closed_set: ?DB.SortedSet(.read_only) = null; 234 if (tagged) { 235 const tag_to_issues_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.tag_status_to_id_set_key)) orelse return error.NotFound; 236 const tag_to_issues = try DB.SortedMap(.read_only).init(tag_to_issues_cursor); 237 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, empty.tag)); 238 open_set = try thread.tagStatusSet(Self, DB, tag_to_issues, decoded, .open); 239 closed_set = try thread.tagStatusSet(Self, DB, tag_to_issues, decoded, .closed); 240 // a tag no issue carries is a bad url 241 if (open_set == null and closed_set == null) return error.NotFound; 242 } else if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.status_to_id_set_key))) |status_to_issues_cursor| { 243 const status_to_issues = try DB.SortedMap(.read_only).init(status_to_issues_cursor); 244 open_set = try thread.statusSet(Self, DB, status_to_issues, .open); 245 closed_set = try thread.statusSet(Self, DB, status_to_issues, .closed); 246 } else if (rooted) return error.NotFound; 247 248 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.record_map_key)) orelse { 249 if (strict) return error.NotFound; 250 return empty; 251 }; 252 const event_id_to_issue = try DB.HashMap(.read_only).init(event_id_to_issue_cursor); 253 254 // the conflicted issues' container: a set view for membership and 255 // windowing, a map view for the resolve entry, over the same cursor. 256 var conflict_set: ?DB.SortedSet(.read_only) = null; 257 var conflicts_map: ?DB.SortedMap(.read_only) = null; 258 if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.conflicts_key))) |cursor| { 259 conflict_set = try DB.SortedSet(.read_only).init(cursor); 260 conflicts_map = try DB.SortedMap(.read_only).init(cursor); 261 } 262 263 // a named issue roots its own status's window at itself (the conflicts 264 // view's window instead); the other windows start at the beginning. 265 var resolved_view = empty.view; 266 var open_root: ?[]const u8 = null; 267 var closed_root: ?[]const u8 = null; 268 var conflicts_root: ?[]const u8 = null; 269 var conflict_data: ?Conflict = null; 270 if (rooted) { 271 const id_bytes = evt.parseEventId(empty.selected_id) catch return error.NotFound; 272 const issue_cursor = try event_id_to_issue.getCursor(hash.hashInt(repo_opts.hash, &id_bytes)) orelse return error.NotFound; 273 const issue_map = try DB.HashMap(.read_only).init(issue_cursor); 274 const issue_event = try evt.read(evt.Issue.Record, DB, repo_opts.hash, arena, issue_map); 275 const order_key = try aa.dupe(u8, &evt.orderKeyDesc(issue_event.created_order, &id_bytes)); 276 277 if (view == .conflicts) { 278 // the id roots the conflicts window, so it must be conflicted 279 const set = conflict_set orelse return error.NotFound; 280 if (!try set.contains(order_key)) return error.NotFound; 281 conflicts_root = order_key; 282 } else { 283 // the named issue must be in its windowed set (a tag url can name 284 // an issue that doesn't carry the tag). 285 const set = (switch (issue_event.event.status) { 286 .open => open_set, 287 .closed => closed_set, 288 }) orelse return error.NotFound; 289 if (!try set.contains(order_key)) return error.NotFound; 290 291 switch (issue_event.event.status) { 292 .open => open_root = order_key, 293 .closed => closed_root = order_key, 294 } 295 // form urls keep their view; otherwise the issue's status picks it. 296 if (view != .edit and view != .new_comment and view != .edit_comment and view != .remove) resolved_view = switch (issue_event.event.status) { 297 .open => .open, 298 .closed => .closed, 299 }; 300 301 // a resolve url shows the resolve view only while the issue still 302 // has a conflict entry; otherwise the status list stands. the 303 // wasm client renders from the snapshot, so the diff machinery 304 // this pulls in is gated out of its build. 305 if (comptime !wasm) { 306 if (view == .resolve) { 307 if (conflicts_map) |map| { 308 if (try map.getCursor(order_key)) |conflict_cursor| { 309 const conflict_entry = try DB.HashMap(.read_only).init(conflict_cursor); 310 conflict_data = try thread.readConflict(Self, repo_kind, repo_opts, arena, repo, io, admin_moment, haxy_moment, &id_bytes, issue_event, conflict_entry); 311 resolved_view = .resolve; 312 } 313 } 314 } 315 } 316 } 317 } 318 319 const thread_comments_start = if (empty.comment_id.len == 0) comments_start else 0; 320 const open_window = try thread.loadWindow(Self, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, open_set, open_root, conflict_set, empty.selected_id, thread_comments_start); 321 const closed_window = try thread.loadWindow(Self, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, closed_set, closed_root, conflict_set, empty.selected_id, thread_comments_start); 322 const conflicts_window = try thread.loadWindow(Self, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, conflict_set, conflicts_root, conflict_set, empty.selected_id, thread_comments_start); 323 if (view == .conflicts and conflicts_window.count > 0) resolved_view = .conflicts; 324 325 const comment_page = if (empty.comment_id.len == 0) 326 null 327 else 328 try Comment.init(repo_opts.hash, arena, admin_moment, haxy_moment, empty.selected_id, empty.comment_id, comments_start); 329 330 const tags = try thread.loadTags(Self, repo_opts.hash, arena, haxy_moment); 331 332 return .{ 333 .identity = empty.identity, 334 .tag = empty.tag, 335 .selected_id = empty.selected_id, 336 .comment_id = empty.comment_id, 337 .comments_start = comments_start, 338 .comment_page = comment_page, 339 .open = open_window, 340 .closed = closed_window, 341 .conflicts = conflicts_window, 342 .conflict = conflict_data, 343 .theirs_picks = empty.theirs_picks, 344 .view = resolved_view, 345 .description_page = empty.description_page, 346 .tags = tags, 347 }; 348 } 349 350 pub const View = thread.View(.issue, Self); 351 352 pub const Header = thread.Header; 353 354 // tabs switching between the issues page's views 355 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 356 var header = try Header.init(allocator); 357 errdefer header.deinit(allocator); 358 const aa = session.page_arena.allocator(); 359 const selected_index = View.viewIndex(data.view); 360 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_issues; 361 362 // a list tab per status, labeled with its listing's issue count 363 for ([_]evt.Issue.Status{ .open, .closed }, 0..) |status, index| { 364 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 365 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 366 var label_buf: [64]u8 = undefined; 367 const label = try std.fmt.bufPrint(&label_buf, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 368 try header.addTab(allocator, label, link, index); 369 } 370 371 // tags tab, labeled with the active tag filter 372 { 373 const tags_route = ui.RoutablePage.repoThreadTagsRoute(.issue, data.identity, data.tag) orelse return error.RouteTooLong; 374 const tags_link = try ui.inPageTabLink(session, tags_route, page_selected and selected_index == View.viewIndex(.tags)); 375 const label = if (data.tag.len == 0) "tags" else blk: { 376 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 377 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 378 }; 379 try header.addTab(allocator, label, tags_link, View.viewIndex(.tags)); 380 } 381 382 // new-issue tab; an edit or resolve url shows its tab in this place 383 { 384 const route = switch (data.view) { 385 .edit => ui.RoutablePage.repoThreadEditRoute(.issue, data.identity, data.selected_id) orelse return error.RouteTooLong, 386 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 387 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 388 .remove => ui.RoutablePage.repoThreadRemoveRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 389 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 390 else => ui.RoutablePage.repoThreadNewRoute(.issue, data.identity) orelse return error.RouteTooLong, 391 }; 392 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 393 const label: []const u8 = switch (data.view) { 394 .edit => "edit", 395 .new_comment => "reply", 396 .edit_comment => "edit", 397 .remove => "remove", 398 .resolve => "resolve", 399 else => "new", 400 }; 401 try header.addTab(allocator, label, link, View.viewIndex(.new)); 402 } 403 404 // conflicts tab, labeled with the conflict count 405 if (data.conflicts.count > 0) { 406 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 407 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 408 var label_buf: [64]u8 = undefined; 409 const label = try std.fmt.bufPrint(&label_buf, "conflicts ({d})", .{data.conflicts.count}); 410 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 411 } 412 413 header.select(View.viewIndex(data.view)); 414 return header; 415 } 416