|
| 1 | +import { Chip, cn } from '@sim/emcn' |
| 2 | +import { Plus } from '@sim/emcn/icons' |
| 3 | +import { EmptyState } from '@/components/empty-state/empty-state' |
| 4 | +import { EmptyStateDocsLink } from '@/app/workspace/[workspaceId]/components/resource/components/resource-empty-state/docs-link' |
| 5 | +import { HAIRLINE } from '@/app/workspace/[workspaceId]/components/resource/components/resource-empty-state/hairline' |
| 6 | +import { MASK_NO_REPEAT } from '@/app/workspace/[workspaceId]/components/resource/components/resource-empty-state/mask' |
| 7 | + |
| 8 | +const KNOWLEDGE_DOCS_URL = 'https://docs.sim.ai/knowledgebase' |
| 9 | + |
| 10 | +/** |
| 11 | + * Ruled text — see the `INK` note in `tables-empty-state.tsx` for why not the surface |
| 12 | + * ramp. The heading line takes the stronger mix so the sheet reads as a document |
| 13 | + * rather than as blank ruling. |
| 14 | + */ |
| 15 | +const INK = { |
| 16 | + heading: 'color-mix(in srgb, var(--text-secondary) 30%, transparent)', |
| 17 | + body: 'color-mix(in srgb, var(--text-secondary) 15%, transparent)', |
| 18 | +} as const |
| 19 | + |
| 20 | +/** Widths of the ruled body lines, in viewBox units. */ |
| 21 | +const BODY_LINES = [ |
| 22 | + { y: 84, width: 62 }, |
| 23 | + { y: 98, width: 54 }, |
| 24 | + { y: 112, width: 66 }, |
| 25 | +] as const |
| 26 | + |
| 27 | +/** |
| 28 | + * The front sheet, with the top-right corner turned back. |
| 29 | + * |
| 30 | + * The dog-ear is the one signifier no other graphic in the set uses — the folder is a |
| 31 | + * container, the knowledge mark is a shelf of volumes, and this has to read as the |
| 32 | + * pages inside one of them. |
| 33 | + */ |
| 34 | +const SHEET = [ |
| 35 | + 'M 58 34', |
| 36 | + 'H 128', |
| 37 | + 'L 148 54', |
| 38 | + 'V 140', |
| 39 | + 'Q 148 146 142 146', |
| 40 | + 'H 58', |
| 41 | + 'Q 52 146 52 140', |
| 42 | + 'V 40', |
| 43 | + 'Q 52 34 58 34', |
| 44 | + 'Z', |
| 45 | +].join(' ') |
| 46 | + |
| 47 | +/** The turned-back corner itself, drawn over the sheet so its two edges both read. */ |
| 48 | +const DOG_EAR = ['M 128 34', 'L 148 54', 'H 134', 'Q 128 54 128 48', 'Z'].join(' ') |
| 49 | + |
| 50 | +/** |
| 51 | + * Dissolves upward, the direction the stack recedes — the same call the folder makes. |
| 52 | + * The sheets behind are a repeating structure and cost nothing cropped, while the front |
| 53 | + * sheet stays crisp where the copy begins beneath it. |
| 54 | + */ |
| 55 | +const STACK_FADE = |
| 56 | + '[-webkit-mask-image:linear-gradient(to_top,#000_56%,transparent_100%)] [mask-image:linear-gradient(to_top,#000_56%,transparent_100%)]' |
| 57 | + |
| 58 | +/** |
| 59 | + * The artwork's own bounds, so the frame follows the drawing rather than a round number. |
| 60 | + * |
| 61 | + * The sheets are authored around the front sheet's origin and step up and to the right, |
| 62 | + * which leaves the drawn mass off-centre inside any round-numbered viewBox — enough that |
| 63 | + * the mark sat visibly right of the copy beneath it. Framing on these bounds centres the |
| 64 | + * two. They are read off the shapes below by hand, so retuning the stack means updating |
| 65 | + * them here. |
| 66 | + */ |
| 67 | +const ART = { minX: 52, maxX: 166, minY: 18, maxY: 146 } as const |
| 68 | +const ART_PADDING = 10 |
| 69 | +const VIEW_BOX_WIDTH = ART.maxX - ART.minX + ART_PADDING * 2 |
| 70 | +const VIEW_BOX_HEIGHT = ART.maxY - ART.minY + ART_PADDING * 2 |
| 71 | +const VIEW_BOX = `${ART.minX - ART_PADDING} ${ART.minY - ART_PADDING} ${VIEW_BOX_WIDTH} ${VIEW_BOX_HEIGHT}` |
| 72 | + |
| 73 | +/** Matches the other resource graphics, so the set centres as one collection. */ |
| 74 | +const MARK_HEIGHT = 148 |
| 75 | + |
| 76 | +/** |
| 77 | + * A stack of sheets, the front one dog-eared and ruled. The two behind it step up and |
| 78 | + * to the right, so the stack reads as depth rather than as a single thick page. |
| 79 | + */ |
| 80 | +function DocumentsGraphic() { |
| 81 | + return ( |
| 82 | + <svg |
| 83 | + viewBox={VIEW_BOX} |
| 84 | + width={(MARK_HEIGHT * VIEW_BOX_WIDTH) / VIEW_BOX_HEIGHT} |
| 85 | + height={MARK_HEIGHT} |
| 86 | + fill='none' |
| 87 | + aria-hidden='true' |
| 88 | + focusable='false' |
| 89 | + className={cn('block max-w-none shrink-0', STACK_FADE, MASK_NO_REPEAT)} |
| 90 | + > |
| 91 | + <rect x='70' y='18' width='96' height='112' rx='6' fill='var(--surface-4)' {...HAIRLINE} /> |
| 92 | + <rect x='61' y='26' width='96' height='112' rx='6' fill='var(--surface-3)' {...HAIRLINE} /> |
| 93 | + |
| 94 | + <path d={SHEET} fill='var(--surface-2)' {...HAIRLINE} /> |
| 95 | + <path d={DOG_EAR} fill='var(--surface-4)' {...HAIRLINE} /> |
| 96 | + |
| 97 | + <rect x='68' y='64' width='44' height='6' rx='3' fill={INK.heading} /> |
| 98 | + {BODY_LINES.map((line) => ( |
| 99 | + <rect |
| 100 | + key={line.y} |
| 101 | + x='68' |
| 102 | + y={line.y} |
| 103 | + width={line.width} |
| 104 | + height='5' |
| 105 | + rx='2.5' |
| 106 | + fill={INK.body} |
| 107 | + /> |
| 108 | + ))} |
| 109 | + </svg> |
| 110 | + ) |
| 111 | +} |
| 112 | + |
| 113 | +interface DocumentsEmptyStateProps { |
| 114 | + /** Opens the file picker — the same action the header's primary chip runs. */ |
| 115 | + onAddDocuments: () => void |
| 116 | + /** Mirrors the header chip's disabled state: no edit rights on the workspace. */ |
| 117 | + addDisabled?: boolean |
| 118 | +} |
| 119 | + |
| 120 | +/** Empty state for a knowledge base that holds no documents yet. */ |
| 121 | +export function DocumentsEmptyState({ |
| 122 | + onAddDocuments, |
| 123 | + addDisabled = false, |
| 124 | +}: DocumentsEmptyStateProps) { |
| 125 | + return ( |
| 126 | + <EmptyState |
| 127 | + graphic={<DocumentsGraphic />} |
| 128 | + title='Documents' |
| 129 | + description='Upload documents so your agents can search this base.' |
| 130 | + action={ |
| 131 | + <> |
| 132 | + <Chip variant='primary' onClick={onAddDocuments} disabled={addDisabled} leftIcon={Plus}> |
| 133 | + New documents |
| 134 | + </Chip> |
| 135 | + <EmptyStateDocsLink href={KNOWLEDGE_DOCS_URL} /> |
| 136 | + </> |
| 137 | + } |
| 138 | + /> |
| 139 | + ) |
| 140 | +} |
0 commit comments