-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSettings.tsx
177 lines (167 loc) · 6.05 KB
/
Settings.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { useEffect, useState } from 'react'
import { Grid, Tab, Tabs, Typography, Button } from '@mui/material'
import { Box } from '@mui/system'
import { SyntheticEvent } from 'react'
import CommonSettings from './common/Common'
import UniqueToGR from './uniqueToGR/UniqueToGR'
import UniqueToInteraction from './uniqueToInteraction/UniqueToInteraction'
import Deterministic from './deterministic/Deterministic'
import Blocking from './blocking/Blocking'
import GoldenRecordLists from './goldenRecordLists/GoldenRecordLists'
import InteractiveNode from './interactiveNode/InteractiveNode'
import { CustomTabPanel, a11yProps } from './deterministic/BasicTabs'
import { Configuration } from 'types/Configuration'
import { generateId } from 'utils/helpers'
import Probabilistic from './probabilistic/Probabilistic'
import { useConfig } from 'hooks/useConfig'
import { useSnackbar } from 'notistack'
import { useConfiguration } from 'hooks/useUIConfiguration'
const Settings = () => {
const [value, setValue] = useState(0)
const {configuration} = useConfiguration()
const [configurationData, setConfigurationData] = useState(() => {
const storedData = localStorage.getItem('configuration')
return storedData
? generateId(JSON.parse(storedData))
: ({} as Configuration)
})
const [isSaving, setIsSaving] = useState<boolean>(false)
const { apiClient } = useConfig()
const handleChange = (event: SyntheticEvent, newValue: number) => {
setValue(newValue)
}
const { enqueueSnackbar } = useSnackbar()
const handleSave = async () => {
setIsSaving(true)
const response = await apiClient.saveConfiguration()
setIsSaving(false)
if (response && response.response === 'ok') {
enqueueSnackbar(`Successfully saved configuration`, {
variant: 'success'
})
}
if (response && response.response === 'error') {
enqueueSnackbar(`Error saving configuration`, {
variant: 'error'
})
console.log('handleSave error', response.data)
}
}
useEffect(() => {
const handleStorageChange = (event: StorageEvent) => {
if (event.key === 'configuration') {
const newConfigData = localStorage.getItem('configuration')
setConfigurationData(
newConfigData
? generateId(JSON.parse(newConfigData))
: ({} as Configuration)
)
}
}
window.addEventListener('storage', handleStorageChange)
return () => {
window.removeEventListener('storage', handleStorageChange)
}
}, [])
useEffect(() => {
const storedData = localStorage.getItem('configuration')
if (storedData) {
setConfigurationData(generateId(JSON.parse(storedData)))
}
}, [])
return (
<Grid container spacing={4}>
<Grid item md={4}>
<div
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
justifyItems: 'center',
alignContent: 'center',
gap: 0,
width: '100%'
}}
>
<div className="shapes-container">
<InteractiveNode />
</div>
</div>
</Grid>
<Grid item md={8}>
<Box sx={{ width: '100%' }}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs
value={value}
onChange={handleChange}
aria-label="tabs"
variant="scrollable"
>
<Tab label="Common" {...a11yProps(0)} />
{/* <Tab label="Unique to Golden Record" {...a11yProps(1)} />
<Tab label="Unique to Interaction" {...a11yProps(2)} />
<Tab label="Golden Records Lists" {...a11yProps(3)} /> */}
<Tab label="Deterministic" {...a11yProps(1)} />
<Tab label="Blocking" {...a11yProps(2)} />
<Tab label="Probabilistic" {...a11yProps(3)} />
</Tabs>
</Box>
<CustomTabPanel value={value} index={0}>
<Typography variant="h5" sx={{ py: 3 }}>
Setup common properties
</Typography>
<CommonSettings />
</CustomTabPanel>
{/* <CustomTabPanel value={value} index={1}>
<Typography variant="h5" sx={{ py: 3 }}>
Setup properties that are unique to the golden record
</Typography>
<UniqueToGR />
</CustomTabPanel> */}
{/* <CustomTabPanel value={value} index={2}>
<Typography variant="h5" sx={{ py: 3 }}>
Setup properties that are unique to the interaction
</Typography>
<UniqueToInteraction />
</CustomTabPanel> */}
{/* <CustomTabPanel value={value} index={3}>
<Typography variant="h5" sx={{ py: 3 }}>
Setup properties for Golden record lists
</Typography>
<GoldenRecordLists />
</CustomTabPanel> */}
<CustomTabPanel value={value} index={1}>
<Deterministic />
</CustomTabPanel>
<CustomTabPanel value={value} index={2}>
<Blocking />
</CustomTabPanel>
<CustomTabPanel value={value} index={3}>
<Typography variant="h5" sx={{ py: 3 }}>
<Probabilistic />
</Typography>
</CustomTabPanel>
<Box sx={{ display: 'flex', justifyContent: 'space-between', my: 2 }}>
<Box sx={{ display: 'flex', gap: 1 }}>
{/* <Button variant="outlined" color="secondary">Edit</Button>
<Button variant="outlined" color="secondary">Clear</Button>
<Button variant="outlined" color="secondary">Set to Reference</Button> */}
</Box>
<Box>
<Button
variant="contained"
color="primary"
onClick={handleSave}
disabled={isSaving}
>
{isSaving ? 'Saving...' : 'Save'}
</Button>
</Box>
</Box>
</Box>
</Grid>
</Grid>
)
}
export default Settings