@stoker-platform/web-app 0.5.110 → 0.5.112
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/Breadcrumbs.tsx +1 -1
- package/src/Form.tsx +37 -39
- package/src/loadRoutes.tsx +1 -1
- package/src/utils/getRelationFields.ts +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @stoker-platform/web-app
|
|
2
2
|
|
|
3
|
+
## 0.5.112
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: fix role group issue
|
|
8
|
+
|
|
9
|
+
## 0.5.111
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- fix: hide convert button when target collection create access not granted
|
|
14
|
+
|
|
3
15
|
## 0.5.110
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
package/src/Breadcrumbs.tsx
CHANGED
|
@@ -59,7 +59,7 @@ export const Breadcrumbs = ({
|
|
|
59
59
|
const titleField = field.titleField
|
|
60
60
|
if (titleField && field.includeFields?.includes(titleField)) {
|
|
61
61
|
const relationCollection = schema.collections[field.collection]
|
|
62
|
-
if (!record[breadcrumb]) continue
|
|
62
|
+
if (!(record[breadcrumb] && Object.values(record[breadcrumb])[0])) continue
|
|
63
63
|
recordMap[breadcrumb] = {
|
|
64
64
|
title: (Object.values(record[breadcrumb])[0] as StokerRelation)[titleField],
|
|
65
65
|
collection: relationCollection,
|
package/src/Form.tsx
CHANGED
|
@@ -2477,7 +2477,6 @@ function RecordForm({
|
|
|
2477
2477
|
const [showDuplicateModal, setShowDuplicateModal] = useState(false)
|
|
2478
2478
|
const [duplicateRecordData, setDuplicateRecordData] = useState<Partial<StokerRecord> | undefined>(undefined)
|
|
2479
2479
|
const [convert, setConvert] = useState<Convert[] | undefined>(undefined)
|
|
2480
|
-
const [convertAllowed, setConvertAllowed] = useState<Record<string, boolean>>({})
|
|
2481
2480
|
const [showConvertModal, setShowConvertModal] = useState(false)
|
|
2482
2481
|
const [convertRecordData, setConvertRecordData] = useState<Partial<StokerRecord> | undefined>(undefined)
|
|
2483
2482
|
const [convertTargetCollection, setConvertTargetCollection] = useState<CollectionSchema | undefined>(undefined)
|
|
@@ -2504,6 +2503,21 @@ function RecordForm({
|
|
|
2504
2503
|
return collectionAccess("Delete", collectionPermissions)
|
|
2505
2504
|
}, [collection, permissions])
|
|
2506
2505
|
|
|
2506
|
+
const convertMenuItems = useMemo(() => {
|
|
2507
|
+
if (!convert?.length || !permissions?.Role) return []
|
|
2508
|
+
const role = permissions.Role
|
|
2509
|
+
return convert.filter((convertConfig) => {
|
|
2510
|
+
const targetPermissions = permissions.collections?.[convertConfig.collection] as
|
|
2511
|
+
| CollectionPermissions
|
|
2512
|
+
| undefined
|
|
2513
|
+
if (!collectionAccess("Create", targetPermissions as CollectionPermissions)) return false
|
|
2514
|
+
if (convertConfig.roles && convertConfig.roles.length > 0) {
|
|
2515
|
+
return convertConfig.roles.includes(role)
|
|
2516
|
+
}
|
|
2517
|
+
return true
|
|
2518
|
+
})
|
|
2519
|
+
}, [convert, permissions])
|
|
2520
|
+
|
|
2507
2521
|
const isPending = !!(id && isGlobalLoading.has(id))
|
|
2508
2522
|
const isPendingServer = !!(id && isGlobalLoading.get(id)?.server)
|
|
2509
2523
|
const [isAddingServer, setIsAddingServer] = useState(false)
|
|
@@ -3624,12 +3638,6 @@ function RecordForm({
|
|
|
3624
3638
|
...prev,
|
|
3625
3639
|
[collection.labels.collection]: collectionTitles?.record || collection.labels.record,
|
|
3626
3640
|
}))
|
|
3627
|
-
if (convert && convert.length > 0) {
|
|
3628
|
-
setConvertAllowed((prev) => ({
|
|
3629
|
-
...prev,
|
|
3630
|
-
[collection.labels.collection]: !disableCreate,
|
|
3631
|
-
}))
|
|
3632
|
-
}
|
|
3633
3641
|
})
|
|
3634
3642
|
permissionTitleResults.forEach(({ collection, titles: collectionTitles }) => {
|
|
3635
3643
|
setPermissionsTitles((prev) => ({
|
|
@@ -4502,10 +4510,17 @@ function RecordForm({
|
|
|
4502
4510
|
const convertRecord = useCallback(
|
|
4503
4511
|
async (targetCollection: CollectionSchema) => {
|
|
4504
4512
|
if (!formValues || !originalRecord) return
|
|
4513
|
+
const targetPermissions = permissions?.collections?.[targetCollection.labels.collection] as
|
|
4514
|
+
| CollectionPermissions
|
|
4515
|
+
| undefined
|
|
4516
|
+
if (!collectionAccess("Create", targetPermissions as CollectionPermissions)) return
|
|
4505
4517
|
const record = cloneDeep(originalRecord) as Partial<StokerRecord>
|
|
4506
4518
|
|
|
4507
4519
|
const convertConfig = convert?.find((convert) => convert.collection === targetCollection.labels.collection)
|
|
4508
4520
|
if (!convertConfig) return
|
|
4521
|
+
if (convertConfig.roles && convertConfig.roles.length > 0 && permissions?.Role) {
|
|
4522
|
+
if (!convertConfig.roles.includes(permissions.Role)) return
|
|
4523
|
+
}
|
|
4509
4524
|
|
|
4510
4525
|
const convertedRecord = await convertConfig.convert(record as StokerRecord)
|
|
4511
4526
|
|
|
@@ -4513,7 +4528,7 @@ function RecordForm({
|
|
|
4513
4528
|
setConvertTargetCollection(targetCollection)
|
|
4514
4529
|
setShowConvertModal(true)
|
|
4515
4530
|
},
|
|
4516
|
-
[formValues, originalRecord, permissions],
|
|
4531
|
+
[formValues, originalRecord, permissions, convert],
|
|
4517
4532
|
)
|
|
4518
4533
|
|
|
4519
4534
|
const hasBreadcrumbs = useMemo(() => {
|
|
@@ -5651,7 +5666,7 @@ function RecordForm({
|
|
|
5651
5666
|
Duplicate
|
|
5652
5667
|
</Button>
|
|
5653
5668
|
)}
|
|
5654
|
-
{
|
|
5669
|
+
{convertMenuItems.length > 0 && (
|
|
5655
5670
|
<DropdownMenu>
|
|
5656
5671
|
<DropdownMenuTrigger asChild>
|
|
5657
5672
|
<Button variant="outline" disabled={isCreateDisabled}>
|
|
@@ -5660,36 +5675,19 @@ function RecordForm({
|
|
|
5660
5675
|
</Button>
|
|
5661
5676
|
</DropdownMenuTrigger>
|
|
5662
5677
|
<DropdownMenuContent align="end">
|
|
5663
|
-
{
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
convertConfig.
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
return convertConfig.roles.includes(permissions?.Role)
|
|
5677
|
-
}
|
|
5678
|
-
return true
|
|
5679
|
-
})
|
|
5680
|
-
.map((convertConfig) => {
|
|
5681
|
-
const targetCollection =
|
|
5682
|
-
schema.collections[convertConfig.collection]
|
|
5683
|
-
if (!targetCollection) return null
|
|
5684
|
-
return (
|
|
5685
|
-
<DropdownMenuItem
|
|
5686
|
-
key={convertConfig.collection}
|
|
5687
|
-
onClick={() => convertRecord(targetCollection)}
|
|
5688
|
-
>
|
|
5689
|
-
{allRecordTitles[convertConfig.collection]}
|
|
5690
|
-
</DropdownMenuItem>
|
|
5691
|
-
)
|
|
5692
|
-
})}
|
|
5678
|
+
{convertMenuItems.map((convertConfig) => {
|
|
5679
|
+
const targetCollection =
|
|
5680
|
+
schema.collections[convertConfig.collection]
|
|
5681
|
+
if (!targetCollection) return null
|
|
5682
|
+
return (
|
|
5683
|
+
<DropdownMenuItem
|
|
5684
|
+
key={convertConfig.collection}
|
|
5685
|
+
onClick={() => convertRecord(targetCollection)}
|
|
5686
|
+
>
|
|
5687
|
+
{allRecordTitles[convertConfig.collection]}
|
|
5688
|
+
</DropdownMenuItem>
|
|
5689
|
+
)
|
|
5690
|
+
})}
|
|
5693
5691
|
</DropdownMenuContent>
|
|
5694
5692
|
</DropdownMenu>
|
|
5695
5693
|
)}
|
package/src/loadRoutes.tsx
CHANGED
|
@@ -89,7 +89,7 @@ export const loadRoutes = (): RouteObject[] => {
|
|
|
89
89
|
element: <Dashboard />,
|
|
90
90
|
errorElement: <ErrorPage />,
|
|
91
91
|
})
|
|
92
|
-
} else if (homePage) {
|
|
92
|
+
} else if (homePage && collectionAccess("Read", permissions.collections?.[homePage])) {
|
|
93
93
|
routes[0].children.unshift({
|
|
94
94
|
index: true,
|
|
95
95
|
element: <Navigate to={`/${homePage.toLowerCase()}`} replace />,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CollectionSchema } from "@stoker-platform/types"
|
|
2
|
-
import { getFieldCustomization,
|
|
2
|
+
import { getFieldCustomization, isRelationField, tryFunction } from "@stoker-platform/utils"
|
|
3
3
|
import {
|
|
4
|
+
getAllRoleGroups,
|
|
4
5
|
getCollectionConfigModule,
|
|
5
6
|
getCollectionRefs,
|
|
6
7
|
getCurrentUserPermissions,
|
|
@@ -13,14 +14,16 @@ export const getRelationFields = (collection: CollectionSchema) => {
|
|
|
13
14
|
const permissions = getCurrentUserPermissions()
|
|
14
15
|
if (!permissions?.Role) throw new Error("PERMISSION_DENIED")
|
|
15
16
|
const customization = getCollectionConfigModule(labels.collection)
|
|
16
|
-
const collectionSchema = schema.collections[labels.collection]
|
|
17
17
|
const relationFields: string[] = []
|
|
18
18
|
for (const field of fields) {
|
|
19
19
|
const fieldCustomization = getFieldCustomization(field, customization)
|
|
20
20
|
if (!isRelationField(field)) continue
|
|
21
21
|
const queryFullRecord = tryFunction(fieldCustomization.admin?.queryFullRecord)
|
|
22
22
|
const condition = tryFunction(fieldCustomization.admin?.condition?.form, ["update"])
|
|
23
|
-
const
|
|
23
|
+
const roleGroups = getAllRoleGroups()
|
|
24
|
+
const roleGroup = Array.from(roleGroups[labels.collection]).find(
|
|
25
|
+
(roleGroup) => permissions.Role && roleGroup.roles.includes(permissions.Role),
|
|
26
|
+
)
|
|
24
27
|
if (!roleGroup) throw new Error("PERMISSION_DENIED")
|
|
25
28
|
if (!schema.collections[field.collection]) continue
|
|
26
29
|
const refs = getCollectionRefs([field.collection], roleGroup)
|