feat: default workflow batch filters to latest batch

This commit is contained in:
chengma
2026-07-08 10:30:30 +08:00
parent c64f947f2f
commit 530ef2009f
6 changed files with 108 additions and 12 deletions
+9 -3
View File
@@ -376,14 +376,20 @@ class ApplyTab(QWidget):
)
def _populate_batch_filter(self, batches, selected_batch):
previous = selected_batch if selected_batch in {batch.id for batch in batches} else None
had_previous_items = self.batch_filter.count() > 0
self.batch_filter.blockSignals(True)
self.batch_filter.clear()
self.batch_filter.addItem("全部批次", None)
for batch in batches:
self.batch_filter.addItem(self._batch_label(batch), batch.id)
index = self.batch_filter.findData(previous)
self.batch_filter.setCurrentIndex(index if index >= 0 else 0)
self.batch_filter.setCurrentIndex(
_batch_filter_current_index(
self.batch_filter,
batches,
selected_batch,
had_previous_items,
)
)
self.batch_filter.blockSignals(False)
def _populate_shop_filter(self, tasks, account_rows, selected_shop):
+9 -4
View File
@@ -375,15 +375,20 @@ class CollectTab(QWidget):
self._update_delete_batch_button()
def _populate_batch_filter(self, batches, selected_batch):
batch_ids = {batch.id for batch in batches}
previous = selected_batch if selected_batch in batch_ids else None
had_previous_items = self.batch_filter.count() > 0
self.batch_filter.blockSignals(True)
self.batch_filter.clear()
self.batch_filter.addItem("全部批次", None)
for batch in batches:
self.batch_filter.addItem(self._batch_label(batch), batch.id)
index = self.batch_filter.findData(previous)
self.batch_filter.setCurrentIndex(index if index >= 0 else 0)
self.batch_filter.setCurrentIndex(
_batch_filter_current_index(
self.batch_filter,
batches,
selected_batch,
had_previous_items,
)
)
self.batch_filter.blockSignals(False)
def _batch_label(self, batch):
+9 -3
View File
@@ -1000,14 +1000,20 @@ class GenerateTab(QWidget):
_set_empty_state(self.empty_state_card, self.empty_state_label, self.empty_state_button)
def _populate_batch_filter(self, batches, selected_batch):
previous = selected_batch if selected_batch in {batch.id for batch in batches} else None
had_previous_items = self.batch_filter.count() > 0
self.batch_filter.blockSignals(True)
self.batch_filter.clear()
self.batch_filter.addItem("全部批次", None)
for batch in batches:
self.batch_filter.addItem(self._batch_label(batch), batch.id)
index = self.batch_filter.findData(previous)
self.batch_filter.setCurrentIndex(index if index >= 0 else 0)
self.batch_filter.setCurrentIndex(
_batch_filter_current_index(
self.batch_filter,
batches,
selected_batch,
had_previous_items,
)
)
self.batch_filter.blockSignals(False)
def _populate_shop_filter(self, tasks, account_rows, selected_shop):
+13
View File
@@ -405,6 +405,19 @@ def _set_batch_progress_overview(label, tasks):
label.setText(_format_batch_progress(summary) if active else "")
def _batch_filter_current_index(combo, batches, selected_batch, had_previous_items):
batch_ids = {batch.id for batch in batches}
if selected_batch in batch_ids:
index = combo.findData(selected_batch)
if index >= 0:
return index
if selected_batch is None and had_previous_items:
index = combo.findData(None)
if index >= 0:
return index
return 1 if batches else 0
def _database_path(db_path=None, config=None) -> str:
return db_path or appconfig.db_path(config)