전역 구조 리팩터링 및 테스트 확장

This commit is contained in:
JiWoong Sul
2025-09-29 01:51:47 +09:00
parent c00c0c9ab2
commit fef7108479
70 changed files with 7709 additions and 3185 deletions

View File

@@ -5,6 +5,7 @@ import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:superport_v2/core/constants/app_sections.dart';
import 'package:superport_v2/widgets/app_layout.dart';
import 'package:superport_v2/widgets/components/filter_bar.dart';
import 'package:superport_v2/widgets/components/superport_dialog.dart';
import '../../../../../core/config/environment.dart';
import '../../../../../widgets/spec_page.dart';
@@ -130,7 +131,8 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
? false
: (result.page * result.pageSize) < result.total;
final showReset = _searchController.text.isNotEmpty ||
final showReset =
_searchController.text.isNotEmpty ||
_controller.defaultFilter != GroupDefaultFilter.all ||
_controller.statusFilter != GroupStatusFilter.all;
@@ -145,12 +147,35 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
actions: [
ShadButton(
leading: const Icon(LucideIcons.plus, size: 16),
onPressed:
_controller.isSubmitting ? null : () => _openGroupForm(context),
onPressed: _controller.isSubmitting
? null
: () => _openGroupForm(context),
child: const Text('신규 등록'),
),
],
toolbar: FilterBar(
actions: [
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateQuery('');
_controller.updateDefaultFilter(
GroupDefaultFilter.all,
);
_controller.updateStatusFilter(GroupStatusFilter.all);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
children: [
SizedBox(
width: 260,
@@ -206,28 +231,6 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
.toList(),
),
),
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateQuery('');
_controller.updateDefaultFilter(
GroupDefaultFilter.all,
);
_controller.updateStatusFilter(
GroupStatusFilter.all,
);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
),
child: ShadCard(
@@ -272,26 +275,22 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
child: Center(child: CircularProgressIndicator()),
)
: groups.isEmpty
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 그룹이 없습니다.',
style: theme.textTheme.muted,
),
)
: _GroupTable(
groups: groups,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
? null
: (group) => _openGroupForm(context, group: group),
onDelete: _controller.isSubmitting
? null
: _confirmDelete,
onRestore: _controller.isSubmitting
? null
: _restoreGroup,
),
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 그룹이 없습니다.',
style: theme.textTheme.muted,
),
)
: _GroupTable(
groups: groups,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
? null
: (group) => _openGroupForm(context, group: group),
onDelete: _controller.isSubmitting ? null : _confirmDelete,
onRestore: _controller.isSubmitting ? null : _restoreGroup,
),
),
);
},
@@ -352,199 +351,185 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
final saving = ValueNotifier<bool>(false);
final nameError = ValueNotifier<String?>(null);
await showDialog<bool>(
await SuperportDialog.show<void>(
context: context,
builder: (dialogContext) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
final navigator = Navigator.of(dialogContext);
return Dialog(
insetPadding: const EdgeInsets.all(24),
clipBehavior: Clip.antiAlias,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 540),
child: ShadCard(
title: Text(
isEdit ? '그룹 수정' : '그룹 등록',
style: theme.textTheme.h3,
),
description: Text(
'그룹 정보를 ${isEdit ? '수정' : '입력'}하세요.',
style: theme.textTheme.muted,
),
footer: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (_, isSaving, __) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ShadButton.ghost(
onPressed: isSaving ? null : () => navigator.pop(false),
child: const Text('취소'),
),
const SizedBox(width: 12),
ShadButton(
onPressed: isSaving
? null
: () async {
final name = nameController.text.trim();
final description = descriptionController.text
.trim();
final note = noteController.text.trim();
dialog: SuperportDialog(
title: isEdit ? '그룹 수정' : '그룹 등록',
description: '그룹 정보를 ${isEdit ? '수정' : '입력'}하세요.',
constraints: const BoxConstraints(maxWidth: 540),
actions: [
ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
return ShadButton.ghost(
onPressed: isSaving
? null
: () => Navigator.of(dialogContext).pop(),
child: const Text('취소'),
);
},
),
ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
return ShadButton(
onPressed: isSaving
? null
: () async {
final name = nameController.text.trim();
final description = descriptionController.text.trim();
final note = noteController.text.trim();
nameError.value = name.isEmpty
? '그룹명을 입력하세요.'
: null;
nameError.value = name.isEmpty ? '그룹명을 입력하세요.' : null;
if (nameError.value != null) {
return;
}
if (nameError.value != null) {
return;
}
saving.value = true;
final input = GroupInput(
groupName: name,
description: description.isEmpty
? null
: description,
isDefault: isDefaultNotifier.value,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final response = isEdit
? await _controller.update(groupId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
saving.value = true;
final input = GroupInput(
groupName: name,
description: description.isEmpty ? null : description,
isDefault: isDefaultNotifier.value,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final navigator = Navigator.of(dialogContext);
final response = isEdit
? await _controller.update(groupId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(isEdit ? '그룹을 수정했습니다.' : '그룹을 등록했습니다.');
}
navigator.pop();
}
},
child: Text(isEdit ? '저장' : '등록'),
);
},
),
],
child: StatefulBuilder(
builder: (dialogContext, _) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
return SizedBox(
width: double.infinity,
child: SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: nameError,
builder: (_, errorText, __) {
return _FormField(
label: '그룹명',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
controller: nameController,
readOnly: isEdit,
onChanged: (_) {
if (nameController.text.trim().isNotEmpty) {
nameError.value = null;
}
if (mounted) {
_showSnack(
isEdit ? '그룹을 수정했습니다.' : '그룹을 등록했습니다.',
);
}
navigator.pop(true);
}
},
child: Text(isEdit ? '저장' : '등록'),
),
],
);
},
),
child: SizedBox(
width: double.infinity,
child: SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: nameError,
builder: (_, errorText, __) {
return _FormField(
label: '그룹명',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
controller: nameController,
readOnly: isEdit,
onChanged: (_) {
if (nameController.text.trim().isNotEmpty) {
nameError.value = null;
}
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '설명',
child: ShadTextarea(controller: descriptionController),
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isDefaultNotifier,
builder: (_, value, __) {
return _FormField(
label: '기본여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: saving.value
? null
: (next) =>
isDefaultNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '기본 그룹' : '일반 그룹'),
],
),
);
},
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '설명',
child: ShadTextarea(controller: descriptionController),
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isDefaultNotifier,
builder: (_, value, __) {
return _FormField(
label: '기본여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: saving.value
? null
: (next) => isDefaultNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '기본 그룹' : '일반 그룹'),
],
),
);
},
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isActiveNotifier,
builder: (_, value, __) {
return _FormField(
label: '사용여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: saving.value
? null
: (next) => isActiveNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '사용' : '미사용'),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (existingGroup != null) ...[
const SizedBox(height: 20),
Text(
'생성일시: ${_formatDateTime(existingGroup.createdAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isActiveNotifier,
builder: (_, value, __) {
return _FormField(
label: '사용여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: saving.value
? null
: (next) => isActiveNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '사용' : '미사용'),
],
),
);
},
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(existingGroup.updatedAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (isEdit) ...[
const SizedBox(height: 20),
Text(
'생성일시: ${_formatDateTime(existingGroup.createdAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(existingGroup.updatedAt)}',
style: theme.textTheme.small,
),
],
],
),
],
),
),
),
),
);
},
);
},
),
),
);
nameController.dispose();