@@ -4,29 +4,14 @@ import {useVersionedClient} from '../../versionedClient'
4
4
import { Subscription } from 'rxjs'
5
5
import { WidgetContainer } from '../../containers/WidgetContainer'
6
6
import { DashboardWidgetContainer } from '../../components/DashboardWidgetContainer'
7
- import { DashboardWidget } from '../../types'
8
-
9
- export interface ProjectInfoProps {
10
- __experimental_before ?: DashboardWidget [ ]
11
- data : ProjectData [ ]
12
- }
13
-
14
- interface App {
15
- title : string
16
- rows ?: App [ ]
17
- value ?: string | { error : string }
18
- }
19
-
20
- interface ProjectData {
21
- title : string
22
- category ?: string
23
- }
7
+ import { type DashboardWidget } from '../../types'
8
+ import { type App , type ProjectInfoProps , type ProjectData , UserApplication } from './types'
24
9
25
10
function isUrl ( url ?: string ) {
26
11
return url && / ^ h t t p s ? : \/ \/ / . test ( `${ url } ` )
27
12
}
28
13
29
- function getGraphQlUrl ( projectId : string , dataset : string ) {
14
+ function getGraphQLUrl ( projectId : string , dataset : string ) {
30
15
return `https://${ projectId } .api.sanity.io/v1/graphql/${ dataset } /default`
31
16
}
32
17
@@ -43,8 +28,8 @@ const NO_DATA: ProjectData[] = []
43
28
44
29
export function ProjectInfo ( props : ProjectInfoProps ) {
45
30
const { __experimental_before = NO_EXPERIMENTAL , data = NO_DATA } = props
46
- const [ studioHost , setStudioHost ] = useState < string | { error : string } | undefined > ( )
47
- const [ graphqlApi , setGraphQlApi ] = useState < string | { error : string } | undefined > ( )
31
+ const [ studioApps , setStudioApps ] = useState < UserApplication [ ] | { error : string } | undefined > ( )
32
+ const [ graphQLApi , setGraphQLApi ] = useState < string | { error : string } | undefined > ( )
48
33
const versionedClient = useVersionedClient ( )
49
34
const { projectId = 'unknown' , dataset = 'unknown' } = versionedClient . config ( )
50
35
@@ -53,25 +38,13 @@ export function ProjectInfo(props: ProjectInfoProps) {
53
38
54
39
subscriptions . push (
55
40
versionedClient . observable
56
- . request < {
57
- studioHost : string
58
- metadata ?: { externalStudioHost ?: string }
59
- } > ( { uri : `/projects/${ projectId } ` , tag : 'dashboard.project-info.studio-host' } )
41
+ . request < UserApplication [ ] > ( { uri : '/user-applications' , tag : 'dashboard.project-info' } )
60
42
. subscribe ( {
61
- next : ( result ) => {
62
- if ( result . metadata ?. externalStudioHost ) {
63
- setStudioHost ( result . metadata . externalStudioHost )
64
- return
65
- }
66
-
67
- setStudioHost (
68
- result . studioHost ? `https://${ result . studioHost } .sanity.studio` : undefined ,
69
- )
70
- } ,
43
+ next : ( result ) => setStudioApps ( result . filter ( ( app ) => app . type === 'studio' ) ) ,
71
44
error : ( error ) => {
72
- console . error ( 'Error while looking for studioHost ' , error )
73
- setStudioHost ( {
74
- error : 'Something went wrong while looking up studioHost . See console.' ,
45
+ console . error ( 'Error while resolving user applications ' , error )
46
+ setStudioApps ( {
47
+ error : 'Something went wrong while resolving user applications . See console.' ,
75
48
} )
76
49
} ,
77
50
} ) ,
@@ -86,14 +59,14 @@ export function ProjectInfo(props: ProjectInfoProps) {
86
59
tag : 'dashboard.project-info.graphql-api' ,
87
60
} )
88
61
. subscribe ( {
89
- next : ( ) => setGraphQlApi ( getGraphQlUrl ( projectId , dataset ) ) ,
62
+ next : ( ) => setGraphQLApi ( getGraphQLUrl ( projectId , dataset ) ) ,
90
63
error : ( error ) => {
91
64
if ( error . statusCode === 404 ) {
92
- setGraphQlApi ( undefined )
65
+ setGraphQLApi ( undefined )
93
66
} else {
94
- console . error ( 'Error while looking for graphqlApi ' , error )
95
- setGraphQlApi ( {
96
- error : 'Something went wrong while looking up graphqlApi . See console.' ,
67
+ console . error ( 'Error while looking for graphQLApi ' , error )
68
+ setGraphQLApi ( {
69
+ error : 'Something went wrong while looking up graphQLApi . See console.' ,
97
70
} )
98
71
}
99
72
} ,
@@ -103,7 +76,7 @@ export function ProjectInfo(props: ProjectInfoProps) {
103
76
return ( ) => {
104
77
subscriptions . forEach ( ( s ) => s . unsubscribe ( ) )
105
78
}
106
- } , [ dataset , projectId , versionedClient , setGraphQlApi , setStudioHost ] )
79
+ } , [ dataset , projectId , versionedClient , setGraphQLApi ] )
107
80
108
81
const assembleTableRows = useMemo ( ( ) => {
109
82
let result : App [ ] = [
@@ -116,11 +89,16 @@ export function ProjectInfo(props: ProjectInfoProps) {
116
89
} ,
117
90
]
118
91
119
- // Handle any apps
120
- const apps : App [ ] = [
121
- studioHost ? { title : 'Studio' , value : studioHost } : null ,
122
- ...data . filter ( ( item ) => item . category === 'apps' ) ,
123
- ] . filter ( ( a ) : a is App => ! ! a )
92
+ const apps : App [ ] = data . filter ( ( item ) => item . category === 'apps' )
93
+
94
+ // Handle studios
95
+ ; ( Array . isArray ( studioApps ) ? studioApps : [ ] ) . forEach ( ( app ) => {
96
+ apps . push ( {
97
+ title : app . title || 'Studio' ,
98
+ value : app . urlType === 'internal' ? `https://${ app . appHost } .sanity.studio` : app . appHost ,
99
+ } )
100
+ } )
101
+
124
102
if ( apps . length > 0 ) {
125
103
result = result . concat ( [ { title : 'Apps' , rows : apps } ] )
126
104
}
@@ -134,7 +112,7 @@ export function ProjectInfo(props: ProjectInfoProps) {
134
112
{ title : 'GROQ' , value : getGroqUrl ( projectId , dataset ) } ,
135
113
{
136
114
title : 'GraphQL' ,
137
- value : ( typeof graphqlApi === 'object' ? 'Error' : graphqlApi ) ?? 'Not deployed' ,
115
+ value : ( typeof graphQLApi === 'object' ? 'Error' : graphQLApi ) ?? 'Not deployed' ,
138
116
} ,
139
117
] ,
140
118
} ,
@@ -157,7 +135,7 @@ export function ProjectInfo(props: ProjectInfoProps) {
157
135
} )
158
136
159
137
return result
160
- } , [ graphqlApi , studioHost , projectId , dataset , data ] )
138
+ } , [ graphQLApi , studioApps , projectId , dataset , data ] )
161
139
162
140
return (
163
141
< >
@@ -207,7 +185,7 @@ export function ProjectInfo(props: ProjectInfoProps) {
207
185
< Stack space = { 4 } paddingX = { 3 } role = "rowgroup" >
208
186
{ item . rows . map ( ( row ) => {
209
187
return (
210
- < Grid key = { row . title } columns = { 2 } role = "row" >
188
+ < Grid key = { ` ${ row . value } - ${ row . title } ` } columns = { 2 } role = "row" >
211
189
< Text weight = "medium" role = "rowheader" >
212
190
{ row . title }
213
191
</ Text >
0 commit comments