1
1
'use client'
2
2
import type { FC } from 'react'
3
- import React from 'react'
3
+ import React , { useMemo } from 'react'
4
4
import { useTranslation } from 'react-i18next'
5
5
import { useContext } from 'use-context-selector'
6
6
import produce from 'immer'
@@ -19,6 +19,8 @@ import {
19
19
} from '@/app/components/workflow/nodes/knowledge-retrieval/utils'
20
20
import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
21
21
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
22
+ import { useSelector as useAppContextSelector } from '@/context/app-context'
23
+ import { hasEditPermissionForDataset } from '@/utils/permission'
22
24
23
25
const Icon = (
24
26
< svg width = "24" height = "24" viewBox = "0 0 24 24" fill = "none" xmlns = "http://www.w3.org/2000/svg" >
@@ -29,6 +31,7 @@ const Icon = (
29
31
30
32
const DatasetConfig : FC = ( ) => {
31
33
const { t } = useTranslation ( )
34
+ const userProfile = useAppContextSelector ( s => s . userProfile )
32
35
const {
33
36
mode,
34
37
dataSets : dataSet ,
@@ -105,6 +108,20 @@ const DatasetConfig: FC = () => {
105
108
setModelConfig ( newModelConfig )
106
109
}
107
110
111
+ const formattedDataset = useMemo ( ( ) => {
112
+ return dataSet . map ( ( item ) => {
113
+ const datasetConfig = {
114
+ createdBy : item . created_by ,
115
+ partialMemberList : item . partial_member_list as string [ ] ,
116
+ permission : item . permission ,
117
+ }
118
+ return {
119
+ ...item ,
120
+ readonly : ! hasEditPermissionForDataset ( userProfile ?. id as string , datasetConfig ) ,
121
+ }
122
+ } )
123
+ } , [ dataSet , userProfile ?. id ] )
124
+
108
125
return (
109
126
< FeaturePanel
110
127
className = 'mt-2'
@@ -122,12 +139,13 @@ const DatasetConfig: FC = () => {
122
139
{ hasData
123
140
? (
124
141
< div className = 'flex flex-wrap mt-1 px-3 pb-3 justify-between' >
125
- { dataSet . map ( item => (
142
+ { formattedDataset . map ( item => (
126
143
< CardItem
127
144
key = { item . id }
128
145
config = { item }
129
146
onRemove = { onRemove }
130
147
onSave = { handleSave }
148
+ readonly = { item . readonly }
131
149
/>
132
150
) ) }
133
151
</ div >
0 commit comments