mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-02 17:28:12 +08:00
add autosave
This commit is contained in:
@@ -387,3 +387,82 @@ export const saveObsAnnotationsAction = () => async (dispatch, getState) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const saveGenesetsAction = () => async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const { config, genesets, annotations } = state;
|
||||
|
||||
// bail if gene sets not available, or in readonly mode.
|
||||
const genesetsAreAvailable =
|
||||
config?.parameters?.["annotations_genesets"] ?? false;
|
||||
const genesetsReadonly =
|
||||
config?.parameters?.["annotations_genesets_readonly"] ?? true;
|
||||
if (!genesetsAreAvailable || genesetsReadonly) {
|
||||
// our non-save was completed!
|
||||
dispatch({
|
||||
type: "autosave: genesets complete",
|
||||
lastSavedGenesets: genesets,
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
JSON data structure is an array of arrays, where the first
|
||||
element is gene set name, remainder are the genes. Eg,
|
||||
|
||||
{
|
||||
"genesets": [
|
||||
[ "gs1", ["TNFRSF4","SUMO3","BRWD1"]],
|
||||
[ "gs2", ["DSCR3", "BRWD1", "BACE2", "SIK1", "C21orf33", "ICOSLG", "SUMO3"]]
|
||||
]
|
||||
}
|
||||
|
||||
Order of gene sets and genes is significant
|
||||
*/
|
||||
const gsArr = [];
|
||||
for (const [gsName, gsGenes] of genesets.genesets) {
|
||||
gsArr.push([gsName, Array.from(gsGenes)]);
|
||||
}
|
||||
|
||||
try {
|
||||
const { dataCollectionNameIsReadOnly, dataCollectionName } = annotations;
|
||||
const queryString =
|
||||
!dataCollectionNameIsReadOnly && !!dataCollectionName
|
||||
? `?annotation-collection-name=${encodeURIComponent(
|
||||
dataCollectionName
|
||||
)}`
|
||||
: "";
|
||||
|
||||
const res = await fetch(
|
||||
`${globals.API.prefix}${globals.API.version}genesets${queryString}`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: new Headers({
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
body: JSON.stringify({
|
||||
genesets: gsArr,
|
||||
}),
|
||||
credentials: "include",
|
||||
}
|
||||
);
|
||||
if (res.ok) {
|
||||
dispatch({
|
||||
type: "autosave: genesets complete",
|
||||
lastSavedGenesets: genesets,
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: "autosave: genesets error",
|
||||
message: `HTTP error ${res.status} - ${res.statusText}`,
|
||||
res,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: "autosave: genesets error",
|
||||
message: error.toString(),
|
||||
error,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -52,14 +52,21 @@ async function userInfoFetch(dispatch) {
|
||||
});
|
||||
}
|
||||
|
||||
async function genesetsFetch(dispatch) {
|
||||
return fetchJson("genesets").then((response) => {
|
||||
const genesets = response?.genesets ?? {};
|
||||
async function genesetsFetch(dispatch, config) {
|
||||
if (config?.parameters?.["annotations_genesets"] ?? false) {
|
||||
fetchJson("genesets").then((response) => {
|
||||
const genesets = response?.genesets ?? {};
|
||||
dispatch({
|
||||
type: "geneset: initial load",
|
||||
init: genesets,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: "geneset: initial load",
|
||||
init: genesets,
|
||||
init: [],
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function prefetchEmbeddings(annoMatrix) {
|
||||
@@ -84,9 +91,10 @@ const doInitialDataLoad = () =>
|
||||
schemaFetch(dispatch),
|
||||
userColorsFetchAndLoad(dispatch),
|
||||
userInfoFetch(dispatch),
|
||||
genesetsFetch(dispatch),
|
||||
]);
|
||||
|
||||
genesetsFetch(dispatch, config);
|
||||
|
||||
const baseDataUrl = `${globals.API.prefix}${globals.API.version}`;
|
||||
const annoMatrix = new AnnoMatrixLoader(baseDataUrl, schema.schema);
|
||||
const obsCrossfilter = new AnnoMatrixObsCrossfilter(annoMatrix);
|
||||
@@ -253,6 +261,7 @@ export default {
|
||||
annotationRenameLabelInCategory: annoActions.annotationRenameLabelInCategory,
|
||||
annotationLabelCurrentSelection: annoActions.annotationLabelCurrentSelection,
|
||||
saveObsAnnotationsAction: annoActions.saveObsAnnotationsAction,
|
||||
saveGenesetsAction: annoActions.saveGenesetsAction,
|
||||
needToSaveObsAnnotations: annoActions.needToSaveObsAnnotations,
|
||||
layoutChoiceAction: embActions.layoutChoiceAction,
|
||||
setCellSetFromSelection: selnActions.setCellSetFromSelection,
|
||||
|
||||
Reference in New Issue
Block a user