Skip to content

Commit

Permalink
workaround for perf issue by preventing redraw of today details table
Browse files Browse the repository at this point in the history
when it is hidden.  added new context items to records in today
  • Loading branch information
aapis committed Feb 2, 2023
1 parent e9f5bfa commit dac03e0
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 26 deletions.
4 changes: 2 additions & 2 deletions DLPrototype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 69;
CURRENT_PROJECT_VERSION = 70;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand Down Expand Up @@ -936,7 +936,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 69;
CURRENT_PROJECT_VERSION = 70;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand Down
10 changes: 7 additions & 3 deletions DLPrototype/Views/Today/LogTable/LogTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI

struct LogTable: View, Identifiable {
public var id = UUID()
@Binding public var selectedJob: String

@State private var records: [LogRecord] = []
@State private var wordCount: Int = 0
Expand Down Expand Up @@ -164,7 +165,8 @@ struct LogTable: View, Identifiable {
LogRow(
entry: entry,
index: records.firstIndex(of: record),
colour: Color.fromStored((record.job?.colour) ?? Theme.rowColourAsDouble)
colour: Color.fromStored((record.job?.colour) ?? Theme.rowColourAsDouble),
selectedJob: $selectedJob
)
}
}.onAppear(perform: changeSort)
Expand All @@ -178,7 +180,7 @@ struct LogTable: View, Identifiable {
}

var tableDetails: some View {
LogTableDetails(records: $records, selectedDate: $selectedDate)
LogTableDetails(records: $records, selectedDate: $selectedDate, open: $showSidebar)
.environmentObject(updater)
}

Expand Down Expand Up @@ -232,8 +234,10 @@ struct LogTable: View, Identifiable {
}

struct LogTablePreview: PreviewProvider {
@State static public var sj: String = "11.0"

static var previews: some View {
LogTable()
LogTable(selectedJob: $sj)
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
.frame(width: 700)
}
Expand Down
24 changes: 13 additions & 11 deletions DLPrototype/Views/Today/LogTable/LogTableDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum StatisticPeriod: String, CaseIterable {
struct LogTableDetails: View {
@Binding public var records: [LogRecord]
@Binding public var selectedDate: Date
@Binding public var open: Bool

@State private var statistics: [any Statistics] = []

Expand Down Expand Up @@ -175,7 +176,7 @@ struct LogTableDetails: View {
}

private func update() -> Void {
if records.count > 0 {
if records.count > 0 && open {
statistics = []

for record in records {
Expand Down Expand Up @@ -228,16 +229,16 @@ struct LogTableDetails: View {
.frame(height: 30)
}
}
.help(note.title!)
.buttonStyle(.borderless)
.padding(5)
.onHover { inside in
if inside {
NSCursor.pointingHand.push()
} else {
NSCursor.pop()
.help(note.title!)
.buttonStyle(.borderless)
.padding(5)
.onHover { inside in
if inside {
NSCursor.pointingHand.push()
} else {
NSCursor.pop()
}
}
}
)
)
)
Expand Down Expand Up @@ -289,9 +290,10 @@ struct LogTableDetails: View {
struct LogTableDetailsPreview: PreviewProvider {
@State static private var selectedDate: Date = Date()
@State static private var records: [LogRecord] = []
@State static private var open: Bool = true

static var previews: some View {
LogTableDetails(records: $records, selectedDate: $selectedDate)
LogTableDetails(records: $records, selectedDate: $selectedDate, open: $open)
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}
44 changes: 37 additions & 7 deletions DLPrototype/Views/Today/LogTable/RowTypes/LogRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct LogRow: View, Identifiable {
public var colour: Color
public var id = UUID()

@Binding public var selectedJob: String

@State public var isEditing: Bool = false
@State public var isDeleting: Bool = false
@State public var message: String = ""
Expand Down Expand Up @@ -48,7 +50,7 @@ struct LogRow: View, Identifiable {
.frame(maxWidth: 101)
.contextMenu {
Button(action: {ClipboardHelper.copy(entry.timestamp)}, label: {
Text("Copy \"\(entry.timestamp)\"")
Text("Copy timestamp")
})
}

Expand All @@ -65,9 +67,27 @@ struct LogRow: View, Identifiable {
)
.frame(maxWidth: 100)
.contextMenu {
if entry.jobObject != nil && entry.jobObject!.uri != nil {
Button(action: {ClipboardHelper.copy(entry.jobObject!.uri!.absoluteString)}, label: {
Text("Copy \"\(entry.jobObject!.uri!.absoluteString)\"")
if entry.jobObject != nil {
if entry.jobObject!.uri != nil {
Button(action: {ClipboardHelper.copy(entry.jobObject!.uri!.absoluteString)}, label: {
Text("Copy job URL")
})
}

Button(action: {ClipboardHelper.copy(entry.jobObject!.jid.string)}, label: {
Text("Copy job ID")
})
}

Button(action: {ClipboardHelper.copy(colour.description.debugDescription)}, label: {
Text("Copy colour code")
})

Divider()

if entry.jobObject != nil {
Button(action: {setJob(entry.jobObject!.jid.string)}, label: {
Text("Set job")
})
}
}
Expand All @@ -83,7 +103,7 @@ struct LogRow: View, Identifiable {
)
.contextMenu {
Button(action: {ClipboardHelper.copy(entry.message)}, label: {
Text("Copy \"\(entry.message)\"")
Text("Copy message")
})
}

Expand Down Expand Up @@ -114,6 +134,14 @@ struct LogRow: View, Identifiable {
}
// .onHover(perform: onHover)
}

private func setJob(_ job: String) -> Void {
let dotIndex = (job.range(of: ".")?.lowerBound)

if dotIndex != nil {
selectedJob = String(job.prefix(upTo: dotIndex!))
}
}

private func setEditableValues() -> Void {
message = entry.message
Expand Down Expand Up @@ -169,10 +197,12 @@ struct LogRow: View, Identifiable {
}

struct LogTableRowPreview: PreviewProvider {
@State static public var sj: String = "11.0"

static var previews: some View {
VStack {
LogRow(entry: Entry(timestamp: "2023-01-01 19:48", job: "88888", message: "Hello, world"), index: 0, colour: Theme.rowColour)
LogRow(entry: Entry(timestamp: "2023-01-01 19:49", job: "11", message: "Hello, world"), index: 1, colour: Theme.rowColour)
LogRow(entry: Entry(timestamp: "2023-01-01 19:48", job: "88888", message: "Hello, world"), index: 0, colour: Theme.rowColour, selectedJob: $sj)
LogRow(entry: Entry(timestamp: "2023-01-01 19:49", job: "11", message: "Hello, world"), index: 1, colour: Theme.rowColour, selectedJob: $sj)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ struct LogRowActions: View, Identifiable {
}

struct LogTableRowActionsPreview: PreviewProvider {
@State static public var sj: String = "11.0"

static var previews: some View {
let entry = Entry(timestamp: "2023-01-01 19:48", job: "88888", message: "Hello, world")
let pView = LogRow(entry: entry, index: 0, colour: Color.red)
let pView = LogRow(entry: entry, index: 0, colour: Color.red, selectedJob: $sj)

LogRowActions(entry: entry, colour: Color.red, index: pView.index, isEditing: pView.$isEditing, isDeleting: pView.$isDeleting)
LogRowActions(entry: entry, colour: Color.red, index: pView.index, isEditing: pView.$isEditing, isDeleting: pView.$isDeleting)
Expand Down
4 changes: 3 additions & 1 deletion DLPrototype/Views/Today/LogTable/RowTypes/LogRowEmpty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ struct LogRowEmpty: View, Identifiable {
}

struct LogTableRowEmptyPreview: PreviewProvider {
@State static public var sj: String = "11.0"

static var previews: some View {
VStack {
LogRowEmpty(message: "Nothing to see here", index: 0, colour: Theme.rowColour)
LogRow(entry: Entry(timestamp: "2023-01-01 19:49", job: "11", message: "Hello, world"), index: 1, colour: Theme.rowColour)
LogRow(entry: Entry(timestamp: "2023-01-01 19:49", job: "11", message: "Hello, world"), index: 1, colour: Theme.rowColour, selectedJob: $sj)
}
}
}
2 changes: 1 addition & 1 deletion DLPrototype/Views/Today/Today.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct Today : View, Identifiable {

// MARK: Table view
var table: some View {
LogTable()
LogTable(selectedJob: $jobId)
.id(updater.ids["today.table"])
.environmentObject(updater)
}
Expand Down

0 comments on commit dac03e0

Please sign in to comment.