robobyte-front-builder 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/pages/viewer/[id]/index.js +12 -88
package/package.json
CHANGED
|
@@ -1,43 +1,21 @@
|
|
|
1
1
|
import { useRouter } from 'next/router'
|
|
2
|
-
import { useEffect, useState, useContext
|
|
3
|
-
import { Box, Typography, CircularProgress, Grid
|
|
2
|
+
import { useEffect, useState, useContext } from 'react'
|
|
3
|
+
import { Box, Typography, CircularProgress, Grid } from '@mui/material'
|
|
4
4
|
import { SystemContext } from 'context/SystemContext'
|
|
5
5
|
import { Endpoints, Services } from 'services/Endpoints'
|
|
6
6
|
import ProductionViewer from 'views/builder/viewer/ProductionViewer'
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Finds the parent group of a viewId in the navigator config items tree.
|
|
10
|
-
* Returns the array of siblings (all dynamic children of that parent).
|
|
11
|
-
*
|
|
12
|
-
* nav.config.items shape:
|
|
13
|
-
* [ { title, children: [ { title, type, viewId }, ... ] }, ... ]
|
|
14
|
-
*/
|
|
15
|
-
function findSiblings(navConfig, viewId) {
|
|
16
|
-
if (!navConfig?.items || viewId == null) return []
|
|
17
|
-
for (const group of navConfig.items) {
|
|
18
|
-
const children = group.children || []
|
|
19
|
-
const dynamicChildren = children.filter(c => c.type === 'dynamic' && c.viewId != null)
|
|
20
|
-
const found = dynamicChildren.find(c => Number(c.viewId) === Number(viewId))
|
|
21
|
-
if (found) return dynamicChildren
|
|
22
|
-
}
|
|
23
|
-
return []
|
|
24
|
-
}
|
|
25
|
-
|
|
26
8
|
export default function ViewPage() {
|
|
27
9
|
const router = useRouter()
|
|
28
10
|
const { id } = router.query
|
|
29
11
|
const systemContext = useContext(SystemContext)
|
|
30
12
|
const viewRegistry = systemContext.nav?.registry || {}
|
|
31
|
-
const navConfig = systemContext.nav?.config
|
|
32
13
|
|
|
33
14
|
const [schema, setSchema] = useState({})
|
|
34
15
|
const [viewMetaData, setViewMetaData] = useState({})
|
|
35
16
|
const [loading, setLoading] = useState(true)
|
|
36
17
|
const [error, setError] = useState(null)
|
|
37
18
|
|
|
38
|
-
// Sibling pages under the same root section — used for horizontal sub-nav tabs
|
|
39
|
-
const siblings = useMemo(() => findSiblings(navConfig, id), [navConfig, id])
|
|
40
|
-
|
|
41
19
|
const handleGetView = async (viewId) => {
|
|
42
20
|
try {
|
|
43
21
|
setLoading(true)
|
|
@@ -83,79 +61,25 @@ export default function ViewPage() {
|
|
|
83
61
|
)
|
|
84
62
|
}
|
|
85
63
|
|
|
86
|
-
// Error state
|
|
87
64
|
if (error) {
|
|
88
65
|
const viewId = Number(id)
|
|
89
66
|
const view = viewRegistry[viewId]
|
|
90
67
|
|
|
91
68
|
return (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
<Typography variant="body2" sx={{ mt: 2 }}>
|
|
99
|
-
View #{viewId} {view ? `(${view.name})` : ''} has not been created yet.
|
|
100
|
-
</Typography>
|
|
101
|
-
</Box>
|
|
102
|
-
</>
|
|
69
|
+
<Box sx={{ p: 6, textAlign: 'center' }}>
|
|
70
|
+
<Typography variant="h4">Coming soon 🚧</Typography>
|
|
71
|
+
<Typography variant="body2" sx={{ mt: 2 }}>
|
|
72
|
+
View #{viewId} {view ? `(${view.name})` : ''} has not been created yet.
|
|
73
|
+
</Typography>
|
|
74
|
+
</Box>
|
|
103
75
|
)
|
|
104
76
|
}
|
|
105
77
|
|
|
106
|
-
// Success state
|
|
107
78
|
return (
|
|
108
|
-
<
|
|
109
|
-
{
|
|
110
|
-
<
|
|
111
|
-
)}
|
|
112
|
-
<Grid container>
|
|
113
|
-
<Grid item size={12}>
|
|
114
|
-
<ProductionViewer schema={schema} />
|
|
115
|
-
</Grid>
|
|
79
|
+
<Grid container>
|
|
80
|
+
<Grid item size={12}>
|
|
81
|
+
<ProductionViewer schema={schema} />
|
|
116
82
|
</Grid>
|
|
117
|
-
</
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Horizontal sub-navigation tabs shown at the top of the viewer page
|
|
123
|
-
* when the current view has sibling pages under the same root section.
|
|
124
|
-
*/
|
|
125
|
-
function HorizontalSubNav({ siblings, currentId, router }) {
|
|
126
|
-
const currentIndex = siblings.findIndex(s => Number(s.viewId) === Number(currentId))
|
|
127
|
-
const activeTab = currentIndex >= 0 ? currentIndex : 0
|
|
128
|
-
|
|
129
|
-
const handleChange = (_, newIndex) => {
|
|
130
|
-
const target = siblings[newIndex]
|
|
131
|
-
if (target?.viewId != null) {
|
|
132
|
-
router.push(`/viewer/${target.viewId}`)
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
<Box
|
|
138
|
-
sx={{
|
|
139
|
-
borderBottom: 1,
|
|
140
|
-
borderColor: 'divider',
|
|
141
|
-
mb: 2,
|
|
142
|
-
backgroundColor: 'background.paper',
|
|
143
|
-
px: 2,
|
|
144
|
-
}}
|
|
145
|
-
>
|
|
146
|
-
<Tabs
|
|
147
|
-
value={activeTab}
|
|
148
|
-
onChange={handleChange}
|
|
149
|
-
variant="scrollable"
|
|
150
|
-
scrollButtons="auto"
|
|
151
|
-
>
|
|
152
|
-
{siblings.map((sibling) => (
|
|
153
|
-
<Tab
|
|
154
|
-
key={sibling.viewId}
|
|
155
|
-
label={sibling.title}
|
|
156
|
-
/>
|
|
157
|
-
))}
|
|
158
|
-
</Tabs>
|
|
159
|
-
</Box>
|
|
83
|
+
</Grid>
|
|
160
84
|
)
|
|
161
85
|
}
|