-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent data loss after go from step 3 to step 2
- Loading branch information
1 parent
f88e5e5
commit d16235a
Showing
6 changed files
with
77 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...import/steps/components/MatchColumnsStep/components/states/initialComputedColumnsState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Columns, | ||
ColumnType, | ||
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep'; | ||
import { ImportedRow } from '@/spreadsheet-import/types'; | ||
import { atom, selectorFamily } from 'recoil'; | ||
|
||
export const matchColumnsState = atom({ | ||
key: 'MatchColumnsState', | ||
default: [] as Columns<string>, | ||
}); | ||
|
||
export const initialComputedColumnsState = selectorFamily< | ||
Columns<string>, | ||
ImportedRow | ||
>({ | ||
key: 'InitialComputedColumnsState', | ||
get: | ||
(headerValues: ImportedRow) => | ||
({ get }) => { | ||
const currentState = get(matchColumnsState) as Columns<string>; | ||
if (currentState.length === 0) { | ||
// Do not remove spread, it indexes empty array elements, otherwise map() skips over them | ||
const initialState = ([...headerValues] as string[]).map( | ||
(value, index) => ({ | ||
type: ColumnType.empty, | ||
index, | ||
header: value ?? '', | ||
}), | ||
); | ||
return initialState as Columns<string>; | ||
} else { | ||
return currentState; | ||
} | ||
}, | ||
set: | ||
() => | ||
({ set }, newValue) => { | ||
set(matchColumnsState, newValue as Columns<string>); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters