Fix Category/Media dropdowns: use cells() callback for dynamic sources

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-03-23 17:28:24 +00:00
parent 5169209c89
commit 7aea651df5

View file

@ -53,8 +53,6 @@ export default function SheetPage() {
}
}, [sheetId])
const categoryNames = categories.map(c => c.name)
const columns: Handsontable.ColumnSettings[] = [
{ data: 'Number', title: '#', width: 70, readOnly: true },
{ data: 'Title', title: 'Title', width: 200 },
@ -64,15 +62,11 @@ export default function SheetPage() {
},
{
data: 'Category', title: 'Category', width: 180,
type: 'autocomplete', source: categoryNames, strict: false, filter: true,
type: 'dropdown', strict: false,
},
{
data: 'Media', title: 'Media', width: 180,
type: 'autocomplete', strict: false, filter: true,
source(_query: string, process: (items: string[]) => void) {
// Dynamic source — resolved in cells() callback below
process([])
},
type: 'dropdown', strict: false,
},
{ data: 'Sub-media', title: 'Sub-media', width: 120 },
{ data: 'Format', title: 'Format', width: 100 },
@ -83,8 +77,12 @@ export default function SheetPage() {
]
const cells = useCallback((row: number, col: number): Handsontable.CellMeta => {
if (col === 3) {
// Category — source from admin dropdowns
return { source: categories.map(c => c.name) }
}
if (col === 4) {
// Media column — filter based on current row's Category
// Media — filter based on current row's Category
const hot = hotRef.current?.hotInstance
const category = hot?.getDataAtRowProp(row, 'Category') as string | undefined
const cat = categories.find(c => c.name === category)