UNPKG

@datalayer/core

Version:

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)

34 lines (33 loc) 2.58 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; /* * Copyright (c) 2023-2025 Datalayer, Inc. * Distributed under the terms of the Modified BSD License. */ import { FormControl, IconButton, Text, TextInput } from '@primer/react'; import { Box } from '@datalayer/primer-addons'; import { PlusIcon } from '@primer/octicons-react'; import { Slider } from '@datalayer/primer-addons'; /** * Maximal time reservable for a runtime in minutes. * * TODO this should be configurable */ export const MAXIMAL_RUNTIME_TIME_RESERVATION_MINUTES = 24 * 60; /** * Runtime reservation control */ export function RuntimeReservationControl(props) { const { addCredits, burningRate, disabled, error, label, max: maxProps, onTimeChange, time, } = props; const max = Math.min(maxProps, MAXIMAL_RUNTIME_TIME_RESERVATION_MINUTES); // Temporary workaround to not show disabled components. const hidden = disabled; return !hidden ? (_jsxs(FormControl, { disabled: disabled, sx: { paddingBottom: 'var(--stack-padding-condensed)' }, children: [_jsx(FormControl.Label, { children: label }), _jsxs(Box, { style: { alignItems: 'center', display: 'grid', gridTemplateColumns: 'max-content 1fr max-content max-content', gridGap: 'var(--stack-gap-condensed)', width: '100%', }, children: [_jsx(Slider, { step: 1, min: 1, max: max, value: time, onChange: onTimeChange, disabled: disabled, label: "", displayValue: false }), _jsx(TextInput, { type: "number", step: "1", min: "1", max: max, disabled: disabled, value: Math.min(max, time).toFixed(2), onChange: event => { onTimeChange(parseFloat(event.target.value)); } }), (max === 0 || max > Number.EPSILON) && (_jsxs(_Fragment, { children: [_jsxs(Text, { children: ["out of ", maxProps, " available minutes"] }), addCredits && (_jsx(IconButton, { icon: PlusIcon, "aria-label": "Add credits", onClick: () => addCredits() }))] }))] }), _jsxs(FormControl.Caption, { children: ["Maximum execution time that can be consumed by the runtime. It must be less than ", (MAXIMAL_RUNTIME_TIME_RESERVATION_MINUTES / 60).toFixed(0), ' ', "hours.", burningRate && (_jsxs(_Fragment, { children: [_jsx("br", {}), `With the current value, the runtime execution will consume at most ${(time * burningRate * 60).toFixed(2)} credits.`] }))] }), error && (_jsx(FormControl.Validation, { variant: "error", children: error }))] })) : (_jsx(_Fragment, {})); }