synapse-react-client
Version:
[](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [](https://badge.fury.io/js/synaps
47 lines • 3.22 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HelpersToTest = exports.EvaluationEditorPage = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importStar)(require("react"));
var EvaluationEditor_1 = require("./EvaluationEditor");
var EvaluationRoundEditorList_1 = require("./EvaluationRoundEditorList");
var react_bootstrap_1 = require("react-bootstrap");
/**
* Combined editor that allows editing an Evaluation's data and also it's associated rounds (once the Evaluation exists on Synapse)
*/
var EvaluationEditorPage = function (_a) {
var evaluationId = _a.evaluationId, entityId = _a.entityId, onDeleteSuccess = _a.onDeleteSuccess;
var _b = (0, react_1.useState)(evaluationId), savedEvaluationId = _b[0], setSavedEvaluationId = _b[1];
return (react_1.default.createElement("div", { className: "bootstrap-4-backport" },
react_1.default.createElement(EvaluationEditor_1.EvaluationEditor, { evaluationId: savedEvaluationId,
//do not use entityId if we already have the evaluation Id
entityId: savedEvaluationId ? undefined : entityId, onDeleteSuccess: onDeleteSuccess, onSaveSuccess: setSavedEvaluationId }),
react_1.default.createElement("div", { className: "mt-4" }, savedEvaluationId ? (react_1.default.createElement(EvaluationRoundEditorList_1.EvaluationRoundEditorList, { evaluationId: savedEvaluationId })) : (
// shows an alert informing user to first create an Evaluation if they
// click the "Add Round" button
react_1.default.createElement(FakeEvaluationRoundEditorList, null)))));
};
exports.EvaluationEditorPage = EvaluationEditorPage;
/**
* special case handling when the evaluation has not been created yet (i.e. does not exist)
* in this case, we show a fake "add round" button that when clicked, will
* display an alert telling the user to first create an Evaluation
*
* Note: an alternative would be to modify the existing EvaluationRoundEditorList
* to accept a nullable evaluationId (i.e. `string?` instead of `string`)
* so that we can move this fake Alert functionality into it.
*
* Since the "uncreated Evaluation" edge case is currently only specific to the EvaluationEditorPage,
* I believe adopting this alternative would add unnecessary complexity,
* forcing EvaluationRoundEditorList to handle undefined `evaluationId`.
*/
var FakeEvaluationRoundEditorList = function () {
var _a = (0, react_1.useState)(false), showEvaluationNotExistAlert = _a[0], setShowEvaluationNotExistAlert = _a[1];
return (react_1.default.createElement("div", null, showEvaluationNotExistAlert ? (react_1.default.createElement(react_bootstrap_1.Alert, { dismissible: false, show: true, variant: 'info', transition: false }, "Evaluation Rounds can be edited once the Evaluation has been created.")) : (react_1.default.createElement(react_bootstrap_1.Button, { className: "add-round-button", variant: "primary", onClick: function () {
setShowEvaluationNotExistAlert(true);
} }, "Add Round"))));
};
exports.HelpersToTest = {
FakeEvaluationRoundEditorList: FakeEvaluationRoundEditorList,
};
//# sourceMappingURL=EvaluationEditorPage.js.map