Skip to content

Commit

Permalink
Provide backend access to IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
kazcw committed Jul 5, 2024
1 parent 9fbb4a6 commit 3bb22b4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/gui2/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import HelpScreen from '@/components/HelpScreen.vue'
import { provideAppClassSet } from '@/providers/appClass'
import { provideBackend } from '@/providers/backend'
import { provideEventLogger } from '@/providers/eventLogging'
import { provideGuiConfig } from '@/providers/guiConfig'
import { registerAutoBlurHandler } from '@/util/autoBlur'
Expand All @@ -13,7 +14,8 @@ import {
} from '@/util/config'
import ProjectView from '@/views/ProjectView.vue'
import { useEventListener } from '@vueuse/core'
import { computed, toRef, watch } from 'vue'
import Backend from 'enso-common/src/services/Backend'
import { computed, markRaw, toRaw, toRef, watch } from 'vue'
import TooltipDisplayer from './components/TooltipDisplayer.vue'
import { provideTooltipRegistry } from './providers/tooltipState'
import { initializePrefixes } from './util/ast/node'
Expand All @@ -26,8 +28,11 @@ const props = defineProps<{
hidden: boolean
ignoreParamsRegex?: RegExp
renameProject: (newName: string) => void
backend: Backend
}>()
provideBackend(() => markRaw(toRaw(props.backend)))
const classSet = provideAppClassSet()
const appTooltips = provideTooltipRegistry()
Expand Down
11 changes: 11 additions & 0 deletions app/gui2/src/providers/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createContextStore } from '@/providers'
import type { ToValue } from '@/util/reactivity'
import type Backend from 'enso-common/src/services/Backend'
import { computed, proxyRefs, toValue } from 'vue'

export { injectFn as injectBackend, provideFn as provideBackend }
const { provideFn, injectFn } = createContextStore('backend', (backend: ToValue<Backend>) =>
proxyRefs({
backend: computed(() => toValue(backend)),
}),
)
14 changes: 11 additions & 3 deletions app/ide-desktop/lib/dashboard/src/layouts/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ function EditorInternal(props: EditorInternalProps) {
[remoteBackend]
)

const renameProject = React.useCallback(
(newName: string) => {
const backend = React.useMemo(
() => {
let backend: Backend | null
switch (projectStartupInfo.backendType) {
case backendModule.BackendType.local:
Expand All @@ -107,6 +107,12 @@ function EditorInternal(props: EditorInternalProps) {
backend = remoteBackend
break
}
return backend
}, [localBackend, remoteBackend, projectStartupInfo.backendType]
)

const renameProject = React.useCallback(
(newName: string) => {
const { id: projectId, parentId, title } = projectStartupInfo.projectAsset
backend
?.updateProject(
Expand All @@ -121,7 +127,7 @@ function EditorInternal(props: EditorInternalProps) {
e => toastAndLog('renameProjectError', e)
)
},
[remoteBackend, localBackend, projectStartupInfo, toastAndLog]
[backend, projectStartupInfo.projectAsset, toastAndLog]
)

React.useEffect(() => {
Expand Down Expand Up @@ -162,6 +168,7 @@ function EditorInternal(props: EditorInternalProps) {
ignoreParamsRegex: IGNORE_PARAMS_REGEX,
logEvent,
renameProject,
backend,
}
}
}, [
Expand All @@ -175,6 +182,7 @@ function EditorInternal(props: EditorInternalProps) {
hidden,
logEvent,
renameProject,
backend,
])

if (AppRunner == null) {
Expand Down
1 change: 1 addition & 0 deletions app/ide-desktop/lib/dashboard/src/services/Backend.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as React from 'react'
import * as backend from 'enso-common/src/services/Backend'
import Backend from 'enso-common/src/services/Backend'

export * from 'enso-common/src/services/Backend'
export default Backend

Expand Down
3 changes: 3 additions & 0 deletions app/ide-desktop/lib/types/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/** @file Interfaces common to multiple modules. */
import type * as React from 'react'

import type Backend from 'enso-common/src/services/Backend'

// ======================================
// === Globally accessible interfaces ===
// ======================================
Expand All @@ -22,6 +24,7 @@ interface EditorProps {
metadata?: object | null
) => void
readonly renameProject: (newName: string) => void
readonly backend: Backend | null
}

/** The value passed from the entrypoint to the dashboard, which enables the dashboard to
Expand Down

0 comments on commit 3bb22b4

Please sign in to comment.