Files
cellxgene/client/src/reducers/annotations.js
T
65ea1b673f Dunitz 1685 hosted annotations (#1789)
* save tiledb array to s3, dont cache user annotations

* Add option to disable annotation filename prompt (#1787)

Co-authored-by: Madison Dunitz <dunitzm@gmail.com>

* set tiledb default context in cxg_adaptor

Co-authored-by: maniarathi <arathi.mani@chanzuckerberg.com>
Co-authored-by: Severiano Badajoz <sbadajoz@chanzuckerberg.com>
2020-08-24 18:26:08 -05:00

120 lines
3.0 KiB
JavaScript

/*
Reducers for annotation UI-state.
*/
const Annotations = (
state = {
/*
Annotations collection name - which will be used to save the named set of annotations
in some persistent store (database, file system, etc).
The backend may expect this to be a legal file name, which is typically alpha-numeric, plus [_-,.].
Keep it simple or the server may return an error.
If `dataCollectionNameIsReadOnly` is true, you may NOT change the data collection name.
If false, you may change `dataCollectionName` and it will be used at the time the annotations are
written to the back-end.
*/
dataCollectionNameIsReadOnly: true,
dataCollectionName: null,
/*
Annotations UI component state
*/
isEditingCategoryName: false,
isEditingLabelName: false,
categoryBeingEdited: null,
categoryAddingNewLabel: null,
labelEditable: { category: null, label: null },
promptForFilename: true,
},
action
) => {
switch (action.type) {
case "configuration load complete": {
const dataCollectionName =
action.config.parameters?.["annotations-data-collection-name"] ?? null;
const dataCollectionNameIsReadOnly =
action.config.parameters?.[
"annotations-data-collection-name-is-read-only"
] ?? false;
const promptForFilename =
action.config.parameters?.["user_annotation_collection_name_enabled"];
return {
...state,
dataCollectionNameIsReadOnly,
dataCollectionName,
promptForFilename,
};
}
case "set annotations collection name": {
if (state.dataCollectionNameIsReadOnly) {
throw new Error("data collection name is read only");
}
return {
...state,
dataCollectionName: action.data,
};
}
/* CATEGORY */
case "annotation: activate add new label mode": {
return {
...state,
isAddingNewLabel: true,
categoryAddingNewLabel: action.data,
};
}
case "annotation: disable add new label mode": {
return {
...state,
isAddingNewLabel: false,
categoryAddingNewLabel: null,
};
}
case "annotation: activate category edit mode": {
return {
...state,
isEditingCategoryName: true,
categoryBeingEdited: action.data,
};
}
case "annotation: disable category edit mode": {
return {
...state,
isEditingCategoryName: false,
categoryBeingEdited: null,
};
}
/* LABEL */
case "annotation: activate edit label mode": {
return {
...state,
isEditingLabelName: true,
labelEditable: {
category: action.metadataField,
label: action.categoryIndex,
},
};
}
case "annotation: cancel edit label mode": {
return {
...state,
isEditingLabelName: false,
labelEditable: { category: null, label: null },
};
}
default:
return state;
}
};
export default Annotations;