Ajoute la base organisable par carnet (schéma, champs partagés, valeurs par note) avec activation guidée, tableau éditable, kanban et suppression de colonnes. Corrige le multiselect en vue tableau et enrichit sidebar, grille et i18n FR/EN. Inclut aussi les améliorations flashcards SM-2, l'audit consentement IA et la robustesse du serveur MCP (config, validation, rate-limit, métriques). Co-authored-by: Cursor <cursoragent@cursor.com>
72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
import type { NotebookSchemaPayload } from '@/lib/structured-views/types'
|
|
|
|
export type BootstrapStructuredTarget = 'table' | 'kanban'
|
|
|
|
export type BootstrapStructuredLabels = {
|
|
statusName: string
|
|
statusOptions: string[]
|
|
}
|
|
|
|
export type BootstrapStructuredActions = {
|
|
getSchema: () => NotebookSchemaPayload | null
|
|
enableStructuredMode: () => Promise<NotebookSchemaPayload | null>
|
|
addProperty: (name: string, type: string, options?: string[]) => Promise<NotebookSchemaPayload | null>
|
|
setKanbanGroupProperty: (propertyId: string | null) => Promise<void>
|
|
}
|
|
|
|
function pickGroupProperty(schema: NotebookSchemaPayload, statusName: string) {
|
|
return (
|
|
schema.properties.find((p) => p.type === 'select' && p.name === statusName) ??
|
|
schema.properties.find((p) => p.type === 'select') ??
|
|
null
|
|
)
|
|
}
|
|
|
|
/** Active une base organisable avec champs par défaut (Statut) si nécessaire. */
|
|
export async function bootstrapStructuredNotebook(
|
|
target: BootstrapStructuredTarget,
|
|
labels: BootstrapStructuredLabels,
|
|
actions: BootstrapStructuredActions,
|
|
): Promise<NotebookSchemaPayload> {
|
|
let schema = actions.getSchema()
|
|
if (!schema) {
|
|
schema = await actions.enableStructuredMode()
|
|
}
|
|
if (!schema) {
|
|
throw new Error('enable_failed')
|
|
}
|
|
|
|
const selectProps = schema.properties.filter((p) => p.type === 'select')
|
|
const needsDefaultStatus =
|
|
target === 'kanban' ? selectProps.length === 0 : schema.properties.length === 0
|
|
|
|
if (needsDefaultStatus) {
|
|
schema =
|
|
(await actions.addProperty(labels.statusName, 'select', labels.statusOptions)) ?? schema
|
|
}
|
|
|
|
if (target === 'kanban') {
|
|
const groupProp = pickGroupProperty(schema, labels.statusName)
|
|
if (!groupProp) {
|
|
throw new Error('kanban_needs_select')
|
|
}
|
|
if (schema.viewSettings.kanbanGroupPropertyId !== groupProp.id) {
|
|
await actions.setKanbanGroupProperty(groupProp.id)
|
|
schema = {
|
|
...schema,
|
|
viewSettings: { ...schema.viewSettings, kanbanGroupPropertyId: groupProp.id },
|
|
}
|
|
}
|
|
}
|
|
|
|
return schema
|
|
}
|
|
|
|
/** Ajoute un champ Statut + colonnes kanban sur une base déjà active. */
|
|
export async function ensureKanbanStatusField(
|
|
labels: BootstrapStructuredLabels,
|
|
actions: BootstrapStructuredActions,
|
|
): Promise<NotebookSchemaPayload> {
|
|
return bootstrapStructuredNotebook('kanban', labels, actions)
|
|
}
|