Skip to content

Commit 0ad725d

Browse files
authored
chore: (studio) AI status updates (#32511)
1 parent b81c5a0 commit 0ad725d

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

packages/app/src/runner/SpecRunnerOpenMode.vue

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
:event-manager="eventManager"
9999
:studio-status="studioStatus"
100100
:aut-url-selector="autUrlSelector"
101+
:user-project-status-store="userProjectStatusStore"
102+
:has-requested-project-access="hasRequestedProjectAccess"
103+
:request-project-access-mutation="requestProjectAccessMutation"
101104
/>
102105
</HideDuringScreenshot>
103106
</template>
@@ -122,7 +125,7 @@ import ScreenshotHelperPixels from './screenshot/ScreenshotHelperPixels.vue'
122125
import { useScreenshotStore } from '../store/screenshot-store'
123126
import ChooseExternalEditorModal from '@packages/frontend-shared/src/gql-components/ChooseExternalEditorModal.vue'
124127
import { useMutation, gql } from '@urql/vue'
125-
import { SpecRunnerOpenMode_OpenFileInIdeDocument, StudioStatus_ChangeDocument } from '../generated/graphql'
128+
import { SpecRunnerOpenMode_OpenFileInIdeDocument, StudioStatus_ChangeDocument, SpecRunner_Studio_RequestAccessDocument } from '../generated/graphql'
126129
import type { SpecRunnerFragment } from '../generated/graphql'
127130
import { usePreferences } from '../composables/usePreferences'
128131
import ScriptError from './ScriptError.vue'
@@ -136,6 +139,7 @@ import { runnerConstants } from './runner-constants'
136139
import { useStudioStore } from '../store/studio-store'
137140
import StudioPanel from '../studio/StudioPanel.vue'
138141
import { useSubscription } from '../graphql'
142+
import { useUserProjectStatusStore } from '@packages/frontend-shared/src/store/user-project-status-store'
139143
140144
// this is used by the StudioPanel to access the AUT URL input
141145
const autUrlSelector = '.aut-url-input'
@@ -149,6 +153,8 @@ const {
149153
collapsedNavBarWidth,
150154
} = runnerConstants
151155
156+
const userProjectStatusStore = useUserProjectStatusStore()
157+
152158
gql`
153159
fragment SpecRunner_Preferences on Query {
154160
localSettings {
@@ -167,6 +173,32 @@ fragment SpecRunner_Preferences on Query {
167173
gql`
168174
fragment SpecRunner_Studio on Query {
169175
cloudStudioRequested
176+
currentProject {
177+
id
178+
projectId
179+
cloudProject {
180+
__typename
181+
... on CloudProjectUnauthorized {
182+
message
183+
hasRequestedAccess
184+
}
185+
... on CloudProject {
186+
id
187+
}
188+
}
189+
}
190+
}
191+
`
192+
193+
gql`
194+
mutation SpecRunner_Studio_RequestAccess( $projectId: String! ) {
195+
cloudProjectRequestAccess(projectSlug: $projectId) {
196+
__typename
197+
... on CloudProjectUnauthorized {
198+
message
199+
hasRequestedAccess
200+
}
201+
}
170202
}
171203
`
172204
@@ -232,6 +264,12 @@ const {
232264
233265
const studioStore = useStudioStore()
234266
267+
const hasRequestedProjectAccess = computed(() => {
268+
return (props.gql.currentProject?.cloudProject?.__typename === 'CloudProjectUnauthorized' && props.gql.currentProject?.cloudProject?.hasRequestedAccess) ?? false
269+
})
270+
271+
const requestProjectAccessMutation = useMutation(SpecRunner_Studio_RequestAccessDocument)
272+
235273
const handleStudioPanelClose = () => {
236274
eventManager.emit('studio:cancel', undefined)
237275
}

packages/app/src/studio/StudioPanel.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
import { ref, onMounted, onBeforeUnmount, watch } from 'vue'
2929
import { init, loadRemote, registerRemotes } from '@module-federation/runtime'
3030
import type { StudioAppDefaultShape, StudioPanelShape } from './studio-app-types'
31+
import type { UserProjectStatusStore } from '@cy/store/user-project-status-store'
3132
import LoadingStudioPanel from './LoadingStudioPanel.vue'
3233
import StudioErrorPanel from './StudioErrorPanel.vue'
3334
import type { EventManager } from '../runner/event-manager'
34-
import { useMutation, gql } from '@urql/vue'
35+
import { useMutation, gql, UseMutationResponse } from '@urql/vue'
3536
3637
// Mirrors the ReactDOM.Root type since incorporating those types
3738
// messes up vue typing elsewhere
@@ -53,6 +54,9 @@ const props = defineProps<{
5354
studioStatus: string | null
5455
cloudStudioSessionId?: string
5556
autUrlSelector: string
57+
userProjectStatusStore: UserProjectStatusStore
58+
hasRequestedProjectAccess: boolean
59+
requestProjectAccessMutation: UseMutationResponse<any, any>
5660
}>()
5761
5862
interface StudioApp { default: StudioAppDefaultShape }
@@ -79,6 +83,9 @@ const maybeRenderReactComponent = () => {
7983
onStudioPanelClose: props.onStudioPanelClose,
8084
studioSessionId: props.cloudStudioSessionId,
8185
autUrlSelector: props.autUrlSelector,
86+
userProjectStatusStore: props.userProjectStatusStore,
87+
hasRequestedProjectAccess: props.hasRequestedProjectAccess,
88+
requestProjectAccessMutation: props.requestProjectAccessMutation,
8289
})
8390
8491
// Store the react root in a weak map keyed by the container. We do this so that we have a reference

packages/app/src/studio/studio-app-types.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,38 @@
22
// `studio` bundle. It is downloaded and copied to the app.
33
// It should not be modified directly in the app.
44

5+
import type { CloudStatus } from '@cy/store/user-project-status-store'
6+
57
export type RecordingState = 'recording' | 'paused' | 'disabled'
68

9+
export interface UserProjectStatusStore {
10+
user: {
11+
isLoggedIn: boolean
12+
}
13+
project: {
14+
isProjectConnected: boolean
15+
isNotAuthorized: boolean
16+
}
17+
openLoginConnectModal: (options: { utmMedium: string }) => void
18+
cloudStatus: CloudStatus
19+
projectId: string
20+
}
21+
22+
export interface RequestProjectAccessMutationResult {
23+
data?: {
24+
cloudProjectRequestAccess: {
25+
hasRequestedAccess: boolean
26+
}
27+
}
28+
error?: any
29+
}
30+
31+
export interface RequestProjectAccessMutation {
32+
executeMutation: (variables: {
33+
projectId: string
34+
}) => Promise<RequestProjectAccessMutationResult>
35+
}
36+
737
export interface StudioPanelProps {
838
canAccessStudioAI: boolean
939
onStudioPanelClose?: () => void
@@ -13,6 +43,10 @@ export interface StudioPanelProps {
1343
useCypress?: CypressShape
1444
autUrlSelector?: string
1545
studioAiAvailable?: boolean
46+
userProjectStatusStore: UserProjectStatusStore
47+
hasRequestedProjectAccess: boolean
48+
requestProjectAccessMutation: RequestProjectAccessMutation
49+
1650
}
1751

1852
export type StudioPanelShape = (props: StudioPanelProps) => JSX.Element

0 commit comments

Comments
 (0)