UNPKG

@fusedashlabs/ui9000-workspace

Version:

UI9000 workspace MCP. One tool, show_workspace, draws a chart from your table. Set TYPESAFE_API_KEY to let Jev choose the chart.

75 lines (74 loc) • 2.93 kB
/** * Gantt object for `<ui9000-gantt-chart>`: one row per task, with the day it * starts and the day it ends. Optional columns are the phase (one colour and * one collapsible row each), the tasks it waits for, an assignee, progress * and effort in hours. * * The widget reads its fields by position (`xAxe` task, start, end, * dependsOn, assignee; `yAxe` progress, effort; `groupBy` the phase), so a * column that is missing leaves an empty name in its place. Rows with no * readable start are left for the widget to drop; a table where none can be * read is not a schedule. */ import { ASSIGNEE_KEYS, DEPENDS_KEYS, EFFORT_KEYS, END_KEYS, PHASE_KEYS, PROGRESS_KEYS, START_KEYS, TASK_KEYS, pickKey, } from '../../profiler/schedule-columns.js'; export function ganttChartPayload(_fields, rows) { const columns = readColumns(rows); if (!columns) return null; const { task, start, end, phase, dependsOn, assignee, progress, effort } = columns; const used = [task, start, end, phase, dependsOn, assignee, progress, effort].filter((key) => !!key); const labelled = Object.fromEntries(used.map((key) => [key, { label: words(key) }])); return { chartType: 'ganttChart', name: 'gantt-chart', xAxe: trimEmpty([task, start, end, dependsOn ?? '', assignee ?? '']), yAxe: trimEmpty([progress ?? '', effort ?? '']), ...(phase ? { groupBy: [phase] } : {}), axisDetails: labelled, data: rows.map((row) => Object.fromEntries(used.map((key) => [key, row[key]]))), }; } function readColumns(rows) { if (rows.length === 0) return null; const keys = Object.keys(rows[0]); const task = pickKey(keys, TASK_KEYS); const start = pickKey(keys, START_KEYS); const end = pickKey(keys, END_KEYS); if (!task || !start || !end) return null; if (!rows.some((row) => readable(row[start]) && String(row[task] ?? '').trim())) return null; const taken = new Set([task, start, end]); const optional = (set) => { const key = pickKey(keys.filter((candidate) => !taken.has(candidate)), set); if (key) taken.add(key); return key; }; return { task, start, end, phase: optional(PHASE_KEYS), dependsOn: optional(DEPENDS_KEYS), assignee: optional(ASSIGNEE_KEYS), progress: optional(PROGRESS_KEYS), effort: optional(EFFORT_KEYS), }; } function readable(value) { if (value === null || value === undefined || value === '') return false; return Number.isFinite(new Date(value).getTime()); } function trimEmpty(list) { const out = [...list]; while (out.length && out[out.length - 1] === '') out.pop(); return out; } function words(key) { const spaced = key.replace(/[_-]+/g, ' ').trim(); return spaced ? spaced.charAt(0).toUpperCase() + spaced.slice(1) : key; }