UNPKG

synapse-react-client

Version:

[![Build Status](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client.svg?branch=main)](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synaps

73 lines 4.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EvaluationRoundEditorList = void 0; var tslib_1 = require("tslib"); var react_1 = (0, tslib_1.__importStar)(require("react")); var useListState_1 = require("../../utils/hooks/useListState"); var EvaluationRoundEditor_1 = require("./EvaluationRoundEditor"); var react_bootstrap_1 = require("react-bootstrap"); var models_1 = require("./input_models/models"); var SynapseClient_1 = require("../../utils/SynapseClient"); var shortid_1 = (0, tslib_1.__importDefault)(require("shortid")); var ErrorBanner_1 = require("../ErrorBanner"); var SynapseContext_1 = require("../../utils/SynapseContext"); var fetchEvaluationList = function (evaluationId, accessToken, setListCallback, errorHandleCallback) { var allEvaluationRoundInputList = []; var getEvaluationRounds = function (nextPageToken) { (0, SynapseClient_1.getEvaluationRoundsList)(evaluationId, { nextPageToken: nextPageToken }, accessToken) .then(function (response) { var convertedToInput = response.page.map(function (evaluationRound) { return (0, models_1.convertEvaluationRoundToInput)(evaluationRound); }); allEvaluationRoundInputList.push.apply(allEvaluationRoundInputList, convertedToInput); errorHandleCallback(undefined); if (response.nextPageToken) { getEvaluationRounds(response.nextPageToken); } else { // no more pages left. we can set the list setListCallback(allEvaluationRoundInputList); } }) .catch(function (error) { errorHandleCallback(error); }); }; //initially no next page token getEvaluationRounds(undefined); }; /** * Edits EvaluationsRounds for an Evaluation. */ var EvaluationRoundEditorList = function (_a) { var evaluationId = _a.evaluationId; var accessToken = (0, SynapseContext_1.useSynapseContext)().accessToken; var _b = (0, react_1.useState)(), error = _b[0], setError = _b[1]; var _c = (0, useListState_1.useListState)([]), evaluationRoundInputList = _c.list, appendToEvaluationRoundInputList = _c.appendToList, handleEvaluationRoundInputListChange = _c.handleListChange, handleEvaluationRoundInputListRemove = _c.handleListRemove, setEvaluationRoundInputList = _c.setList; //run only once (0, react_1.useEffect)(function () { fetchEvaluationList(evaluationId, accessToken, setEvaluationRoundInputList, setError); }, // we explicitly dont want to list setEvaluationRoundInputList nor setError as a dependency // if we do, the fetchEvaluationList will re-fetch from the backend on every new render // eslint-disable-next-line react-hooks/exhaustive-deps [accessToken, evaluationId]); if (error) { return react_1.default.createElement(ErrorBanner_1.ErrorBanner, { error: error }); } return (react_1.default.createElement("div", { className: "evaluation-round-editor-list bootstrap-4-backport" }, react_1.default.createElement("div", { className: "evaluation-rounds" }, evaluationRoundInputList.map(function (evaluationRoundInput, index) { return (react_1.default.createElement(EvaluationRoundEditor_1.EvaluationRoundEditor, { key: evaluationRoundInput.reactListKey, evaluationRoundInput: evaluationRoundInput, onSave: handleEvaluationRoundInputListChange(index), onDelete: handleEvaluationRoundInputListRemove(index) })); })), react_1.default.createElement("div", null, react_1.default.createElement(react_bootstrap_1.Button, { className: "add-round-button", variant: "primary", onClick: function () { appendToEvaluationRoundInputList({ reactListKey: (0, shortid_1.default)(), evaluationId: evaluationId, roundStart: '', roundEnd: '', totalSubmissionLimit: '', otherLimits: [], }); } }, "Add Round")))); }; exports.EvaluationRoundEditorList = EvaluationRoundEditorList; //# sourceMappingURL=EvaluationRoundEditorList.js.map