refactor(macos): simplify skills list rows

This commit is contained in:
Peter Steinberger
2025-12-20 21:12:41 +01:00
parent 8fe0b72a04
commit 91d4c24078

View File

@@ -91,13 +91,11 @@ struct SkillsSettings: View {
envKey: envKey, envKey: envKey,
isPrimary: isPrimary) isPrimary: isPrimary)
}) })
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
} }
if !self.model.skills.isEmpty, self.filteredSkills.isEmpty { if !self.model.skills.isEmpty, self.filteredSkills.isEmpty {
Text("No skills match this filter.") Text("No skills match this filter.")
.font(.callout) .font(.callout)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
} }
} }
.listStyle(.inset) .listStyle(.inset)
@@ -185,11 +183,8 @@ private struct SkillRow: View {
.font(.title2) .font(.title2)
VStack(alignment: .leading, spacing: 6) { VStack(alignment: .leading, spacing: 6) {
HStack(alignment: .firstTextBaseline, spacing: 8) { Text(self.skill.name)
Text(self.skill.name) .font(.headline)
.font(.headline)
self.statusBadge
}
Text(self.skill.description) Text(self.skill.description)
.font(.subheadline) .font(.subheadline)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
@@ -200,7 +195,7 @@ private struct SkillRow: View {
Text("Disabled in config") Text("Disabled in config")
.font(.caption) .font(.caption)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
} else if !self.skill.eligible { } else if !self.requirementsMet, self.shouldShowMissingSummary {
self.missingSummary self.missingSummary
} }
@@ -235,22 +230,6 @@ private struct SkillRow: View {
} }
} }
private var statusBadge: some View {
Group {
if self.skill.disabled {
Label("Disabled", systemImage: "slash.circle")
.foregroundStyle(.secondary)
} else if self.skill.eligible {
Label("Ready", systemImage: "checkmark.circle.fill")
.foregroundStyle(.green)
} else {
Label("Needs setup", systemImage: "exclamationmark.triangle")
.foregroundStyle(.orange)
}
}
.font(.caption)
}
private var metaRow: some View { private var metaRow: some View {
HStack(spacing: 10) { HStack(spacing: 10) {
SkillTag(text: self.sourceLabel) SkillTag(text: self.sourceLabel)
@@ -282,7 +261,7 @@ private struct SkillRow: View {
@ViewBuilder @ViewBuilder
private var missingSummary: some View { private var missingSummary: some View {
VStack(alignment: .leading, spacing: 4) { VStack(alignment: .leading, spacing: 4) {
if !self.missingBins.isEmpty { if self.shouldShowMissingBins {
Text("Missing binaries: \(self.missingBins.joined(separator: ", "))") Text("Missing binaries: \(self.missingBins.joined(separator: ", "))")
.font(.caption) .font(.caption)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
@@ -336,7 +315,7 @@ private struct SkillRow: View {
VStack(alignment: .trailing, spacing: 8) { VStack(alignment: .trailing, spacing: 8) {
if !self.installOptions.isEmpty { if !self.installOptions.isEmpty {
ForEach(self.installOptions) { option in ForEach(self.installOptions) { option in
Button(option.label) { self.onInstall(option) } Button("Install") { self.onInstall(option) }
.buttonStyle(.borderedProminent) .buttonStyle(.borderedProminent)
.disabled(self.isBusy) .disabled(self.isBusy)
} }
@@ -344,7 +323,7 @@ private struct SkillRow: View {
Toggle("", isOn: self.enabledBinding) Toggle("", isOn: self.enabledBinding)
.toggleStyle(.switch) .toggleStyle(.switch)
.labelsHidden() .labelsHidden()
.disabled(self.isBusy) .disabled(self.isBusy || !self.requirementsMet)
} }
if self.isBusy { if self.isBusy {
@@ -363,6 +342,20 @@ private struct SkillRow: View {
} }
} }
private var requirementsMet: Bool {
self.missingBins.isEmpty && self.missingEnv.isEmpty && self.missingConfig.isEmpty
}
private var shouldShowMissingBins: Bool {
!self.missingBins.isEmpty && self.installOptions.isEmpty
}
private var shouldShowMissingSummary: Bool {
self.shouldShowMissingBins ||
!self.missingEnv.isEmpty ||
!self.missingConfig.isEmpty
}
private func formatConfigValue(_ value: AnyCodable?) -> String { private func formatConfigValue(_ value: AnyCodable?) -> String {
guard let value else { return "" } guard let value else { return "" }
switch value.value { switch value.value {