mirror of
https://github.com/kean/Pulse.git
synced 2026-04-30 21:02:27 +00:00
Remove ConsoleMessageCellViewModel
This commit is contained in:
@@ -239,7 +239,6 @@
|
||||
0CF0D67C296F189600EED9D4 /* ConsoleView-macos.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CF0D5FD296F189600EED9D4 /* ConsoleView-macos.swift */; };
|
||||
0CF0D67D296F189600EED9D4 /* ConsoleEntityCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CF0D5FF296F189600EED9D4 /* ConsoleEntityCell.swift */; };
|
||||
0CF0D67F296F189600EED9D4 /* ConsoleContextMenu-ios.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CF0D601296F189600EED9D4 /* ConsoleContextMenu-ios.swift */; };
|
||||
0CF0D680296F189600EED9D4 /* ConsoleMessageCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CF0D602296F189600EED9D4 /* ConsoleMessageCellViewModel.swift */; };
|
||||
0CF0D686296F189600EED9D4 /* ConsoleMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CF0D608296F189600EED9D4 /* ConsoleMessageCell.swift */; };
|
||||
0CF0D687296F189600EED9D4 /* ConsoleTaskCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CF0D609296F189600EED9D4 /* ConsoleTaskCell.swift */; };
|
||||
0CF0D688296F189600EED9D4 /* ConsoleEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CF0D60A296F189600EED9D4 /* ConsoleEnvironment.swift */; };
|
||||
@@ -693,7 +692,6 @@
|
||||
0CF0D5FD296F189600EED9D4 /* ConsoleView-macos.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConsoleView-macos.swift"; sourceTree = "<group>"; };
|
||||
0CF0D5FF296F189600EED9D4 /* ConsoleEntityCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsoleEntityCell.swift; sourceTree = "<group>"; };
|
||||
0CF0D601296F189600EED9D4 /* ConsoleContextMenu-ios.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConsoleContextMenu-ios.swift"; sourceTree = "<group>"; };
|
||||
0CF0D602296F189600EED9D4 /* ConsoleMessageCellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsoleMessageCellViewModel.swift; sourceTree = "<group>"; };
|
||||
0CF0D608296F189600EED9D4 /* ConsoleMessageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsoleMessageCell.swift; sourceTree = "<group>"; };
|
||||
0CF0D609296F189600EED9D4 /* ConsoleTaskCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsoleTaskCell.swift; sourceTree = "<group>"; };
|
||||
0CF0D60A296F189600EED9D4 /* ConsoleEnvironment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsoleEnvironment.swift; sourceTree = "<group>"; };
|
||||
@@ -1402,7 +1400,6 @@
|
||||
0CF0D5FF296F189600EED9D4 /* ConsoleEntityCell.swift */,
|
||||
0C31FFB8298211AF002A7D64 /* ConsoleEntityDetailsView.swift */,
|
||||
0CF0D608296F189600EED9D4 /* ConsoleMessageCell.swift */,
|
||||
0CF0D602296F189600EED9D4 /* ConsoleMessageCellViewModel.swift */,
|
||||
0CF0D609296F189600EED9D4 /* ConsoleTaskCell.swift */,
|
||||
0CE45E0B2977813400249C5D /* ConsoleToolbarView.swift */,
|
||||
0CB345A5298DEEA6009428B2 /* ConsoleInspectorsView.swift */,
|
||||
@@ -2085,7 +2082,6 @@
|
||||
0CA32DE729D5E028001712E8 /* NSAttributedString+Extensions.swift in Sources */,
|
||||
0CF0D60F296F189600EED9D4 /* UIKit+Extensions.swift in Sources */,
|
||||
0CF0D610296F189600EED9D4 /* SpinnerView.swift in Sources */,
|
||||
0CF0D680296F189600EED9D4 /* ConsoleMessageCellViewModel.swift in Sources */,
|
||||
0CF0D639296F189600EED9D4 /* PinButton.swift in Sources */,
|
||||
0CB17F1A2978ABBA004E33F4 /* ManagedObjectsCountObserver.swift in Sources */,
|
||||
0CF0D644296F189600EED9D4 /* ConsoleSearchInlinePickerMenu.swift in Sources */,
|
||||
|
||||
@@ -33,15 +33,15 @@ private struct _ConsoleMessageCell: View {
|
||||
|
||||
var body: some View {
|
||||
#if os(iOS)
|
||||
let cell = ConsoleMessageCell(viewModel: .init(message: message), isDisclosureNeeded: true)
|
||||
let cell = ConsoleMessageCell(message: message, isDisclosureNeeded: true)
|
||||
.background(NavigationLink("", destination: ConsoleMessageDetailsView(message: message)).opacity(0))
|
||||
#elseif os(macOS)
|
||||
let cell = ConsoleMessageCell(viewModel: .init(message: message))
|
||||
let cell = ConsoleMessageCell(message: message)
|
||||
.tag(ConsoleSelectedItem.entity(message.objectID))
|
||||
#else
|
||||
// `id` is a workaround for macOS (needs to be fixed)
|
||||
let cell = NavigationLink(destination: ConsoleMessageDetailsView(message: message)) {
|
||||
ConsoleMessageCell(viewModel: .init(message: message))
|
||||
ConsoleMessageCell(message: message)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import CoreData
|
||||
import Combine
|
||||
|
||||
struct ConsoleMessageCell: View {
|
||||
let viewModel: ConsoleMessageCellViewModel
|
||||
let message: LoggerMessageEntity
|
||||
var isDisclosureNeeded = false
|
||||
|
||||
var body: some View {
|
||||
@@ -18,9 +18,9 @@ struct ConsoleMessageCell: View {
|
||||
} else {
|
||||
header
|
||||
}
|
||||
Text(viewModel.preprocessedText)
|
||||
Text(message.text)
|
||||
.font(ConsoleConstants.fontBody)
|
||||
.foregroundColor(.textColor(for: viewModel.message.logLevel))
|
||||
.foregroundColor(.textColor(for: message.logLevel))
|
||||
.lineLimit(ConsoleSettings.shared.lineLimit)
|
||||
}
|
||||
#if os(macOS)
|
||||
@@ -37,7 +37,7 @@ struct ConsoleMessageCell: View {
|
||||
@ViewBuilder
|
||||
private var header: some View {
|
||||
HStack {
|
||||
Text(viewModel.message.logLevel.name.uppercased())
|
||||
Text(message.logLevel.name.uppercased())
|
||||
.lineLimit(1)
|
||||
#if os(iOS)
|
||||
.font(ConsoleConstants.fontInfo.weight(.medium))
|
||||
@@ -47,10 +47,10 @@ struct ConsoleMessageCell: View {
|
||||
.foregroundColor(titleColor)
|
||||
Spacer()
|
||||
#if os(macOS) || os(iOS)
|
||||
PinView(message: viewModel.message)
|
||||
PinView(message: message)
|
||||
#endif
|
||||
HStack(spacing: 3) {
|
||||
Text(viewModel.time)
|
||||
Text(ConsoleMessageCell.timeFormatter.string(from: message.createdAt))
|
||||
.lineLimit(1)
|
||||
.font(ConsoleConstants.fontInfo)
|
||||
.foregroundColor(.secondary)
|
||||
@@ -63,8 +63,15 @@ struct ConsoleMessageCell: View {
|
||||
}
|
||||
|
||||
var titleColor: Color {
|
||||
viewModel.message.logLevel >= .warning ? .textColor(for: viewModel.message.logLevel) : .secondary
|
||||
message.logLevel >= .warning ? .textColor(for: message.logLevel) : .secondary
|
||||
}
|
||||
|
||||
static let timeFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.locale = Locale(identifier: "en_US")
|
||||
formatter.dateFormat = "HH:mm:ss.SSS"
|
||||
return formatter
|
||||
}()
|
||||
}
|
||||
|
||||
struct ListDisclosureIndicator: View {
|
||||
@@ -78,10 +85,32 @@ struct ListDisclosureIndicator: View {
|
||||
}
|
||||
}
|
||||
|
||||
extension UXColor {
|
||||
static func textColor(for level: LoggerStore.Level) -> UXColor {
|
||||
switch level {
|
||||
case .trace: return .secondaryLabel
|
||||
case .debug, .info: return .label
|
||||
case .notice, .warning: return .systemOrange
|
||||
case .error, .critical: return .red
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Color {
|
||||
static func textColor(for level: LoggerStore.Level) -> Color {
|
||||
switch level {
|
||||
case .trace: return .secondary
|
||||
case .debug, .info: return .primary
|
||||
case .notice, .warning: return .orange
|
||||
case .error, .critical: return .red
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct ConsoleMessageCell_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ConsoleMessageCell(viewModel: .init(message: (try! LoggerStore.mock.allMessages())[0]))
|
||||
ConsoleMessageCell(message: try! LoggerStore.mock.allMessages()[0])
|
||||
.padding()
|
||||
.previewLayout(.sizeThatFits)
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2020–2023 Alexander Grebenyuk (github.com/kean).
|
||||
|
||||
import SwiftUI
|
||||
import Pulse
|
||||
import CoreData
|
||||
import Combine
|
||||
|
||||
final class ConsoleMessageCellViewModel {
|
||||
let message: LoggerMessageEntity
|
||||
|
||||
private let searchCriteriaViewModel: ConsoleSearchCriteriaViewModel?
|
||||
|
||||
// TODO: Trim whitespaces and remove newlines?
|
||||
var preprocessedText: String { message.text }
|
||||
|
||||
private(set) lazy var time = ConsoleMessageCellViewModel.timeFormatter.string(from: message.createdAt)
|
||||
|
||||
static let timeFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.locale = Locale(identifier: "en_US")
|
||||
formatter.dateFormat = "HH:mm:ss.SSS"
|
||||
return formatter
|
||||
}()
|
||||
|
||||
init(message: LoggerMessageEntity, searchCriteriaViewModel: ConsoleSearchCriteriaViewModel? = nil) {
|
||||
self.message = message
|
||||
self.searchCriteriaViewModel = searchCriteriaViewModel
|
||||
}
|
||||
}
|
||||
|
||||
extension UXColor {
|
||||
static func textColor(for level: LoggerStore.Level) -> UXColor {
|
||||
switch level {
|
||||
case .trace: return .secondaryLabel
|
||||
case .debug, .info: return .label
|
||||
case .notice, .warning: return .systemOrange
|
||||
case .error, .critical: return .red
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Color {
|
||||
static func textColor(for level: LoggerStore.Level) -> Color {
|
||||
switch level {
|
||||
case .trace: return .secondary
|
||||
case .debug, .info: return .primary
|
||||
case .notice, .warning: return .orange
|
||||
case .error, .critical: return .red
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ struct ConsoleTaskCell: View {
|
||||
}
|
||||
|
||||
private var time: some View {
|
||||
Text(ConsoleMessageCellViewModel.timeFormatter.string(from: task.createdAt))
|
||||
Text(ConsoleMessageCell.timeFormatter.string(from: task.createdAt))
|
||||
.lineLimit(1)
|
||||
.font(ConsoleConstants.fontInfo)
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
@@ -92,7 +92,7 @@ enum ConsoleFormatter {
|
||||
// MARK: Individual Components
|
||||
|
||||
static func time(for date: Date) -> String {
|
||||
ConsoleMessageCellViewModel.timeFormatter.string(from: date)
|
||||
ConsoleMessageCell.timeFormatter.string(from: date)
|
||||
}
|
||||
|
||||
static func status(for task: NetworkTaskEntity) -> String {
|
||||
|
||||
Reference in New Issue
Block a user