@@ -5,7 +5,7 @@ import React, { FC, useEffect, useState } from 'react';
5
5
import '../scss/App.scss' ;
6
6
7
7
import { useDispatch , useSelector } from "react-redux" ;
8
- import {
8
+ import {
9
9
DataFormulatorState ,
10
10
dfActions ,
11
11
fetchAvailableModels ,
@@ -58,6 +58,7 @@ import { ActionSubscription, subscribe, unsubscribe } from './embed';
58
58
import dfLogo from '../assets/df-logo.png' ;
59
59
import { Popup } from '../components/Popup' ;
60
60
import { ModelSelectionButton } from '../views/ModelSelectionDialog' ;
61
+ import { TableCopyDialogV2 } from '../views/TableSelectionView' ;
61
62
62
63
const AppBar = styled ( MuiAppBar ) ( ( { theme } ) => ( {
63
64
color : 'black' ,
@@ -70,7 +71,7 @@ const AppBar = styled(MuiAppBar)(({ theme }) => ({
70
71
} ) ,
71
72
} ) ) ;
72
73
73
- declare module '@mui/material/styles' {
74
+ declare module '@mui/material/styles' {
74
75
interface Palette {
75
76
derived : Palette [ 'primary' ] ;
76
77
custom : Palette [ 'primary' ] ;
@@ -97,52 +98,52 @@ export const ImportStateButton: React.FC<{}> = ({ }) => {
97
98
let savedState = JSON . parse ( text ) ;
98
99
dispatch ( dfActions . loadState ( savedState ) ) ;
99
100
} catch {
100
-
101
+
101
102
}
102
103
} ) ;
103
104
}
104
105
}
105
106
} ;
106
107
107
-
108
+
108
109
return < Tooltip title = "load a saved session" >
109
- < Button variant = "text" color = "primary"
110
- //endIcon={<InputIcon />}
111
- >
112
- < Input inputProps = { { accept : '.dfstate' , multiple : false } } id = "upload-data-file"
113
- type = "file" sx = { { display : 'none' } } aria-hidden = { true }
114
- ref = { $uploadStateFile } onChange = { handleFileUpload }
115
- />
116
- Import
117
- </ Button >
118
- </ Tooltip > ;
110
+ < Button variant = "text" color = "primary"
111
+ //endIcon={<InputIcon />}
112
+ >
113
+ < Input inputProps = { { accept : '.dfstate' , multiple : false } } id = "upload-data-file"
114
+ type = "file" sx = { { display : 'none' } } aria-hidden = { true }
115
+ ref = { $uploadStateFile } onChange = { handleFileUpload }
116
+ />
117
+ Import
118
+ </ Button >
119
+ </ Tooltip > ;
119
120
}
120
121
121
- export const ExportStateButton : React . FC < { } > = ( { } ) => {
122
+ export const ExportStateButton : React . FC < { } > = ( { } ) => {
122
123
const fullStateJson = useSelector ( ( state : DataFormulatorState ) => JSON . stringify ( state ) ) ;
123
-
124
+
124
125
return < Tooltip title = "save session locally" >
125
- < Button variant = "text" onClick = { ( ) => {
126
+ < Button variant = "text" onClick = { ( ) => {
126
127
function download ( content : string , fileName : string , contentType : string ) {
127
- let a = document . createElement ( "a" ) ;
128
- let file = new Blob ( [ content ] , { type : contentType } ) ;
129
- a . href = URL . createObjectURL ( file ) ;
130
- a . download = fileName ;
131
- a . click ( ) ;
132
- }
133
- download ( fullStateJson , `data-formulator.${ new Date ( ) . toISOString ( ) } .dfstate` , 'text/plain' ) ;
134
- } }
135
- //endIcon={<OutputIcon />}
128
+ let a = document . createElement ( "a" ) ;
129
+ let file = new Blob ( [ content ] , { type : contentType } ) ;
130
+ a . href = URL . createObjectURL ( file ) ;
131
+ a . download = fileName ;
132
+ a . click ( ) ;
133
+ }
134
+ download ( fullStateJson , `data-formulator.${ new Date ( ) . toISOString ( ) } .dfstate` , 'text/plain' ) ;
135
+ } }
136
+ //endIcon={<OutputIcon />}
136
137
>
137
- Export
138
+ Export
138
139
</ Button >
139
140
</ Tooltip >
140
141
}
141
142
142
143
143
144
//type AppProps = ConnectedProps<typeof connector>;
144
145
145
- export const toolName = "Data Formulator"
146
+ export const toolName = "Data Formulator"
146
147
147
148
export interface AppFCProps {
148
149
}
@@ -154,12 +155,12 @@ export const AppFC: FC<AppFCProps> = function AppFC(appProps) {
154
155
const tables = useSelector ( ( state : DataFormulatorState ) => state . tables ) ;
155
156
156
157
// if the user has logged in
157
- const [ userInfo , setUserInfo ] = useState < { name : string , userId : string } | undefined > ( undefined ) ;
158
+ const [ userInfo , setUserInfo ] = useState < { name : string , userId : string } | undefined > ( undefined ) ;
158
159
159
- const [ popupConfig , setPopupConfig ] = useState < PopupConfig > ( { } ) ;
160
+ const [ popupConfig , setPopupConfig ] = useState < PopupConfig > ( { } ) ;
160
161
161
162
const dispatch = useDispatch < AppDispatch > ( ) ;
162
-
163
+
163
164
useEffect ( ( ) => {
164
165
const subscription : ActionSubscription = {
165
166
loadData : ( table : DictTable ) => {
@@ -179,23 +180,23 @@ export const AppFC: FC<AppFCProps> = function AppFC(appProps) {
179
180
180
181
useEffect ( ( ) => {
181
182
fetch ( '/.auth/me' )
182
- . then ( function ( response ) { return response . json ( ) ; } )
183
- . then ( function ( result ) {
184
- if ( Array . isArray ( result ) && result . length > 0 ) {
185
- let authInfo = result [ 0 ] ;
186
- let userInfo = {
187
- name : authInfo [ 'user_claims' ] . find ( ( item : any ) => item . typ == 'name' ) ?. val || '' ,
188
- userId : authInfo [ 'user_id' ]
183
+ . then ( function ( response ) { return response . json ( ) ; } )
184
+ . then ( function ( result ) {
185
+ if ( Array . isArray ( result ) && result . length > 0 ) {
186
+ let authInfo = result [ 0 ] ;
187
+ let userInfo = {
188
+ name : authInfo [ 'user_claims' ] . find ( ( item : any ) => item . typ == 'name' ) ?. val || '' ,
189
+ userId : authInfo [ 'user_id' ]
190
+ }
191
+ setUserInfo ( userInfo ) ;
192
+ // console.log("logging info")
193
+ // console.log(userInfo);
189
194
}
190
- setUserInfo ( userInfo ) ;
191
- // console.log("logging info")
192
- // console.log(userInfo);
193
- }
194
-
195
- } ) . catch ( err => {
196
- //user is not logged in, do not show logout button
197
- //console.error(err)
198
- } ) ;
195
+
196
+ } ) . catch ( err => {
197
+ //user is not logged in, do not show logout button
198
+ //console.error(err)
199
+ } ) ;
199
200
} , [ ] )
200
201
201
202
const [ resetDialogOpen , setResetDialogOpen ] = useState < boolean > ( false ) ;
@@ -264,18 +265,20 @@ export const AppFC: FC<AppFCProps> = function AppFC(appProps) {
264
265
265
266
let appBar = [
266
267
< AppBar className = "app-bar" position = "static" key = "app-bar-main" >
267
- < Toolbar variant = "dense" sx = { { backgroundColor : betaMode ? 'lavender' : '' } } >
268
- < Button href = { "/" } sx = { { display : "flex" , flexDirection : "row" , textTransform : "none" ,
269
- backgroundColor : 'transparent' ,
270
- "&:hover" : {
271
- backgroundColor : "transparent"
272
- } } } color = "inherit" >
273
- < Box component = "img" sx = { { height : 32 , marginRight : "12px" } } alt = "" src = { dfLogo } />
268
+ < Toolbar variant = "dense" sx = { { backgroundColor : betaMode ? 'lavender' : '' } } >
269
+ < Button href = { "/" } sx = { {
270
+ display : "flex" , flexDirection : "row" , textTransform : "none" ,
271
+ backgroundColor : 'transparent' ,
272
+ "&:hover" : {
273
+ backgroundColor : "transparent"
274
+ }
275
+ } } color = "inherit" >
276
+ < Box component = "img" sx = { { height : 32 , marginRight : "12px" } } alt = "" src = { dfLogo } />
274
277
< Typography variant = "h6" noWrap component = "h1" sx = { { fontWeight : 300 , display : { xs : 'none' , sm : 'block' } } } >
275
- { toolName } { betaMode ? "β" : "" } { process . env . NODE_ENV == "development" ? "" : "" }
278
+ { toolName } { betaMode ? "β" : "" } { process . env . NODE_ENV == "development" ? "" : "" }
276
279
</ Typography >
277
280
</ Button >
278
- < Box sx = { { flexGrow : 1 , textAlign : 'center' , display : 'flex' , justifyContent : 'center' } } >
281
+ < Box sx = { { flexGrow : 1 , textAlign : 'center' , display : 'flex' , justifyContent : 'center' } } >
279
282
{ switchers }
280
283
</ Box >
281
284
< Box sx = { { display : 'flex' , fontSize : 14 } } >
@@ -286,28 +289,30 @@ export const AppFC: FC<AppFCProps> = function AppFC(appProps) {
286
289
<Divider orientation="vertical" variant="middle" flexItem /> */ }
287
290
< ModelSelectionButton />
288
291
< Divider orientation = "vertical" variant = "middle" flexItem />
292
+ < TableCopyDialogV2 buttonElement = { "ADD TABLE" } disabled = { false } />
293
+ < Divider orientation = "vertical" variant = "middle" flexItem />
289
294
< ExportStateButton />
290
295
< ImportStateButton />
291
296
< Divider orientation = "vertical" variant = "middle" flexItem />
292
- < Button variant = "text" onClick = { ( ) => { setResetDialogOpen ( true ) } } endIcon = { < PowerSettingsNewIcon /> } >
297
+ < Button variant = "text" onClick = { ( ) => { setResetDialogOpen ( true ) } } endIcon = { < PowerSettingsNewIcon /> } >
293
298
Reset session
294
299
</ Button >
295
- < Popup popupConfig = { popupConfig } appConfig = { appConfig } table = { tables [ 0 ] } />
296
- < Dialog onClose = { ( ) => { setResetDialogOpen ( false ) } } open = { resetDialogOpen } >
297
- < DialogTitle sx = { { display : "flex" , alignItems : "center" } } > Reset Session?</ DialogTitle >
300
+ < Popup popupConfig = { popupConfig } appConfig = { appConfig } table = { tables [ 0 ] } />
301
+ < Dialog onClose = { ( ) => { setResetDialogOpen ( false ) } } open = { resetDialogOpen } >
302
+ < DialogTitle sx = { { display : "flex" , alignItems : "center" } } > Reset Session?</ DialogTitle >
298
303
< DialogContent >
299
304
< DialogContentText >
300
305
< Typography > All unexported content (charts, derived data, concepts) will be lost upon reset.</ Typography >
301
306
</ DialogContentText >
302
307
</ DialogContent >
303
308
< DialogActions >
304
- < Button onClick = { ( ) => { dispatch ( dfActions . resetState ( ) ) ; setResetDialogOpen ( false ) ; } } endIcon = { < PowerSettingsNewIcon /> } > reset session </ Button >
305
- < Button onClick = { ( ) => { setResetDialogOpen ( false ) ; } } > cancel</ Button >
309
+ < Button onClick = { ( ) => { dispatch ( dfActions . resetState ( ) ) ; setResetDialogOpen ( false ) ; } } endIcon = { < PowerSettingsNewIcon /> } > reset session </ Button >
310
+ < Button onClick = { ( ) => { setResetDialogOpen ( false ) ; } } > cancel</ Button >
306
311
</ DialogActions >
307
312
</ Dialog >
308
313
{ userInfo && < >
309
314
< Divider orientation = "vertical" variant = "middle" flexItem />
310
- < Divider orientation = "vertical" variant = "middle" flexItem sx = { { marginRight : "6px" } } />
315
+ < Divider orientation = "vertical" variant = "middle" flexItem sx = { { marginRight : "6px" } } />
311
316
< Avatar key = "user-avatar" { ...stringAvatar ( userInfo ?. name || 'U' ) } />
312
317
< Button variant = "text" className = "ml-auto" href = "/.auth/logout" > Sign out</ Button >
313
318
</ > }
@@ -351,15 +356,15 @@ export const AppFC: FC<AppFCProps> = function AppFC(appProps) {
351
356
element : < About /> ,
352
357
} , {
353
358
path : "*" ,
354
- element : < DataFormulatorFC /> ,
355
- errorElement : < Box sx = { { width : "100%" , height : "100%" , display : "flex" } } >
356
- < Typography color = "gray" sx = { { margin : "150px auto" } } > An error has occurred, please < Link href = "/" > refresh the session</ Link > . If the problem still exists, click close session.</ Typography >
357
- </ Box >
359
+ element : < DataFormulatorFC /> ,
360
+ errorElement : < Box sx = { { width : "100%" , height : "100%" , display : "flex" } } >
361
+ < Typography color = "gray" sx = { { margin : "150px auto" } } > An error has occurred, please < Link href = "/" > refresh the session</ Link > . If the problem still exists, click close session.</ Typography >
362
+ </ Box >
358
363
}
359
364
] ) ;
360
365
361
- let app =
362
- < Box sx = { { flexGrow : 1 , height : '100%' , overflow : "hidden" , display : "flex" , flexDirection : "column" } } >
366
+ let app =
367
+ < Box sx = { { flexGrow : 1 , height : '100%' , overflow : "hidden" , display : "flex" , flexDirection : "column" } } >
363
368
{ appBar }
364
369
< RouterProvider router = { router } />
365
370
< MessageSnackbar />
@@ -376,7 +381,7 @@ function stringAvatar(name: string) {
376
381
let displayName = ""
377
382
try {
378
383
let nameSplit = name . split ( ' ' )
379
- displayName = `${ nameSplit [ 0 ] [ 0 ] } ${ nameSplit . length > 1 ? nameSplit [ nameSplit . length - 1 ] [ 0 ] : '' } `
384
+ displayName = `${ nameSplit [ 0 ] [ 0 ] } ${ nameSplit . length > 1 ? nameSplit [ nameSplit . length - 1 ] [ 0 ] : '' } `
380
385
} catch {
381
386
displayName = name ? name [ 0 ] : "?" ;
382
387
}
0 commit comments