mirror of
https://github.com/taskgenius/taskgenius-plugin.git
synced 2026-07-22 06:40:25 +00:00
fix(bulk-ops): fix project list not showing in bulk move menu
Replace unreliable taskStore access with standardized getCachedData() to properly fetch available projects from dataflow API, settings, and path mappings. Also improve ConfirmModal UX by adjusting button order (Cancel left, Confirm right) and removing CTA style from cancel button.
This commit is contained in:
parent
9e3e95d2fd
commit
0f3726d7d2
5 changed files with 34 additions and 45 deletions
|
|
@ -15,17 +15,18 @@ import type { UpdateTaskArgs } from "@/dataflow/api/WriteAPI";
|
|||
import { BulkDatePickerModal } from "@/components/ui/date-picker/BulkDatePickerModal";
|
||||
import { BulkDateOffsetModal } from "@/components/ui/date-picker/BulkDateOffsetModal";
|
||||
import { addDays } from "date-fns";
|
||||
import { getCachedData } from "@/components/ui/inputs/AutoComplete";
|
||||
|
||||
/**
|
||||
* Create and show bulk operations menu
|
||||
*/
|
||||
export function showBulkOperationsMenu(
|
||||
export async function showBulkOperationsMenu(
|
||||
event: MouseEvent,
|
||||
app: App,
|
||||
plugin: TaskProgressBarPlugin,
|
||||
selectionManager: TaskSelectionManager,
|
||||
onOperationComplete: () => void,
|
||||
): void {
|
||||
): Promise<void> {
|
||||
const menu = new Menu();
|
||||
const selectedCount = selectionManager.getSelectedCount();
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ export function showBulkOperationsMenu(
|
|||
addBulkSetPriorityMenu(menu, plugin, selectionManager, onOperationComplete);
|
||||
|
||||
// Bulk move to project
|
||||
addBulkMoveToProjectMenu(
|
||||
await addBulkMoveToProjectMenu(
|
||||
menu,
|
||||
plugin,
|
||||
selectionManager,
|
||||
|
|
@ -337,20 +338,20 @@ function addBulkSetPriorityMenu(
|
|||
/**
|
||||
* Add bulk move to project submenu
|
||||
*/
|
||||
function addBulkMoveToProjectMenu(
|
||||
async function addBulkMoveToProjectMenu(
|
||||
menu: Menu,
|
||||
plugin: TaskProgressBarPlugin,
|
||||
selectionManager: TaskSelectionManager,
|
||||
onOperationComplete: () => void,
|
||||
): void {
|
||||
): Promise<void> {
|
||||
// Get all projects from cached data
|
||||
const projects = await getProjectList(plugin);
|
||||
|
||||
menu.addItem((item) => {
|
||||
item.setIcon("folder");
|
||||
item.setTitle(t("Bulk move to project"));
|
||||
const submenu = item.setSubmenu();
|
||||
|
||||
// Get all projects from settings
|
||||
const projects = getProjectList(plugin);
|
||||
|
||||
if (projects.length === 0) {
|
||||
submenu.addItem((subItem) => {
|
||||
subItem.setTitle(t("No projects available"));
|
||||
|
|
@ -410,9 +411,11 @@ function addBulkDeleteMenu(
|
|||
new ConfirmModal(plugin, {
|
||||
title: t("Confirm bulk delete"),
|
||||
message: t(
|
||||
"Are you sure you want to delete {count} tasks?",
|
||||
"Are you sure you want to delete {{count}} tasks?",
|
||||
{
|
||||
count: count.toString(),
|
||||
interpolation: {
|
||||
count: count.toString(),
|
||||
},
|
||||
},
|
||||
),
|
||||
confirmText: t("Delete"),
|
||||
|
|
@ -902,34 +905,17 @@ function showOperationResult(
|
|||
}
|
||||
|
||||
/**
|
||||
* Get list of all projects from dataflow orchestrator
|
||||
* Get list of all projects using cached data
|
||||
*/
|
||||
function getProjectList(plugin: TaskProgressBarPlugin): string[] {
|
||||
// Get projects from dataflow orchestrator
|
||||
const projects = new Set<string>();
|
||||
|
||||
// Try to access task data through dataflow orchestrator
|
||||
if (plugin.dataflowOrchestrator) {
|
||||
try {
|
||||
// Access the taskStore from dataflow orchestrator
|
||||
const taskStore = (plugin.dataflowOrchestrator as any).taskStore;
|
||||
if (taskStore && taskStore.getAllTasks) {
|
||||
const allTasks = taskStore.getAllTasks();
|
||||
for (const task of allTasks) {
|
||||
if (task.metadata?.project) {
|
||||
projects.add(task.metadata.project);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Could not access tasks for project list:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Return common project names if no tasks found
|
||||
if (projects.size === 0) {
|
||||
async function getProjectList(
|
||||
plugin: TaskProgressBarPlugin,
|
||||
): Promise<string[]> {
|
||||
try {
|
||||
// Load fresh data to ensure newly added projects appear
|
||||
const cachedData = await getCachedData(plugin, true);
|
||||
return cachedData.projects;
|
||||
} catch (error) {
|
||||
console.warn("Could not get projects from cached data:", error);
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.from(projects).sort();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,7 +198,9 @@ export class TaskListItemComponent extends Component {
|
|||
// Refresh view after operation
|
||||
// The parent view should handle this via task updates
|
||||
},
|
||||
);
|
||||
).catch((error) => {
|
||||
console.error("Failed to show bulk operations menu:", error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,7 +209,9 @@ export class TaskTreeItemComponent extends Component {
|
|||
() => {
|
||||
// Optionally refresh the view after bulk operation
|
||||
},
|
||||
);
|
||||
).catch((error) => {
|
||||
console.error("Failed to show bulk operations menu:", error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ let globalCache: GlobalAutoCompleteCache | null = null;
|
|||
const CACHE_DURATION = 30000; // 30 seconds
|
||||
|
||||
// Helper function to get cached data
|
||||
async function getCachedData(
|
||||
export async function getCachedData(
|
||||
plugin: TaskProgressBarPlugin,
|
||||
forceRefresh: boolean = false
|
||||
): Promise<GlobalAutoCompleteCache> {
|
||||
|
|
|
|||
|
|
@ -42,18 +42,17 @@ export class ConfirmModal extends Modal {
|
|||
});
|
||||
|
||||
new ButtonComponent(buttonsContainer)
|
||||
.setButtonText(this.params.confirmText)
|
||||
.setCta()
|
||||
.setButtonText(this.params.cancelText)
|
||||
.onClick(() => {
|
||||
this.params.onConfirm(true);
|
||||
this.params.onConfirm(false);
|
||||
this.close();
|
||||
});
|
||||
|
||||
new ButtonComponent(buttonsContainer)
|
||||
.setButtonText(this.params.cancelText)
|
||||
.setButtonText(this.params.confirmText)
|
||||
.setCta()
|
||||
.onClick(() => {
|
||||
this.params.onConfirm(false);
|
||||
this.params.onConfirm(true);
|
||||
this.close();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue