Files
pipelines/app/lib/features/changes/domain/change_kind.dart
T

31 lines
1.2 KiB
Dart

/// The three recorded file-change kinds plus a safe fallback for future server
/// values. Ported from `web/src/changes.js` (and the Android client's
/// `ui/changes/RunChanges.kt`) so the Flutter client says the same words.
enum ChangeKind { added, modified, deleted, other }
/// Maps a server kind token to a [ChangeKind]. The token is trimmed and
/// lowercased; an unknown or blank token stays [ChangeKind.other] rather than
/// being guessed, so a future server value is shown read-only instead of
/// mislabelled.
ChangeKind changeKind(dynamic kind) =>
switch ('${kind ?? ''}'.trim().toLowerCase()) {
'added' => ChangeKind.added,
'modified' => ChangeKind.modified,
'deleted' => ChangeKind.deleted,
_ => ChangeKind.other,
};
/// The word a file's kind is named by in the list and the diff header.
String changeKindLabel(ChangeKind kind) => switch (kind) {
ChangeKind.added => 'added',
ChangeKind.modified => 'modified',
ChangeKind.deleted => 'deleted',
ChangeKind.other => 'changed',
};
/// The kind word as the viewer header shows it, first letter capitalised.
String changeKindTitle(ChangeKind kind) {
final label = changeKindLabel(kind);
return label.isEmpty ? label : label[0].toUpperCase() + label.substring(1);
}