feat(workbench): add manual task refresh
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
ChevronRight,
|
||||
ClipboardList,
|
||||
History,
|
||||
RefreshCw,
|
||||
X,
|
||||
XCircle
|
||||
} from "lucide-react";
|
||||
@@ -100,6 +101,7 @@ type ScheduledConditionFeedProps = {
|
||||
onTaskReconcile?: (taskId: string, actionId: string, expectedVersion: number) => Promise<unknown>;
|
||||
onLoadTaskEvidenceSnapshot?: (taskId: string, evidenceId: string) => Promise<OperationalTaskDataSnapshot>;
|
||||
onTaskRefresh?: () => void;
|
||||
onRefresh?: () => void | Promise<void>;
|
||||
onCreateSchedule?: (input: ScheduleCreateRequest) => Promise<unknown>;
|
||||
};
|
||||
|
||||
@@ -133,6 +135,7 @@ export function ScheduledConditionFeed({
|
||||
onTaskReconcile,
|
||||
onLoadTaskEvidenceSnapshot,
|
||||
onTaskRefresh,
|
||||
onRefresh,
|
||||
onCreateSchedule
|
||||
}: ScheduledConditionFeedProps) {
|
||||
const [uncontrolledExpanded, setUncontrolledExpanded] = useState(false);
|
||||
@@ -152,6 +155,7 @@ export function ScheduledConditionFeed({
|
||||
const [scheduleNextRunAt, setScheduleNextRunAt] = useState(() => formatLocalDateTimeInput(new Date(Date.now() + 15 * 60_000)));
|
||||
const [scheduleSubmitting, setScheduleSubmitting] = useState(false);
|
||||
const [scheduleError, setScheduleError] = useState<string | null>(null);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const mobileSheet = presentation === "mobile-sheet";
|
||||
const desktopDock = presentation === "desktop-dock";
|
||||
const compactPresentation = mobileSheet || desktopDock;
|
||||
@@ -330,6 +334,23 @@ export function ScheduledConditionFeed({
|
||||
} finally { setScheduleSubmitting(false); }
|
||||
}
|
||||
|
||||
async function handleRefresh() {
|
||||
if (!onRefresh || refreshing) return;
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await onRefresh();
|
||||
} catch (error) {
|
||||
showMapNotice({
|
||||
id: "scheduled-condition-refresh",
|
||||
tone: "error",
|
||||
title: "工况任务刷新失败",
|
||||
message: error instanceof Error ? error.message : "暂时无法重新获取工况任务。"
|
||||
});
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
}
|
||||
|
||||
function handleSelectTimelineCondition(conditionId: string) {
|
||||
updateSelectedConditionId(conditionId);
|
||||
if (!expanded) {
|
||||
@@ -449,6 +470,22 @@ export function ScheduledConditionFeed({
|
||||
<CalendarPlus size={17} aria-hidden="true" />
|
||||
</button>
|
||||
) : null}
|
||||
{onRefresh ? (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={refreshing ? "正在刷新工况任务" : "刷新工况任务"}
|
||||
title={refreshing ? "正在刷新" : "刷新工况任务"}
|
||||
disabled={refreshing}
|
||||
onClick={() => void handleRefresh()}
|
||||
className="grid h-10 w-10 shrink-0 place-items-center rounded-lg text-slate-500 transition-colors active:scale-95 disabled:cursor-wait disabled:text-blue-600 [@media(hover:hover)]:hover:bg-blue-50 [@media(hover:hover)]:hover:text-blue-700"
|
||||
>
|
||||
<RefreshCw
|
||||
size={17}
|
||||
aria-hidden="true"
|
||||
className={cn(refreshing && "animate-spin motion-reduce:animate-none")}
|
||||
/>
|
||||
</button>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={expanded}
|
||||
|
||||
Reference in New Issue
Block a user