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.
feature: UI for loading CSVs (CSV pt. 3) (#213)
* feat: Simple CSV parsing, reading of dataset values from CSV * refactor: Distinguish between numeric and discrete features, implemented more functions (greyscreen) * refactor: Store feature data, map categories to indices * fix: Fix crash caused by values being overwritten with NaN * fix: Initial channel settings, volume and thumbnail URLs * fix: Index cells by row index, not by cell Id label name * refactor: Store feature defs and data together in the same internal map * fix: Fixed bug where counts would not appear for categories * feat: Added artificial row feature when no discrete feature definition is given * refactor: Moved imageDataset into metadata state * feat: Added action to replace image dataset * feat: Added button to upload CSV data * feat: Use categorical color palette * refactor: Code cleanup * refactor: Code cleanup * feat: Add compatibility with BFF CSV data * refactor: CSV Dataset cleanup * feat: Added CSV parser as a mock image dataset * feat: Added unit tests, handled NaN values * doc: Added additional TODOs for CSV unit tests * refactor: Renamed constants * refactor: Renamed methods * feat: Check for BFF keys * refactor: Simplified default groupby feature behavior * fix: Added handling for spaces in headers and values * feat: Added additional unit tests for data validation * feat: Added unit tests for BFF parsing validation * refactor: Code cleanup * feat: Unit tests, updates to csv dataset loader * fix: Handled empty string in cell ID * refactor: Renamed components, actions, constants * refactor: Moved image dataset to its own state branch * refactor: Changed CSV load action to be a logic * fix: Linting * refactor: Code cleanup * doc: Added comment on webpack config * refactor: Renamed methods for clarity * refactor: Added remapping helper function * refactor: Moved types, const assignment, docstring updates * refactor: Hide CsvInput area
- Loading branch information
1 parent
b126f16
commit 22e316d
Showing
27 changed files
with
275 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,45 @@ | ||
import { PlusOutlined } from "@ant-design/icons"; | ||
import { Flex } from "antd"; | ||
import { RcFile } from "antd/es/upload"; | ||
import Dragger from "antd/es/upload/Dragger"; | ||
import React, { ReactElement } from "react"; | ||
import { ActionCreator, connect } from "react-redux"; | ||
|
||
import { State } from "../../state"; | ||
import imageDatasetStateBranch from "../../state/image-dataset"; | ||
import { LoadCsvDatasetAction } from "../../state/image-dataset/types"; | ||
|
||
type DispatchProps = { | ||
loadCsvDataset: ActionCreator<LoadCsvDatasetAction>; | ||
}; | ||
|
||
type CsvInputProps = DispatchProps; | ||
|
||
/** | ||
* An input area for CSV files. When CSV data is provided, replaces the current image dataset | ||
* with a new `CsvRequest` image dataset and triggers the loading of the CSV data. | ||
*/ | ||
function CsvInput(props: CsvInputProps): ReactElement { | ||
const action = async (file: RcFile): Promise<string> => { | ||
const fileText = await file.text(); | ||
props.loadCsvDataset(fileText); | ||
return Promise.resolve(""); | ||
}; | ||
|
||
return ( | ||
<Dragger action={action} accept=".csv" multiple={false} style={{ width: "50vw" }}> | ||
<Flex vertical={true} align={"center"}> | ||
<p style={{ fontSize: "30px" }}> | ||
<PlusOutlined /> | ||
</p> | ||
<p className="ant-upload-text">Click or drag a CSV file here to load.</p> | ||
</Flex> | ||
</Dragger> | ||
); | ||
} | ||
|
||
const dispatchToPropsMap: DispatchProps = { | ||
loadCsvDataset: imageDatasetStateBranch.actions.loadCsvDataset, | ||
}; | ||
|
||
export default connect<any, DispatchProps, any, State>(null, dispatchToPropsMap)(CsvInput); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ChangeImageDatasetTypeAction, LoadCsvDatasetAction } from "./types"; | ||
import { CHANGE_IMAGE_DATASET_TYPE, LOAD_CSV_DATASET } from "./constants"; | ||
import { ImageDataset } from "./types"; | ||
|
||
export function changeImageDatasetType(payload: ImageDataset): ChangeImageDatasetTypeAction { | ||
return { payload, type: CHANGE_IMAGE_DATASET_TYPE }; | ||
} | ||
|
||
export function loadCsvDataset(payload: string): LoadCsvDatasetAction { | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { makeConstant } from "../util"; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import FirebaseRequest from "./firebase"; | ||
import JsonRequest from "./json-dataset"; | ||
import { ImageDataset } from "./types"; | ||
import * as actions from "./actions"; | ||
import logics from "./logics"; | ||
import reducer from "./reducer"; | ||
import * as selectors from "./selectors"; | ||
import * as types from "./types"; | ||
|
||
// by default will use Firebase for dataset, can be switched to JSON dataset using ENV | ||
// variable | ||
export default function RequestClassToUse(): ImageDataset { | ||
return process.env.USE_JSON_DATASET ? new JsonRequest() : new FirebaseRequest(); | ||
} | ||
export default { | ||
actions, | ||
logics, | ||
reducer, | ||
selectors, | ||
types, | ||
}; |
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,28 @@ | ||
import { createLogic } from "redux-logic"; | ||
|
||
import { ReduxLogicDeps } from ".."; | ||
import { receiveAvailableDatasets } from "../metadata/actions"; | ||
import { changeDataset } from "../selection/actions"; | ||
import { changeImageDatasetType } from "./actions"; | ||
import { LOAD_CSV_DATASET } from "./constants"; | ||
import CsvRequest, { DEFAULT_CSV_DATASET_KEY } from "./csv-dataset"; | ||
|
||
/** | ||
* 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { TypeToDescriptionMap } from ".."; | ||
import { AnyAction } from "redux"; | ||
import { CHANGE_IMAGE_DATASET_TYPE } from "./constants"; | ||
import { ImageDataset, ImageDatasetStateBranch, ReceiveImageDatasetAction } from "./types"; | ||
import { makeReducer } from "../util"; | ||
import FirebaseRequest from "./firebase"; | ||
import JsonRequest from "./json-dataset"; | ||
|
||
// by default will use Firebase for dataset, can be switched to JSON dataset using ENV | ||
// variable | ||
function getImageDatasetInstance(): ImageDataset { | ||
return process.env.USE_JSON_DATASET ? new JsonRequest() : new FirebaseRequest(); | ||
} | ||
|
||
export const initialState: ImageDatasetStateBranch = { | ||
imageDataset: getImageDatasetInstance(), | ||
}; | ||
|
||
const actionToConfigMap: TypeToDescriptionMap = { | ||
[CHANGE_IMAGE_DATASET_TYPE]: { | ||
accepts: (action: AnyAction): action is ReceiveImageDatasetAction => | ||
action.type === CHANGE_IMAGE_DATASET_TYPE, | ||
perform: (state: ImageDatasetStateBranch, action: ReceiveImageDatasetAction) => { | ||
return { | ||
...state, | ||
imageDataset: action.payload, | ||
}; | ||
}, | ||
}, | ||
}; | ||
|
||
export default makeReducer<ImageDatasetStateBranch>(actionToConfigMap, initialState); |
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,4 @@ | ||
import { State } from ".."; | ||
import { ImageDataset } from "./types"; | ||
|
||
export const getImageDataset = (state: State): ImageDataset => state.imageDataset.imageDataset; |
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
Oops, something went wrong.