generated from allen-cell-animated/github-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Changed CSV load action to be a logic
- Loading branch information
1 parent
b2e058f
commit 1498c5d
Showing
9 changed files
with
93 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { ReceiveImageDatasetAction } from "./types"; | ||
import { RECEIVE_IMAGE_DATASET } from "./constants"; | ||
import { ChangeImageDatasetTypeAction } from "./types"; | ||
import { CHANGE_IMAGE_DATASET_TYPE, LOAD_CSV_DATASET } from "./constants"; | ||
import { ImageDataset } from "./types"; | ||
|
||
export function receiveImageDataset(payload: ImageDataset): ReceiveImageDatasetAction { | ||
return { payload, type: RECEIVE_IMAGE_DATASET }; | ||
export function changeImageDatasetType(payload: ImageDataset): ChangeImageDatasetTypeAction { | ||
return { payload, type: CHANGE_IMAGE_DATASET_TYPE }; | ||
} | ||
|
||
export function loadCsvDataset(payload: string) { | ||
return { | ||
payload, | ||
type: LOAD_CSV_DATASET, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { makeConstant } from "../util"; | ||
|
||
export const RECEIVE_IMAGE_DATASET = makeConstant("metadata", "receive-image-dataset"); | ||
const makeImageDatasetConstant = (constant: string) => makeConstant("image-dataset", constant); | ||
|
||
export const LOAD_CSV_DATASET = makeImageDatasetConstant("load-csv-dataset"); | ||
|
||
export const CHANGE_IMAGE_DATASET_TYPE = makeImageDatasetConstant("change-image-dataset-type"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createLogic } from "redux-logic"; | ||
import { ReduxLogicDeps } from ".."; | ||
import { LOAD_CSV_DATASET } from "./constants"; | ||
import CsvRequest, { DEFAULT_CSV_DATASET_KEY } from "./csv-dataset"; | ||
import { changeImageDatasetType } from "./actions"; | ||
import { receiveAvailableDatasets } from "../metadata/actions"; | ||
import { changeDataset } from "../selection/actions"; | ||
|
||
/** | ||
* Parses a CSV file and opens it as a new image dataset. | ||
*/ | ||
const loadCsvDataset = createLogic({ | ||
type: LOAD_CSV_DATASET, | ||
async process(deps: ReduxLogicDeps, dispatch: any, done: any) { | ||
const { action } = deps; | ||
const fileContents = action.payload as string; | ||
const dataset = new CsvRequest(fileContents); | ||
dispatch(changeImageDatasetType(dataset)); | ||
|
||
const megasets = await dataset.getAvailableDatasets(); | ||
dispatch(receiveAvailableDatasets(megasets)); | ||
dispatch(changeDataset(DEFAULT_CSV_DATASET_KEY)); | ||
done(); | ||
}, | ||
}); | ||
|
||
export default [loadCsvDataset]; |
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