11import React , { useState , useEffect } from "react" ;
2- import { HTMLTable , Button , MenuItem , Spinner , Label } from "@blueprintjs/core" ;
2+ import {
3+ Button ,
4+ Checkbox ,
5+ HTMLTable ,
6+ Label ,
7+ MenuItem ,
8+ Spinner ,
9+ Tab ,
10+ TabId ,
11+ Tabs ,
12+ } from "@blueprintjs/core" ;
13+ import Description from "roamjs-components/components/Description" ;
314import { Select } from "@blueprintjs/select" ;
15+ import { getSetting , setSetting } from "~/utils/extensionSettings" ;
416import {
517 getSupabaseContext ,
618 getLoggedInClient ,
@@ -91,7 +103,7 @@ const NodeTable = ({ nodes }: { nodes: PConceptFull[] }) => {
91103 ) ;
92104} ;
93105
94- const AdminPanel = ( ) => {
106+ const AdminPanel = ( ) : React . ReactElement => {
95107 const [ context , setContext ] = useState < SupabaseContext | null > ( null ) ;
96108 const [ supabase , setSupabase ] = useState < DGSupabaseClient | null > ( null ) ;
97109 const [ schemas , setSchemas ] = useState < NodeSignature [ ] > ( [ ] ) ;
@@ -101,6 +113,10 @@ const AdminPanel = () => {
101113 const [ loading , setLoading ] = useState ( true ) ;
102114 const [ loadingNodes , setLoadingNodes ] = useState ( true ) ;
103115 const [ error , setError ] = useState < string | null > ( null ) ;
116+ const [ selectedTabId , setSelectedTabId ] = useState < TabId > ( "admin" ) ;
117+ const [ useReifiedRelations , setUseReifiedRelations ] = useState < boolean > (
118+ getSetting ( "use-reified-relations" ) ,
119+ ) ;
104120
105121 useEffect ( ( ) => {
106122 let ignore = false ;
@@ -196,41 +212,83 @@ const AdminPanel = () => {
196212 }
197213
198214 return (
199- < >
200- < p >
201- Context:{ " " }
202- < code > { JSON . stringify ( { ...context , spacePassword : "****" } ) } </ code >
203- </ p >
204- { schemas . length > 0 ? (
205- < >
206- < Label >
207- Display:
208- < div className = "mx-2 inline-block" >
209- < Select
210- items = { schemas }
211- onItemSelect = { ( choice ) => {
212- setShowingSchema ( choice ) ;
213- } }
214- itemRenderer = { ( node , { handleClick, modifiers } ) => (
215- < MenuItem
216- active = { modifiers . active }
217- key = { node . sourceLocalId }
218- label = { node . name }
219- onClick = { handleClick }
220- text = { node . name }
215+ < Tabs
216+ onChange = { ( id ) => setSelectedTabId ( id ) }
217+ selectedTabId = { selectedTabId }
218+ renderActiveTabPanelOnly = { true }
219+ >
220+ < Tab
221+ id = "admin"
222+ title = "Admin"
223+ panel = {
224+ < div className = "flex flex-col gap-4 p-1" >
225+ < Checkbox
226+ defaultChecked = { useReifiedRelations }
227+ onChange = { ( e ) => {
228+ const target = e . target as HTMLInputElement ;
229+ setUseReifiedRelations ( target . checked ) ;
230+ setSetting ( "use-reified-relations" , target . checked ) ;
231+ } }
232+ labelElement = {
233+ < >
234+ Reified Relation Triples
235+ < Description
236+ description = {
237+ "When ON, relations are read/written as reifiedRelationUid in [[roam/js/discourse-graph/relations]]."
238+ }
221239 />
222- ) }
223- >
224- < Button text = { showingSchema . name } />
225- </ Select >
226- </ div >
227- </ Label >
228- < div > { loadingNodes ? < Spinner /> : < NodeTable nodes = { nodes } /> } </ div >
229- </ >
230- ) : (
231- < p > No node schemas found</ p >
232- ) }
233- </ >
240+ </ >
241+ }
242+ />
243+ </ div >
244+ }
245+ />
246+ < Tab
247+ id = "node-list"
248+ title = "Node list"
249+ panel = {
250+ < >
251+ < p >
252+ Context:{ " " }
253+ < code >
254+ { JSON . stringify ( { ...context , spacePassword : "****" } ) }
255+ </ code >
256+ </ p >
257+ { schemas . length > 0 ? (
258+ < >
259+ < Label >
260+ Display:
261+ < div className = "mx-2 inline-block" >
262+ < Select
263+ items = { schemas }
264+ onItemSelect = { ( choice ) => {
265+ setShowingSchema ( choice ) ;
266+ } }
267+ itemRenderer = { ( node , { handleClick, modifiers } ) => (
268+ < MenuItem
269+ active = { modifiers . active }
270+ key = { node . sourceLocalId }
271+ label = { node . name }
272+ onClick = { handleClick }
273+ text = { node . name }
274+ />
275+ ) }
276+ >
277+ < Button text = { showingSchema . name } />
278+ </ Select >
279+ </ div >
280+ </ Label >
281+ < div >
282+ { loadingNodes ? < Spinner /> : < NodeTable nodes = { nodes } /> }
283+ </ div >
284+ </ >
285+ ) : (
286+ < p > No node schemas found</ p >
287+ ) }
288+ </ >
289+ }
290+ />
291+ </ Tabs >
234292 ) ;
235293} ;
236294
0 commit comments