mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 16:05:23 +02:00
Fix: Implement dynamic column detection to handle Excel structure changes (insertion of PM Classification). This fixes the Missing data error in Pricing Units and other views.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import React, { createContext, useContext, useMemo } from 'react';
|
||||
import { COLUMNS, resolveColumnIndices } from '../types';
|
||||
|
||||
type ColumnIndices = typeof COLUMNS;
|
||||
|
||||
const ColumnsContext = createContext<ColumnIndices>(COLUMNS);
|
||||
|
||||
export function ColumnsProvider({ headers, children }: { headers: string[], children: React.ReactNode }) {
|
||||
const resolved = useMemo(() => {
|
||||
if (!headers || headers.length === 0) return COLUMNS;
|
||||
return resolveColumnIndices(headers);
|
||||
}, [headers]);
|
||||
|
||||
return (
|
||||
<ColumnsContext.Provider value={resolved}>
|
||||
{children}
|
||||
</ColumnsContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useColumns() {
|
||||
return useContext(ColumnsContext);
|
||||
}
|
||||
Reference in New Issue
Block a user