import { Accessor, Component, createEffect, createMemo, createSignal } from "solid-js"; import { debounce, Mutation } from "~/utilities"; import { Column, GridApi as GridCompApi, Grid as GridComp } from "~/components/grid"; import { createDataSet, DataSetNode, DataSetRowNode } from "~/components/table"; import { SelectionItem } from "../selectable"; import { useI18n } from "../i18n"; import css from "./grid.module.css" export type Entry = { key: string } & { [lang: string]: string }; export interface GridApi { readonly mutations: Accessor; readonly selection: Accessor[]>; remove(indices: number[]): void; addKey(key: string): void; selectAll(): void; clearSelection(): void; }; const groupBy = (rows: DataSetRowNode[]) => { type R = DataSetRowNode & { _key: string }; const group = (nodes: R[]): DataSetNode[] => Object .entries(Object.groupBy(nodes, r => r._key.split('.').at(0)!) as Record) .map(([key, nodes]) => nodes.at(0)?._key === key ? nodes[0] : ({ kind: 'group', key, groupedBy: 'key', nodes: group(nodes.map(n => ({ ...n, _key: n._key.slice(key.length + 1) }))) }) ); return group(rows.map(r => ({ ...r, _key: r.value.key }))) as any; } export function Grid(props: { class?: string, rows: Entry[], locales: string[], api?: (api: GridApi) => any }) { const { t } = useI18n(); const rows = createMemo(() => createDataSet(props.rows, { group: { by: 'key', with: groupBy } })); const locales = createMemo(() => props.locales); const columns = createMemo[]>(() => [ { id: 'key', label: t('feature.file.grid.key'), renderer: ({ value }) => value.split('.').at(-1), }, ...locales().map>(lang => ({ id: lang, label: lang, renderer: ({ row, column, value, mutate }) => { const entry = rows().value[row]!; return