@datalayer/core 1.0.25 → 1.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -134
- package/lib/api/index.d.ts +0 -9
- package/lib/api/index.js +0 -9
- package/lib/cli-login.js +167 -0
- package/lib/client/auth/AuthenticationManager.d.ts +3 -3
- package/lib/client/auth/AuthenticationManager.js +13 -13
- package/lib/client/auth/strategies.d.ts +2 -2
- package/lib/client/auth/strategies.js +6 -6
- package/lib/client/base.d.ts +9 -12
- package/lib/client/base.js +17 -19
- package/lib/client/index.d.ts +10 -98
- package/lib/client/index.js +12 -21
- package/lib/client/mixins/IAMMixin.js +26 -26
- package/lib/components/auth/Login.js +2 -2
- package/lib/components/avatars/UserAvatar.d.ts +16 -0
- package/lib/components/avatars/UserAvatar.js +47 -0
- package/lib/components/avatars/index.d.ts +1 -0
- package/lib/components/avatars/index.js +1 -0
- package/lib/components/billing/BillableAccountSelect.js +4 -0
- package/lib/components/billing/index.js +4 -0
- package/lib/components/context/index.d.ts +0 -1
- package/lib/components/context/index.js +0 -1
- package/lib/components/display/DisplayHandle.d.ts +12 -0
- package/lib/components/display/DisplayHandle.js +11 -0
- package/lib/components/display/LiveRelativeTime.js +4 -0
- package/lib/components/display/index.d.ts +1 -0
- package/lib/components/display/index.js +1 -0
- package/lib/components/flashes/index.d.ts +0 -1
- package/lib/components/flashes/index.js +0 -1
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -1
- package/lib/components/principal/Principal.d.ts +7 -0
- package/lib/components/principal/Principal.js +153 -16
- package/lib/components/principal/PrincipalAvatar.d.ts +1 -1
- package/lib/components/principal/PrincipalAvatar.js +4 -28
- package/lib/components/principal/PrincipalBadge.js +4 -4
- package/lib/components/principal/PrincipalDetailsOverlay.d.ts +4 -2
- package/lib/components/principal/PrincipalDetailsOverlay.js +27 -7
- package/lib/components/principal/PrincipalSwitcherMenu.js +79 -42
- package/lib/components/progress/index.d.ts +0 -1
- package/lib/components/progress/index.js +0 -1
- package/lib/components/sharing/ShareAccessComponent.d.ts +3 -2
- package/lib/components/sharing/ShareAccessComponent.js +194 -147
- package/lib/components/sharing/SharingEditor.js +4 -0
- package/lib/components/snippets/index.d.ts +1 -1
- package/lib/components/snippets/index.js +1 -1
- package/lib/components/students/StudentResultCircle.d.ts +21 -0
- package/lib/components/students/StudentResultCircle.js +59 -0
- package/lib/components/students/index.d.ts +1 -1
- package/lib/components/students/index.js +1 -1
- package/lib/components/time/LiveRelativeTime.js +4 -0
- package/lib/components/time/index.js +4 -0
- package/lib/components/timeline/index.js +4 -0
- package/lib/components/tokens/index.d.ts +1 -1
- package/lib/components/tokens/index.js +1 -1
- package/lib/components/toolbars/index.d.ts +1 -3
- package/lib/components/toolbars/index.js +1 -3
- package/lib/config/Configuration.d.ts +13 -13
- package/lib/config/Configuration.js +5 -5
- package/lib/hooks/cacheConverters.d.ts +21 -0
- package/lib/hooks/cacheConverters.js +110 -0
- package/lib/hooks/index.d.ts +0 -2
- package/lib/hooks/index.js +0 -2
- package/lib/hooks/useCache.d.ts +64 -35
- package/lib/hooks/useCache.js +661 -306
- package/lib/hooks/useDatalayer.js +3 -1
- package/lib/hooks/useIAM.js +2 -4
- package/lib/hooks/useLocationHandles.d.ts +3 -1
- package/lib/hooks/useLocationHandles.js +2 -1
- package/lib/hooks/usePrincipalStore.d.ts +2 -2
- package/lib/hooks/usePrincipalStore.js +97 -14
- package/lib/hooks/useSelectedPrincipal.js +1 -1
- package/lib/hooks/useUser.js +19 -2
- package/lib/index.d.ts +1 -6
- package/lib/index.js +1 -13
- package/lib/main.js +3 -3
- package/lib/mocks/index.js +1 -1
- package/lib/mocks/models/index.d.ts +0 -1
- package/lib/mocks/models/index.js +0 -1
- package/lib/models/Datasource.d.ts +2 -2
- package/lib/models/IAM.d.ts +1 -1
- package/lib/models/School.d.ts +12 -3
- package/lib/models/Secret.d.ts +2 -2
- package/lib/models/Student.d.ts +13 -3
- package/lib/models/Usage.d.ts +11 -1
- package/lib/models/UserDTO.d.ts +2 -2
- package/lib/models/UserSettings.d.ts +1 -1
- package/lib/models/UserSettings.js +1 -1
- package/lib/models/index.d.ts +0 -30
- package/lib/models/index.js +0 -30
- package/lib/otel/client/OtelClient.d.ts +2 -2
- package/lib/otel/client/OtelClient.js +2 -2
- package/lib/otel/hooks/index.js +5 -5
- package/lib/otel/types.d.ts +1 -1
- package/lib/otel/views/OtelLive.js +1 -1
- package/lib/routes/index.d.ts +1 -0
- package/lib/routes/index.js +1 -0
- package/lib/routes/publicPaths.d.ts +23 -0
- package/lib/routes/publicPaths.js +74 -0
- package/lib/state/State.d.ts +0 -12
- package/lib/state/State.js +0 -12
- package/lib/state/substates/CoreState.js +13 -13
- package/lib/state/substates/IAMState.d.ts +1 -1
- package/lib/state/substates/IAMState.js +14 -14
- package/lib/state/substates/LayoutState.d.ts +12 -1
- package/lib/state/substates/SurveysState.d.ts +1 -1
- package/lib/state/substates/SurveysState.js +10 -10
- package/lib/state/substates/index.d.ts +0 -7
- package/lib/state/substates/index.js +0 -7
- package/lib/utils/Handles.js +3 -1
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/views/api-keys/APIKeys.js +12 -3
- package/lib/views/datasources/DatasourceDetail.d.ts +1 -1
- package/lib/views/datasources/DatasourceNew.d.ts +1 -1
- package/lib/views/datasources/Datasources.d.ts +1 -1
- package/lib/views/datasources/Datasources.js +12 -3
- package/lib/views/iam/SignInSimple.d.ts +37 -1
- package/lib/views/iam/SignInSimple.js +111 -13
- package/package.json +5 -3
- package/lib/App.css +0 -47
- package/lib/App.d.ts +0 -3
- package/lib/App.js +0 -21
- package/lib/api/runtimes/checkpoints.d.ts +0 -122
- package/lib/api/runtimes/checkpoints.js +0 -118
- package/lib/api/runtimes/environments.d.ts +0 -9
- package/lib/api/runtimes/environments.js +0 -29
- package/lib/api/runtimes/healthz.d.ts +0 -15
- package/lib/api/runtimes/healthz.js +0 -44
- package/lib/api/runtimes/index.d.ts +0 -12
- package/lib/api/runtimes/index.js +0 -16
- package/lib/api/runtimes/runtimes.d.ts +0 -138
- package/lib/api/runtimes/runtimes.js +0 -230
- package/lib/api/runtimes/snapshots.d.ts +0 -38
- package/lib/api/runtimes/snapshots.js +0 -82
- package/lib/api/scheduler/index.d.ts +0 -6
- package/lib/api/scheduler/index.js +0 -10
- package/lib/api/scheduler/schedules.d.ts +0 -85
- package/lib/api/scheduler/schedules.js +0 -78
- package/lib/api/spacer/documents.d.ts +0 -12
- package/lib/api/spacer/documents.js +0 -43
- package/lib/api/spacer/healthz.d.ts +0 -15
- package/lib/api/spacer/healthz.js +0 -44
- package/lib/api/spacer/index.d.ts +0 -15
- package/lib/api/spacer/index.js +0 -19
- package/lib/api/spacer/items.d.ts +0 -25
- package/lib/api/spacer/items.js +0 -55
- package/lib/api/spacer/lexicals.d.ts +0 -34
- package/lib/api/spacer/lexicals.js +0 -89
- package/lib/api/spacer/notebooks.d.ts +0 -34
- package/lib/api/spacer/notebooks.js +0 -89
- package/lib/api/spacer/spaces.d.ts +0 -84
- package/lib/api/spacer/spaces.js +0 -170
- package/lib/api/spacer/users.d.ts +0 -9
- package/lib/api/spacer/users.js +0 -29
- package/lib/client/mixins/RuntimesMixin.d.ts +0 -93
- package/lib/client/mixins/RuntimesMixin.js +0 -229
- package/lib/client/mixins/SpacerMixin.d.ts +0 -210
- package/lib/client/mixins/SpacerMixin.js +0 -615
- package/lib/client/utils/spacerUtils.d.ts +0 -18
- package/lib/client/utils/spacerUtils.js +0 -32
- package/lib/collaboration/DatalayerCollaboration.d.ts +0 -13
- package/lib/collaboration/DatalayerCollaboration.js +0 -28
- package/lib/collaboration/DatalayerCollaborationProvider.d.ts +0 -60
- package/lib/collaboration/DatalayerCollaborationProvider.js +0 -163
- package/lib/collaboration/index.d.ts +0 -2
- package/lib/collaboration/index.js +0 -6
- package/lib/components/context/SpaceSelect.d.ts +0 -2
- package/lib/components/context/SpaceSelect.js +0 -42
- package/lib/components/flashes/FlashDisclaimer.d.ts +0 -2
- package/lib/components/flashes/FlashDisclaimer.js +0 -17
- package/lib/components/icons/ArtifactIcon.d.ts +0 -10
- package/lib/components/icons/ArtifactIcon.js +0 -58
- package/lib/components/icons/index.d.ts +0 -1
- package/lib/components/icons/index.js +0 -5
- package/lib/components/nbgrader/NbGradesDetails.d.ts +0 -5
- package/lib/components/nbgrader/NbGradesDetails.js +0 -14
- package/lib/components/nbgrader/index.d.ts +0 -1
- package/lib/components/nbgrader/index.js +0 -5
- package/lib/components/progress/CreditsIndicator.d.ts +0 -33
- package/lib/components/progress/CreditsIndicator.js +0 -23
- package/lib/components/runtimes/RuntimeCellVariables.d.ts +0 -39
- package/lib/components/runtimes/RuntimeCellVariables.js +0 -172
- package/lib/components/runtimes/RuntimeCellVariablesDialog.d.ts +0 -37
- package/lib/components/runtimes/RuntimeCellVariablesDialog.js +0 -101
- package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +0 -57
- package/lib/components/runtimes/RuntimeLauncherDialog.js +0 -275
- package/lib/components/runtimes/RuntimePickerBase.d.ts +0 -69
- package/lib/components/runtimes/RuntimePickerBase.js +0 -122
- package/lib/components/runtimes/RuntimePickerCell.d.ts +0 -34
- package/lib/components/runtimes/RuntimePickerCell.js +0 -104
- package/lib/components/runtimes/RuntimePickerNotebook.d.ts +0 -42
- package/lib/components/runtimes/RuntimePickerNotebook.js +0 -232
- package/lib/components/runtimes/RuntimeReservationControl.d.ts +0 -47
- package/lib/components/runtimes/RuntimeReservationControl.js +0 -42
- package/lib/components/runtimes/RuntimeSimplePicker.d.ts +0 -38
- package/lib/components/runtimes/RuntimeSimplePicker.js +0 -155
- package/lib/components/runtimes/RuntimeTransfer.d.ts +0 -16
- package/lib/components/runtimes/RuntimeTransfer.js +0 -5
- package/lib/components/runtimes/RuntimeUtils.d.ts +0 -17
- package/lib/components/runtimes/RuntimeUtils.js +0 -178
- package/lib/components/runtimes/RuntimeVariables.d.ts +0 -38
- package/lib/components/runtimes/RuntimeVariables.js +0 -75
- package/lib/components/runtimes/index.d.ts +0 -11
- package/lib/components/runtimes/index.js +0 -15
- package/lib/components/scheduler/ScheduleMenu.d.ts +0 -54
- package/lib/components/scheduler/ScheduleMenu.js +0 -154
- package/lib/components/scheduler/index.d.ts +0 -1
- package/lib/components/scheduler/index.js +0 -5
- package/lib/components/snapshots/SandboxSnapshotMenu.d.ts +0 -33
- package/lib/components/snapshots/SandboxSnapshotMenu.js +0 -169
- package/lib/components/snapshots/index.d.ts +0 -1
- package/lib/components/snapshots/index.js +0 -5
- package/lib/components/snippets/SnippetDialog.d.ts +0 -42
- package/lib/components/snippets/SnippetDialog.js +0 -42
- package/lib/components/students/StudentItemStatus.d.ts +0 -7
- package/lib/components/students/StudentItemStatus.js +0 -66
- package/lib/components/tokens/SpaceVariantToken.d.ts +0 -5
- package/lib/components/tokens/SpaceVariantToken.js +0 -23
- package/lib/components/toolbars/AssignmentEditorToolbar.d.ts +0 -4
- package/lib/components/toolbars/AssignmentEditorToolbar.js +0 -18
- package/lib/components/toolbars/DocumentEditorToolbar.d.ts +0 -2
- package/lib/components/toolbars/DocumentEditorToolbar.js +0 -12
- package/lib/components/toolbars/NotebookEditorToolbar.d.ts +0 -29
- package/lib/components/toolbars/NotebookEditorToolbar.js +0 -30
- package/lib/examples/CellExample.d.ts +0 -6
- package/lib/examples/CellExample.js +0 -20
- package/lib/examples/NotebookExample.d.ts +0 -6
- package/lib/examples/NotebookExample.js +0 -19
- package/lib/examples/lexical-theme.css +0 -436
- package/lib/examples/notebooks/IPyWidgetsExample.ipynb.json +0 -101
- package/lib/examples/notebooks/IPyWidgetsExampleWithState.ipynb.json +0 -112
- package/lib/examples/notebooks/Lite.ipynb.json +0 -128
- package/lib/examples/notebooks/Matplotlib.ipynb.json +0 -137
- package/lib/examples/notebooks/NotebookExample1.ipynb.json +0 -126
- package/lib/examples/notebooks/NotebookExample2.ipynb.json +0 -48
- package/lib/examples/notebooks/NotebookOutputs.ipynb.json +0 -49
- package/lib/examples/notebooks/NotebookToCExample.ipynb.json +0 -102
- package/lib/examples/notebooks/PyGWalker.ipynb.json +0 -55
- package/lib/hooks/useCellOutputshot.d.ts +0 -4
- package/lib/hooks/useCellOutputshot.js +0 -25
- package/lib/hooks/useProjects.d.ts +0 -628
- package/lib/hooks/useProjects.js +0 -190
- package/lib/hooks/useRuntimes.d.ts +0 -5
- package/lib/hooks/useRuntimes.js +0 -34
- package/lib/mocks/jupyter/index.js +0 -5
- package/lib/mocks/models/CourseMock.d.ts +0 -6
- package/lib/mocks/models/CourseMock.js +0 -29
- package/lib/mocks/models/SpaceMock.d.ts +0 -6
- package/lib/mocks/models/SpaceMock.js +0 -25
- package/lib/models/Assignment.d.ts +0 -7
- package/lib/models/Assignment.js +0 -5
- package/lib/models/Cell.d.ts +0 -8
- package/lib/models/Cell.js +0 -5
- package/lib/models/CodeBlock.d.ts +0 -10
- package/lib/models/CodeBlock.js +0 -5
- package/lib/models/CodeSandboxSnapshot.d.ts +0 -92
- package/lib/models/CodeSandboxSnapshot.js +0 -13
- package/lib/models/CodeSandboxSnapshotDTO.d.ts +0 -173
- package/lib/models/CodeSandboxSnapshotDTO.js +0 -139
- package/lib/models/CodefeedBlocks.d.ts +0 -7
- package/lib/models/CodefeedBlocks.js +0 -5
- package/lib/models/Content.d.ts +0 -5
- package/lib/models/Content.js +0 -5
- package/lib/models/Course.d.ts +0 -17
- package/lib/models/Course.js +0 -5
- package/lib/models/Dataset.d.ts +0 -16
- package/lib/models/Dataset.js +0 -5
- package/lib/models/Document.d.ts +0 -8
- package/lib/models/Document.js +0 -5
- package/lib/models/Environment.d.ts +0 -86
- package/lib/models/Environment.js +0 -5
- package/lib/models/EnvironmentDTO.d.ts +0 -125
- package/lib/models/EnvironmentDTO.js +0 -88
- package/lib/models/Exercise.d.ts +0 -16
- package/lib/models/Exercise.js +0 -5
- package/lib/models/Item.d.ts +0 -20
- package/lib/models/Item.js +0 -5
- package/lib/models/ItemDTO.d.ts +0 -74
- package/lib/models/ItemDTO.js +0 -186
- package/lib/models/ItemType.d.ts +0 -2
- package/lib/models/ItemType.js +0 -5
- package/lib/models/Lesson.d.ts +0 -5
- package/lib/models/Lesson.js +0 -5
- package/lib/models/LexicalDTO.d.ts +0 -155
- package/lib/models/LexicalDTO.js +0 -157
- package/lib/models/Library.d.ts +0 -10
- package/lib/models/Library.js +0 -5
- package/lib/models/Notebook.d.ts +0 -11
- package/lib/models/Notebook.js +0 -5
- package/lib/models/NotebookDTO.d.ts +0 -96
- package/lib/models/NotebookDTO.js +0 -153
- package/lib/models/Page.d.ts +0 -41
- package/lib/models/Page.js +0 -25
- package/lib/models/PageTag.d.ts +0 -19
- package/lib/models/PageTag.js +0 -94
- package/lib/models/ProjectDTO.d.ts +0 -89
- package/lib/models/ProjectDTO.js +0 -131
- package/lib/models/Runtime.d.ts +0 -123
- package/lib/models/Runtime.js +0 -18
- package/lib/models/RuntimeDTO.d.ts +0 -191
- package/lib/models/RuntimeDTO.js +0 -204
- package/lib/models/Space.d.ts +0 -35
- package/lib/models/Space.js +0 -66
- package/lib/models/SpaceDTO.d.ts +0 -334
- package/lib/models/SpaceDTO.js +0 -244
- package/lib/models/SpaceItem.d.ts +0 -10
- package/lib/models/SpaceItem.js +0 -5
- package/lib/models/SpaceMember.d.ts +0 -6
- package/lib/models/SpaceMember.js +0 -5
- package/lib/models/StudentItem.d.ts +0 -21
- package/lib/models/StudentItem.js +0 -5
- package/lib/services/DatalayerServiceManager.d.ts +0 -22
- package/lib/services/DatalayerServiceManager.js +0 -69
- package/lib/services/index.d.ts +0 -4
- package/lib/services/index.js +0 -7
- package/lib/services/reconnectToRuntime.d.ts +0 -32
- package/lib/services/reconnectToRuntime.js +0 -59
- package/lib/state/substates/CellState.d.ts +0 -12
- package/lib/state/substates/CellState.js +0 -22
- package/lib/state/substates/DocumentState.d.ts +0 -10
- package/lib/state/substates/DocumentState.js +0 -14
- package/lib/state/substates/GradeState.d.ts +0 -10
- package/lib/state/substates/GradeState.js +0 -14
- package/lib/state/substates/JupyterLabState.d.ts +0 -16
- package/lib/state/substates/JupyterLabState.js +0 -17
- package/lib/state/substates/NbformatState.d.ts +0 -13
- package/lib/state/substates/NbformatState.js +0 -16
- package/lib/state/substates/RuntimesState.d.ts +0 -79
- package/lib/state/substates/RuntimesState.js +0 -180
- package/lib/state/substates/SpaceState.d.ts +0 -11
- package/lib/state/substates/SpaceState.js +0 -16
- package/lib/stateful/index.d.ts +0 -2
- package/lib/stateful/index.js +0 -6
- package/lib/stateful/jupyter/exec/Python.d.ts +0 -5
- package/lib/stateful/jupyter/exec/Python.js +0 -100
- package/lib/stateful/jupyter/exec/Snippets.d.ts +0 -105
- package/lib/stateful/jupyter/exec/Snippets.js +0 -101
- package/lib/stateful/jupyter/exec/index.d.ts +0 -2
- package/lib/stateful/jupyter/exec/index.js +0 -6
- package/lib/stateful/jupyter/index.d.ts +0 -2
- package/lib/stateful/jupyter/index.js +0 -6
- package/lib/stateful/jupyter/kernelsHandler.d.ts +0 -8
- package/lib/stateful/jupyter/kernelsHandler.js +0 -39
- package/lib/stateful/runtimes/actions.d.ts +0 -102
- package/lib/stateful/runtimes/actions.js +0 -249
- package/lib/stateful/runtimes/apis.d.ts +0 -273
- package/lib/stateful/runtimes/apis.js +0 -5
- package/lib/stateful/runtimes/index.d.ts +0 -5
- package/lib/stateful/runtimes/index.js +0 -9
- package/lib/stateful/runtimes/settings.d.ts +0 -15
- package/lib/stateful/runtimes/settings.js +0 -31
- package/lib/stateful/runtimes/snapshots.d.ts +0 -25
- package/lib/stateful/runtimes/snapshots.js +0 -150
- package/lib/stateful/runtimes/utils.d.ts +0 -7
- package/lib/stateful/runtimes/utils.js +0 -14
- package/lib/utils/Cells.d.ts +0 -2
- package/lib/utils/Cells.js +0 -28
- /package/lib/{mocks/jupyter/index.d.ts → cli-login.d.ts} +0 -0
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
|
-
* Distributed under the terms of the Modified BSD License.
|
|
5
|
-
*/
|
|
6
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
-
import { nullTranslator } from '@jupyterlab/translation';
|
|
8
|
-
import { JSONExt } from '@lumino/coreutils';
|
|
9
|
-
import { Autocomplete, FormControl, TextInputWithTokens } from '@primer/react';
|
|
10
|
-
import { Box } from '@datalayer/primer-addons';
|
|
11
|
-
/**
|
|
12
|
-
* Runtime Cell Variables Picker.
|
|
13
|
-
*/
|
|
14
|
-
export function RuntimeCellVariables(props) {
|
|
15
|
-
const { getInputOptions, getOutputOptions, inputs, output, setInputs, setOutput, translator, } = props;
|
|
16
|
-
const trans = useMemo(() => (translator ?? nullTranslator).load('jupyterlab'), [translator]);
|
|
17
|
-
const inputForOutputRef = useRef(null);
|
|
18
|
-
const [willSaveOutput, setWillSaveOutput] = useState(false);
|
|
19
|
-
const [inputLoading, setInputLoading] = useState(!!getInputOptions);
|
|
20
|
-
const [outputsState, setOutputsState] = useState(null);
|
|
21
|
-
const [inputsState, setInputsState] = useState(inputs.map(id => ({ id, text: id, selected: true })));
|
|
22
|
-
const [filterVal, setFilterVal] = useState('');
|
|
23
|
-
// Add inputs prop in inputsState
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
const candidates = inputs.filter(item => !inputsState.find(localItem => localItem.text === item));
|
|
26
|
-
if (candidates.length) {
|
|
27
|
-
setInputsState([
|
|
28
|
-
...inputsState,
|
|
29
|
-
...candidates.map(text => ({ id: text, text, selected: true })),
|
|
30
|
-
]);
|
|
31
|
-
}
|
|
32
|
-
}, [inputs]);
|
|
33
|
-
// Update inputs with selected inputsState
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
const candidates = inputsState
|
|
36
|
-
.filter(item => item.selected)
|
|
37
|
-
.map(item => item.text);
|
|
38
|
-
if (!JSONExt.deepEqual(inputs, candidates)) {
|
|
39
|
-
setInputs(candidates);
|
|
40
|
-
}
|
|
41
|
-
}, [inputsState]);
|
|
42
|
-
// Fetch the input candidates
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (!inputLoading) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (getInputOptions) {
|
|
48
|
-
getInputOptions().then(ins => {
|
|
49
|
-
const oldItems = inputsState.map(i => i.text);
|
|
50
|
-
setInputsState([
|
|
51
|
-
...inputsState,
|
|
52
|
-
...ins
|
|
53
|
-
.sort()
|
|
54
|
-
.filter(item => !oldItems.includes(item))
|
|
55
|
-
.map(text => ({
|
|
56
|
-
id: text,
|
|
57
|
-
text,
|
|
58
|
-
selected: false,
|
|
59
|
-
})),
|
|
60
|
-
]);
|
|
61
|
-
setInputLoading(false);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
setInputLoading(false);
|
|
66
|
-
}
|
|
67
|
-
}, [inputsState, getInputOptions]);
|
|
68
|
-
// Fetch the output candidates
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (getOutputOptions) {
|
|
71
|
-
Promise.all([getOutputOptions(), getInputOptions?.()])
|
|
72
|
-
.then(([outs, ins]) => {
|
|
73
|
-
setOutputsState(
|
|
74
|
-
// Add input variables as output candidate to cover
|
|
75
|
-
// mutation case
|
|
76
|
-
outs
|
|
77
|
-
.sort()
|
|
78
|
-
.concat((ins ?? []).sort())
|
|
79
|
-
// Remove duplicated variables; it may happen if
|
|
80
|
-
// the code introspection matches an input.
|
|
81
|
-
.reduce((agg, value) => {
|
|
82
|
-
if (!agg.includes(value)) {
|
|
83
|
-
agg.push(value);
|
|
84
|
-
}
|
|
85
|
-
return agg;
|
|
86
|
-
}, [])
|
|
87
|
-
.map(text => ({
|
|
88
|
-
id: text,
|
|
89
|
-
text,
|
|
90
|
-
selected: false,
|
|
91
|
-
})));
|
|
92
|
-
})
|
|
93
|
-
.catch(err => {
|
|
94
|
-
console.error('Failed to get the cell output candidates', err);
|
|
95
|
-
setOutputsState([]);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}, [getOutputOptions, getInputOptions]);
|
|
99
|
-
const onTokenRemove = useCallback((tokenId) => {
|
|
100
|
-
const idx = inputsState.findIndex(item => item.id === tokenId);
|
|
101
|
-
if (idx >= 0) {
|
|
102
|
-
inputsState.splice(idx, 1);
|
|
103
|
-
setInputsState([...inputsState]);
|
|
104
|
-
}
|
|
105
|
-
}, [inputsState]);
|
|
106
|
-
const onSelectedInputsChange = useCallback((newlySelectedItems) => {
|
|
107
|
-
if (!Array.isArray(newlySelectedItems)) {
|
|
108
|
-
newlySelectedItems = [newlySelectedItems];
|
|
109
|
-
}
|
|
110
|
-
const selectedIds = newlySelectedItems.map(i => i.id);
|
|
111
|
-
setInputsState([
|
|
112
|
-
...inputsState.map(localItem => selectedIds.includes(localItem.id)
|
|
113
|
-
? Object.assign(localItem, { selected: true })
|
|
114
|
-
: Object.assign(localItem, { selected: false })),
|
|
115
|
-
]);
|
|
116
|
-
}, [inputsState]);
|
|
117
|
-
const onItemSelect = useCallback((item) => {
|
|
118
|
-
const oldItem = inputsState.find(localItem => localItem.id === item.id);
|
|
119
|
-
if (!oldItem) {
|
|
120
|
-
setInputsState([...inputsState, item]);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
oldItem.selected = true;
|
|
124
|
-
setInputsState([...inputsState]);
|
|
125
|
-
}
|
|
126
|
-
}, [inputsState]);
|
|
127
|
-
const handleChange = useCallback((e) => {
|
|
128
|
-
if (e.currentTarget) {
|
|
129
|
-
setFilterVal(e.currentTarget.value);
|
|
130
|
-
}
|
|
131
|
-
}, []);
|
|
132
|
-
const onOutputChange = useCallback((e) => {
|
|
133
|
-
if (e.currentTarget) {
|
|
134
|
-
setOutput(e.currentTarget.value);
|
|
135
|
-
}
|
|
136
|
-
}, []);
|
|
137
|
-
const handleOutputMenuOpenChange = useCallback(
|
|
138
|
-
// There is a bug in primer Autocomplete that lead to the suggestion
|
|
139
|
-
// not triggering the `onChange` callback. So to fix it here, we
|
|
140
|
-
// use a pointer to the underlying input element to get the value
|
|
141
|
-
// and set it when the autocompletion menu closes.
|
|
142
|
-
(open) => {
|
|
143
|
-
if (!willSaveOutput) {
|
|
144
|
-
if (open) {
|
|
145
|
-
setWillSaveOutput(true);
|
|
146
|
-
}
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (inputForOutputRef.current && !open) {
|
|
150
|
-
setOutput(inputForOutputRef.current.value);
|
|
151
|
-
setWillSaveOutput(false);
|
|
152
|
-
}
|
|
153
|
-
}, [willSaveOutput]);
|
|
154
|
-
return (_jsxs(Box, { as: "form", sx: { p: 3 }, children: [_jsxs(FormControl, { children: [_jsx(FormControl.Label, { id: "cell-input-variables", children: trans.__('Inputs') }), _jsxs(Autocomplete, { children: [_jsx(Autocomplete.Input, { as: TextInputWithTokens, tokens: inputsState.filter(item => item.selected), onTokenRemove: onTokenRemove, onChange: handleChange }), _jsx(Autocomplete.Overlay, { children: _jsx(Autocomplete.Menu, { addNewItem: filterVal &&
|
|
155
|
-
!inputsState.find(localItem => localItem.text === filterVal)
|
|
156
|
-
? {
|
|
157
|
-
id: filterVal,
|
|
158
|
-
text: trans.__("Add '%1'", filterVal),
|
|
159
|
-
handleAddItem: item => {
|
|
160
|
-
onItemSelect({
|
|
161
|
-
...item,
|
|
162
|
-
text: filterVal,
|
|
163
|
-
selected: true,
|
|
164
|
-
});
|
|
165
|
-
setFilterVal('');
|
|
166
|
-
},
|
|
167
|
-
}
|
|
168
|
-
: undefined, items: inputsState, selectedItemIds: inputsState
|
|
169
|
-
.filter(item => item.selected)
|
|
170
|
-
.map(item => item.id), onSelectedChange: onSelectedInputsChange, "aria-labelledby": "cell-input-variables", selectionVariant: "multiple", emptyStateText: trans.__('No available variables.'), loading: inputLoading }) })] })] }), _jsxs(FormControl, { children: [_jsx(FormControl.Label, { id: "cell-output-variables", children: trans.__('Output') }), _jsxs(Autocomplete, { children: [_jsx(Autocomplete.Input, { ref: inputForOutputRef, value: output, onChange: onOutputChange }), _jsx(Autocomplete.Overlay, { children: _jsx(Autocomplete.Menu, { items: outputsState ?? [], selectedItemIds: output ? [output] : [], "aria-labelledby": "cell-output-variables", loading: getOutputOptions && !outputsState, emptyStateText: trans.__('Not among the available variables.'), onOpenChange: handleOutputMenuOpenChange }) })] })] })] }));
|
|
171
|
-
}
|
|
172
|
-
export default RuntimeCellVariables;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ISessionContext } from '@jupyterlab/apputils';
|
|
2
|
-
import { CodeCellModel } from '@jupyterlab/cells';
|
|
3
|
-
import { ITranslator } from '@jupyterlab/translation';
|
|
4
|
-
/**
|
|
5
|
-
* {@link RuntimeCellVariablesDialog} properties
|
|
6
|
-
*/
|
|
7
|
-
export interface IRuntimeCellVariablesDialogProps {
|
|
8
|
-
/**
|
|
9
|
-
* Code cell model
|
|
10
|
-
*/
|
|
11
|
-
model: CodeCellModel;
|
|
12
|
-
/**
|
|
13
|
-
* Callback request the dialog closure.
|
|
14
|
-
*/
|
|
15
|
-
onClose: () => void;
|
|
16
|
-
/**
|
|
17
|
-
* Session preference
|
|
18
|
-
*/
|
|
19
|
-
preference?: {
|
|
20
|
-
id?: string;
|
|
21
|
-
kernelDisplayName?: string;
|
|
22
|
-
language?: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Document session context
|
|
26
|
-
*/
|
|
27
|
-
sessionContext?: ISessionContext;
|
|
28
|
-
/**
|
|
29
|
-
* Application translator
|
|
30
|
-
*/
|
|
31
|
-
translator?: ITranslator;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Dialog to define the runtime cell variables to transfer
|
|
35
|
-
*/
|
|
36
|
-
export declare function RuntimeCellVariablesDialog(props: IRuntimeCellVariablesDialogProps): JSX.Element;
|
|
37
|
-
export default RuntimeCellVariablesDialog;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
|
-
* Distributed under the terms of the Modified BSD License.
|
|
5
|
-
*/
|
|
6
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
7
|
-
import { Dialog } from '@primer/react/experimental';
|
|
8
|
-
import { nullTranslator } from '@jupyterlab/translation';
|
|
9
|
-
import { JSONExt } from '@lumino/coreutils';
|
|
10
|
-
import { KernelExecutor } from '@datalayer/jupyter-react';
|
|
11
|
-
import { RuntimeSnippetsFacade } from '../../stateful/jupyter/index.js';
|
|
12
|
-
import { RuntimeCellVariables } from './RuntimeCellVariables.js';
|
|
13
|
-
/**
|
|
14
|
-
* Dialog to define the runtime cell variables to transfer
|
|
15
|
-
*/
|
|
16
|
-
export function RuntimeCellVariablesDialog(props) {
|
|
17
|
-
const { onClose, model, preference, sessionContext, translator } = props;
|
|
18
|
-
const [inputs, setInputs] = useState([]);
|
|
19
|
-
const [output, setOutput] = useState();
|
|
20
|
-
const trans = useMemo(() => (translator ?? nullTranslator).load('jupyterlab'), [translator]);
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const updateState = (model) => {
|
|
23
|
-
const datalayerMeta = model.getMetadata('datalayer') ?? {};
|
|
24
|
-
if (datalayerMeta.in && !JSONExt.deepEqual(inputs, datalayerMeta.in)) {
|
|
25
|
-
setInputs(datalayerMeta.in);
|
|
26
|
-
}
|
|
27
|
-
if (datalayerMeta.out && datalayerMeta.out !== output) {
|
|
28
|
-
setOutput(datalayerMeta.out);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
updateState(model);
|
|
32
|
-
model.metadataChanged.connect(updateState);
|
|
33
|
-
return () => {
|
|
34
|
-
model.metadataChanged.disconnect(updateState);
|
|
35
|
-
};
|
|
36
|
-
}, [model, inputs, output]);
|
|
37
|
-
const setVariables = useCallback(() => {
|
|
38
|
-
const datalayerMeta = model.getMetadata('datalayer') ?? {};
|
|
39
|
-
if (inputs.length) {
|
|
40
|
-
datalayerMeta.in = inputs;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
delete datalayerMeta.in;
|
|
44
|
-
}
|
|
45
|
-
if (output) {
|
|
46
|
-
datalayerMeta.out = output;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
delete datalayerMeta.out;
|
|
50
|
-
}
|
|
51
|
-
model.setMetadata('datalayer', { ...datalayerMeta });
|
|
52
|
-
onClose();
|
|
53
|
-
}, [model, inputs, output, onClose]);
|
|
54
|
-
const getInputCandidates = useCallback(async () => {
|
|
55
|
-
if (!sessionContext) {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
const connection = sessionContext.session.kernel;
|
|
59
|
-
const spec = sessionContext.specsManager.specs.kernelspecs[connection.model.name];
|
|
60
|
-
const snippets = new RuntimeSnippetsFacade(spec.language);
|
|
61
|
-
const outputs = await new KernelExecutor({ connection }).execute(snippets.listVariables());
|
|
62
|
-
const content = outputs.get(0).data['text/plain'];
|
|
63
|
-
if (content) {
|
|
64
|
-
const runtimeVariables = JSON.parse(
|
|
65
|
-
// We need to remove the quotes prior to parsing
|
|
66
|
-
content.slice(1, content.length - 1));
|
|
67
|
-
return Object.keys(runtimeVariables ?? {});
|
|
68
|
-
}
|
|
69
|
-
return [];
|
|
70
|
-
}, [preference, sessionContext]);
|
|
71
|
-
const getOutputCandidates = useCallback(async () => {
|
|
72
|
-
// TODO this is only valid for python - using cell mimetype?
|
|
73
|
-
return new RuntimeSnippetsFacade('python').getOutputCandidates(model.sharedModel.source);
|
|
74
|
-
}, [model]);
|
|
75
|
-
const datalayerMeta = model.getMetadata('datalayer') ?? {};
|
|
76
|
-
let title = 'Define cell variables to transfer';
|
|
77
|
-
const kernel = datalayerMeta.kernel ?? {};
|
|
78
|
-
const kernelName = (kernel.displayName || kernel.name) ?? '';
|
|
79
|
-
if (kernelName) {
|
|
80
|
-
if (kernel.params?.notebook !== false && kernel.id) {
|
|
81
|
-
title += ` with running ${kernelName} (${kernel.id.slice(0, 7)})`;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
title += ` with ${kernelName}`;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return (_jsx(Dialog, { title: _jsx("span", { style: { color: 'var(--fgColor-default)' }, children: title }), onClose: onClose, footerButtons: [
|
|
88
|
-
{
|
|
89
|
-
buttonType: 'default',
|
|
90
|
-
content: trans.__('Cancel'),
|
|
91
|
-
onClick: onClose,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
buttonType: 'primary',
|
|
95
|
-
content: trans.__('Set variables'),
|
|
96
|
-
onClick: setVariables,
|
|
97
|
-
autoFocus: true,
|
|
98
|
-
},
|
|
99
|
-
], children: _jsx(RuntimeCellVariables, { inputs: inputs, getInputOptions: sessionContext ? getInputCandidates : undefined, setInputs: setInputs, output: output ?? undefined, getOutputOptions: getOutputCandidates, setOutput: setOutput, translator: translator }) }));
|
|
100
|
-
}
|
|
101
|
-
export default RuntimeCellVariablesDialog;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { IMarkdownParser, IRenderMime } from '@jupyterlab/rendermime';
|
|
2
|
-
import type { IRemoteServicesManager } from '../../stateful/runtimes';
|
|
3
|
-
import type { ICodeSandboxSnapshot, IRuntimeDesc } from '../../models';
|
|
4
|
-
/**
|
|
5
|
-
* {@link RuntimeLauncherDialog} properties.
|
|
6
|
-
*/
|
|
7
|
-
export interface IRuntimeLauncherDialogProps {
|
|
8
|
-
/**
|
|
9
|
-
* Dialog title
|
|
10
|
-
*/
|
|
11
|
-
dialogTitle?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Remote Jupyter service manager
|
|
14
|
-
*/
|
|
15
|
-
manager: IRemoteServicesManager;
|
|
16
|
-
/**
|
|
17
|
-
* Form submission callback
|
|
18
|
-
*/
|
|
19
|
-
onSubmit: (spec?: IRuntimeDesc) => void;
|
|
20
|
-
/**
|
|
21
|
-
* Whether to start the kernel or not.
|
|
22
|
-
*
|
|
23
|
-
* If `with-example`, a kernel will be started an
|
|
24
|
-
* an example document will be opened (if available).
|
|
25
|
-
* If `defer`, a kernel will not be started but the
|
|
26
|
-
* kernel params will have a `creditsLimit` defined
|
|
27
|
-
* for spinning a runtime.
|
|
28
|
-
*
|
|
29
|
-
* Default: `true`
|
|
30
|
-
*/
|
|
31
|
-
startRuntime?: boolean | 'with-example' | 'defer';
|
|
32
|
-
/**
|
|
33
|
-
* Markdown parser
|
|
34
|
-
*/
|
|
35
|
-
markdownParser?: IMarkdownParser;
|
|
36
|
-
/**
|
|
37
|
-
* If provided the kernel will be started and will
|
|
38
|
-
* restore the provided snapshot in the kernel.
|
|
39
|
-
*/
|
|
40
|
-
kernelSnapshot?: ICodeSandboxSnapshot;
|
|
41
|
-
/**
|
|
42
|
-
* HTML sanitizer
|
|
43
|
-
*/
|
|
44
|
-
sanitizer?: IRenderMime.ISanitizer;
|
|
45
|
-
/**
|
|
46
|
-
* Upgrade subscription URL
|
|
47
|
-
*/
|
|
48
|
-
upgradeSubscription?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Optional submit button label override.
|
|
51
|
-
*/
|
|
52
|
-
submitLabel?: string;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Start Runtime Launcher Dialog.
|
|
56
|
-
*/
|
|
57
|
-
export declare function RuntimeLauncherDialog(props: IRuntimeLauncherDialogProps): JSX.Element;
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
|
-
* Distributed under the terms of the Modified BSD License.
|
|
5
|
-
*/
|
|
6
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
7
|
-
import { useIsMounted } from 'usehooks-ts';
|
|
8
|
-
import { Button, FormControl, Select, Spinner, Text, TextInput, ToggleSwitch, Tooltip, IconButton, } from '@primer/react';
|
|
9
|
-
import { Dialog } from '@primer/react/experimental';
|
|
10
|
-
import { AlertIcon } from '@primer/octicons-react';
|
|
11
|
-
import { Box } from '@datalayer/primer-addons';
|
|
12
|
-
import { useJupyterReactStore } from '@datalayer/jupyter-react';
|
|
13
|
-
import { USAGE_ROUTE } from '../../routes/index.js';
|
|
14
|
-
import { useNavigate } from '../../hooks/index.js';
|
|
15
|
-
import { NO_RUNTIME_AVAILABLE_LABEL } from '../../i18n/index.js';
|
|
16
|
-
import { iamStore, useCoreStore, useIAMStore } from '../../state/index.js';
|
|
17
|
-
import { createNotebook, sleep } from '../../utils/index.js';
|
|
18
|
-
import { Markdown } from '../display/index.js';
|
|
19
|
-
import { Timer } from '../progress/index.js';
|
|
20
|
-
import { FlashClosable } from '../flashes/index.js';
|
|
21
|
-
import { RuntimeReservationControl, MAXIMAL_RUNTIME_TIME_RESERVATION_MINUTES, } from './RuntimeReservationControl.js';
|
|
22
|
-
/**
|
|
23
|
-
* Initial time in milliseconds before retrying in case no kernels are available
|
|
24
|
-
*/
|
|
25
|
-
const NOT_AVAILABLE_INIT_RETRY = 10_000;
|
|
26
|
-
/**
|
|
27
|
-
* Number of trials in case of unavailable kernels
|
|
28
|
-
*/
|
|
29
|
-
const NOT_AVAILABLE_RETRIES = 5;
|
|
30
|
-
/**
|
|
31
|
-
* Start Runtime Launcher Dialog.
|
|
32
|
-
*/
|
|
33
|
-
export function RuntimeLauncherDialog(props) {
|
|
34
|
-
const { dialogTitle, kernelSnapshot, manager, onSubmit, markdownParser, sanitizer, upgradeSubscription, submitLabel, startRuntime = true, } = props;
|
|
35
|
-
const hasExample = startRuntime === 'with-example';
|
|
36
|
-
const shouldStartRuntime = startRuntime !== 'defer';
|
|
37
|
-
const user = iamStore.getState().user;
|
|
38
|
-
const environments = manager.environments.get();
|
|
39
|
-
const { configuration } = useCoreStore();
|
|
40
|
-
const { credits, refreshCredits } = useIAMStore();
|
|
41
|
-
let navigate;
|
|
42
|
-
try {
|
|
43
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
44
|
-
navigate = useNavigate();
|
|
45
|
-
}
|
|
46
|
-
catch (reason) {
|
|
47
|
-
// TODO when would this component be shown outside of a react-router? navigation is only available within a react-router.
|
|
48
|
-
console.warn(reason);
|
|
49
|
-
}
|
|
50
|
-
const jupyterReactStore = useJupyterReactStore();
|
|
51
|
-
const jupyterLabAdapter = jupyterReactStore.jupyterLabAdapter;
|
|
52
|
-
const [selection, setSelection] = useState((kernelSnapshot?.environment || environments[0]?.name) ?? '');
|
|
53
|
-
const [timeLimit, setTimeLimit] = useState(10);
|
|
54
|
-
const [runtimeName, setRuntimeName] = useState(environments[0]?.runtime?.givenNameTemplate || environments[0]?.title || '');
|
|
55
|
-
// Whether the runtim name has been changed by the user or not
|
|
56
|
-
const [hasCustomRuntimeName, setHasCustomRuntimeName] = useState(false);
|
|
57
|
-
const [userStorage, setUserStorage] = useState(false);
|
|
58
|
-
const [openExample, setOpenExample] = useState(false);
|
|
59
|
-
const [waitingForRuntime, setWaitingForRuntime] = useState(false);
|
|
60
|
-
const [error, setError] = useState();
|
|
61
|
-
const [flashLevel, setFlashLevel] = useState('danger');
|
|
62
|
-
const isMounted = useIsMounted();
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
if (shouldStartRuntime) {
|
|
65
|
-
refreshCredits();
|
|
66
|
-
}
|
|
67
|
-
}, [shouldStartRuntime]);
|
|
68
|
-
const spec = useMemo(() => environments.find(spec => spec.name === selection), [environments, selection]);
|
|
69
|
-
const description = spec?.description ?? '';
|
|
70
|
-
const burningRate = spec?.burning_rate ?? 1;
|
|
71
|
-
const creditsToMinutes = 1.0 / burningRate / 60.0;
|
|
72
|
-
const includedRuns = user?.subscription?.usage?.included_runs ??
|
|
73
|
-
user?.subscription?.included_runs;
|
|
74
|
-
const currentRuns = user?.subscription?.usage?.current_runs ??
|
|
75
|
-
user?.subscription?.current_runs ??
|
|
76
|
-
user?.subscription?.used_runs;
|
|
77
|
-
const hasKnownRunAllowance = typeof includedRuns === 'number';
|
|
78
|
-
const hasRemainingRuns = hasKnownRunAllowance &&
|
|
79
|
-
typeof currentRuns === 'number' &&
|
|
80
|
-
includedRuns > 0 &&
|
|
81
|
-
currentRuns < includedRuns;
|
|
82
|
-
const hasKnownCredits = typeof credits?.available === 'number';
|
|
83
|
-
const maxFromCredits = hasKnownCredits
|
|
84
|
-
? Math.floor((credits.available ?? 0) * creditsToMinutes)
|
|
85
|
-
: 10;
|
|
86
|
-
const effectiveMaxMinutes = hasKnownCredits && hasKnownRunAllowance && !hasRemainingRuns
|
|
87
|
-
? Math.max(1, maxFromCredits)
|
|
88
|
-
: Math.max(10, maxFromCredits > 0 ? maxFromCredits : 0);
|
|
89
|
-
const outOfCredits = shouldStartRuntime &&
|
|
90
|
-
hasKnownCredits &&
|
|
91
|
-
hasKnownRunAllowance &&
|
|
92
|
-
!hasRemainingRuns &&
|
|
93
|
-
((credits.available ?? 0) <= 0 || maxFromCredits < Number.EPSILON);
|
|
94
|
-
const handleSelectionChange = useCallback((e) => {
|
|
95
|
-
const selection = e.target.value;
|
|
96
|
-
setSelection(selection);
|
|
97
|
-
if (!hasCustomRuntimeName) {
|
|
98
|
-
const spec = environments.find(env => env.name === selection);
|
|
99
|
-
setRuntimeName(spec?.runtime?.givenNameTemplate || spec?.title || '');
|
|
100
|
-
}
|
|
101
|
-
}, [setSelection, hasCustomRuntimeName]);
|
|
102
|
-
const handleSubmitRuntime = useCallback(async () => {
|
|
103
|
-
if (selection) {
|
|
104
|
-
setError(undefined);
|
|
105
|
-
setWaitingForRuntime(shouldStartRuntime);
|
|
106
|
-
const spec = environments.find(s => s.name === selection);
|
|
107
|
-
const desc = {
|
|
108
|
-
name: selection,
|
|
109
|
-
language: spec?.language ?? '',
|
|
110
|
-
location: 'remote',
|
|
111
|
-
displayName: runtimeName ?? spec?.title,
|
|
112
|
-
};
|
|
113
|
-
const creditsLimit = Math.min(timeLimit, MAXIMAL_RUNTIME_TIME_RESERVATION_MINUTES) /
|
|
114
|
-
creditsToMinutes;
|
|
115
|
-
desc.params = {};
|
|
116
|
-
if (startRuntime === 'defer') {
|
|
117
|
-
desc.params['creditsLimit'] = creditsLimit;
|
|
118
|
-
}
|
|
119
|
-
if (userStorage) {
|
|
120
|
-
desc.params['capabilities'] = ['user_storage'];
|
|
121
|
-
}
|
|
122
|
-
let success = true;
|
|
123
|
-
if (shouldStartRuntime) {
|
|
124
|
-
success = false;
|
|
125
|
-
let availableTrial = 1;
|
|
126
|
-
let retryDelay = NOT_AVAILABLE_INIT_RETRY;
|
|
127
|
-
// Should return success status.
|
|
128
|
-
const startNewKernel = async () => {
|
|
129
|
-
try {
|
|
130
|
-
const connection = await manager.runtimesManager.startNew({
|
|
131
|
-
environmentName: selection,
|
|
132
|
-
type: 'notebook',
|
|
133
|
-
givenName: runtimeName,
|
|
134
|
-
creditsLimit: creditsLimit,
|
|
135
|
-
capabilities: userStorage ? ['user_storage'] : undefined,
|
|
136
|
-
snapshot: kernelSnapshot?.id,
|
|
137
|
-
}, {
|
|
138
|
-
username: user?.handle,
|
|
139
|
-
handleComms: true,
|
|
140
|
-
});
|
|
141
|
-
desc.kernelId = connection.id;
|
|
142
|
-
if (jupyterLabAdapter?.jupyterLab && hasExample && openExample) {
|
|
143
|
-
const example = environments.find(spec => spec.name === selection)?.example;
|
|
144
|
-
if (example) {
|
|
145
|
-
const options = {
|
|
146
|
-
kernelId: connection.id,
|
|
147
|
-
kernelName: connection.name,
|
|
148
|
-
};
|
|
149
|
-
createNotebook({
|
|
150
|
-
app: jupyterLabAdapter.jupyterLab,
|
|
151
|
-
name: selection,
|
|
152
|
-
url: example,
|
|
153
|
-
options,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
// Close the connection as we are not using it.
|
|
158
|
-
connection.dispose();
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
let msg = _jsx(Text, { children: "Failed to create the remote runtime\u2026" });
|
|
162
|
-
let level = 'danger';
|
|
163
|
-
let retry = false;
|
|
164
|
-
if (error.response?.status === 503) {
|
|
165
|
-
if (availableTrial++ <= NOT_AVAILABLE_RETRIES) {
|
|
166
|
-
retry = true;
|
|
167
|
-
msg = (_jsxs(Text, { children: ["The runtime you have requested is currently not available due to resource limitations. Leave this dialog open, new trial in ", _jsx(Timer, { duration: retryDelay * 0.001 }), ` (${availableTrial - 1}/${NOT_AVAILABLE_RETRIES}).`] }));
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
msg = _jsx(Text, { children: NO_RUNTIME_AVAILABLE_LABEL });
|
|
171
|
-
}
|
|
172
|
-
level = 'warning';
|
|
173
|
-
}
|
|
174
|
-
else if (error.name === 'MaxRuntimesExceededError') {
|
|
175
|
-
msg = (_jsx(Text, { children: "You reached your remote runtime limits. Stop existing runtimes before starting new ones." }));
|
|
176
|
-
level = 'warning';
|
|
177
|
-
}
|
|
178
|
-
else if (error.name === 'RuntimeUnreachable') {
|
|
179
|
-
msg = (_jsx(Text, { children: "The runtime has been created but can not be accessed. Please contact your IT support team to report this issue." }));
|
|
180
|
-
}
|
|
181
|
-
setFlashLevel(level);
|
|
182
|
-
console.error(msg, error);
|
|
183
|
-
setError(msg);
|
|
184
|
-
if (retry) {
|
|
185
|
-
await sleep(retryDelay);
|
|
186
|
-
retryDelay *= 2;
|
|
187
|
-
if (isMounted()) {
|
|
188
|
-
return await startNewKernel();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
finally {
|
|
194
|
-
setWaitingForRuntime(false);
|
|
195
|
-
}
|
|
196
|
-
return true;
|
|
197
|
-
};
|
|
198
|
-
// Start the kernel if the reservation succeeded.
|
|
199
|
-
success = await startNewKernel();
|
|
200
|
-
}
|
|
201
|
-
if (success && isMounted()) {
|
|
202
|
-
if (!shouldStartRuntime) {
|
|
203
|
-
setWaitingForRuntime(false);
|
|
204
|
-
}
|
|
205
|
-
onSubmit(desc);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}, [
|
|
209
|
-
manager,
|
|
210
|
-
selection,
|
|
211
|
-
startRuntime,
|
|
212
|
-
runtimeName,
|
|
213
|
-
onSubmit,
|
|
214
|
-
userStorage,
|
|
215
|
-
openExample,
|
|
216
|
-
jupyterLabAdapter,
|
|
217
|
-
timeLimit,
|
|
218
|
-
shouldStartRuntime,
|
|
219
|
-
isMounted,
|
|
220
|
-
]);
|
|
221
|
-
const handleUserStorageChange = useCallback((e) => {
|
|
222
|
-
e.preventDefault();
|
|
223
|
-
setUserStorage(!userStorage);
|
|
224
|
-
}, [userStorage]);
|
|
225
|
-
const handleSwitchClick = useCallback((e) => {
|
|
226
|
-
e.preventDefault();
|
|
227
|
-
setOpenExample(!openExample);
|
|
228
|
-
}, [openExample]);
|
|
229
|
-
const handleUpgrade = useCallback(() => {
|
|
230
|
-
if (upgradeSubscription) {
|
|
231
|
-
navigate?.(upgradeSubscription);
|
|
232
|
-
}
|
|
233
|
-
}, [navigate, upgradeSubscription]);
|
|
234
|
-
const handleKernelNameChange = useCallback((e) => {
|
|
235
|
-
if (typeof e.target.value === 'string') {
|
|
236
|
-
setRuntimeName(e.target.value);
|
|
237
|
-
setHasCustomRuntimeName(true);
|
|
238
|
-
}
|
|
239
|
-
}, []);
|
|
240
|
-
// TODO title color is enforced for JupyterLab.
|
|
241
|
-
// This may be fixed in the jupyter-react theme (Primer generates h1 for the dialog title).
|
|
242
|
-
return (_jsx(Dialog, { title: _jsx("span", { style: { color: 'var(--fgColor-default)' }, children: dialogTitle || 'Launch a new Runtime' }), onClose: () => {
|
|
243
|
-
onSubmit(undefined);
|
|
244
|
-
}, footerButtons: [
|
|
245
|
-
{
|
|
246
|
-
buttonType: 'default',
|
|
247
|
-
onClick: () => {
|
|
248
|
-
onSubmit(undefined);
|
|
249
|
-
},
|
|
250
|
-
content: 'Cancel',
|
|
251
|
-
disabled: waitingForRuntime,
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
buttonType: 'primary',
|
|
255
|
-
onClick: handleSubmitRuntime,
|
|
256
|
-
content: waitingForRuntime ? (_jsx(Spinner, { size: "small" })) : ((submitLabel ?? ((startRuntime ?? true) ? 'Launch' : 'Assign'))),
|
|
257
|
-
disabled: waitingForRuntime || !selection || outOfCredits,
|
|
258
|
-
autoFocus: true,
|
|
259
|
-
},
|
|
260
|
-
], children: _jsxs(Box, { as: "form", onKeyDown: event => {
|
|
261
|
-
if (event.defaultPrevented) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
if (event.key === 'Enter') {
|
|
265
|
-
event.preventDefault();
|
|
266
|
-
handleSubmitRuntime();
|
|
267
|
-
}
|
|
268
|
-
}, children: [_jsxs(FormControl, { disabled: !!kernelSnapshot?.environment || environments.length === 0, children: [_jsx(FormControl.Label, { children: "Environment" }), _jsx(Select, { name: "environment", disabled: !!kernelSnapshot?.environment || environments.length === 0, value: selection, onChange: handleSelectionChange, block: true, children: environments.map(spec => (_jsxs(Select.Option, { value: spec.name, children: [spec.name, spec.title && (_jsxs(_Fragment, { children: [' - ', spec.title] }))] }, spec.name))) }), _jsx(FormControl.Caption, { children: _jsx(_Fragment, { children: markdownParser ? (_jsx(Box, { sx: { img: { maxWidth: '100%' } }, children: _jsx(Markdown, { text: description, markdownParser: markdownParser, sanitizer: sanitizer }) })) : (description) }) })] }), startRuntime && (_jsx(RuntimeReservationControl, { addCredits: navigate
|
|
269
|
-
? () => {
|
|
270
|
-
navigate(USAGE_ROUTE);
|
|
271
|
-
}
|
|
272
|
-
: undefined, disabled: outOfCredits, label: 'Time reservation', max: effectiveMaxMinutes, time: timeLimit, burningRate: burningRate, onTimeChange: setTimeLimit, error: outOfCredits ? 'You must add credits to your account.' : undefined })), !configuration.whiteLabel && (_jsxs(FormControl, { layout: "horizontal", children: [_jsxs(FormControl.Label, { id: "user-storage-label", children: ["User storage", _jsx(Tooltip, { text: 'The runtime will be slower to start.', direction: "e", style: { marginLeft: 3 }, children: _jsx(IconButton, { icon: AlertIcon, "aria-label": "", variant: "invisible" }) })] }), _jsx(ToggleSwitch, { checked: userStorage, size: "small", onClick: handleUserStorageChange, "aria-labelledby": "user-storage-label" })] })), _jsxs(FormControl, { sx: { paddingTop: '10px' }, children: [_jsx(FormControl.Label, { children: "Runtime name" }), _jsx(TextInput, { name: "name", value: runtimeName, onChange: handleKernelNameChange, block: true })] }), hasExample &&
|
|
273
|
-
jupyterLabAdapter?.jupyterLab &&
|
|
274
|
-
!configuration.whiteLabel && (_jsxs(FormControl, { sx: { paddingTop: '10px' }, children: [_jsx(FormControl.Label, { id: "open-example-label", children: "Open example notebook" }), _jsx(ToggleSwitch, { disabled: !environments.find(spec => spec.name === selection)?.example, checked: openExample, size: "small", onClick: handleSwitchClick, "aria-labelledby": "open-example-label" })] })), error && (_jsx(FlashClosable, { variant: flashLevel, actions: navigate && upgradeSubscription && flashLevel === 'warning' ? (_jsx(Button, { onClick: handleUpgrade, title: 'Upgrade your subscription.', children: "Upgrade" })) : undefined, children: error }))] }) }));
|
|
275
|
-
}
|