MCPcopy Create free account
hub / github.com/HelloCSV/HelloCSV / reducer

Function reducer

src/importer/reducer.tsx:44–190  ·  view source on GitHub ↗
(
  state: ImporterState,
  action: ImporterAction
)

Source from the content-addressed store, hash-verified

42}
43
44export const reducer = (
45 state: ImporterState,
46 action: ImporterAction
47): ImporterState => {
48 switch (action.type) {
49 case 'ENTER_DATA_MANUALLY': {
50 const emptyData = state.sheetDefinitions.map((sheet) => ({
51 sheetId: sheet.id,
52 rows: Array.from(
53 { length: action.payload.amountOfEmptyRowsToAdd },
54 () => ({})
55 ),
56 }));
57
58 return { ...state, mode: 'preview', sheetData: emptyData };
59 }
60 case 'FILE_PARSED':
61 return {
62 ...state,
63 parsedFile: action.payload.parsed,
64 rowFile: action.payload.rowFile,
65 mode: 'mapping',
66 };
67 case 'UPLOAD':
68 return { ...state, mode: 'upload' };
69 case 'COLUMN_MAPPING_CHANGED': {
70 return {
71 ...state,
72 columnMappings: action.payload.mappings,
73 };
74 }
75 case 'DATA_MAPPED': {
76 return {
77 ...state,
78 sheetData: applyTransformations(
79 state.sheetDefinitions,
80 action.payload.mappedData
81 ),
82 mode: 'preview',
83 };
84 }
85 case 'CELL_CHANGED': {
86 const currentData = state.sheetData;
87
88 const newData = currentData.map((sheet) => {
89 if (sheet.sheetId === action.payload.sheetId) {
90 const newRows = [...sheet.rows];
91
92 newRows[action.payload.rowIndex] = recalculateCalculatedColumns(
93 action.payload.value,
94 action.payload,
95 state
96 );
97
98 return { ...sheet, rows: newRows };
99 } else {
100 return sheet;
101 }

Callers 1

getStateMethod · 0.90

Calls 3

applyTransformationsFunction · 0.90
buildInitialStateFunction · 0.90

Tested by

no test coverage detected