@@ -30,6 +30,7 @@ interface EditColumnsType<T> extends ColumnsType<T> {
3030 } ;
3131 editable : boolean ;
3232}
33+
3334export const AddNodesEdges : React . FC < Prop > = ( {
3435 type,
3536 data = [ ] ,
@@ -39,13 +40,15 @@ export const AddNodesEdges: React.FC<Prop> = ({
3940} ) => {
4041 const [ form ] = Form . useForm ( ) ;
4142 const { visible, onShow, onClose } = useVisible ( { defaultVisible : true } ) ;
42- const isNode = type === 'node' ;
43+
4344 const [ state , updateState ] = useImmer < {
4445 startList : Array < StartData > ;
4546 attrList : Array < AttrData > ;
4647 configList : Array < IndexData > ;
48+ isNode : boolean ;
4749 } > ( {
4850 startList : [ ] ,
51+ isNode : true ,
4952 attrList : [
5053 {
5154 id : 'primary-key' ,
@@ -58,13 +61,20 @@ export const AddNodesEdges: React.FC<Prop> = ({
5861 configList : [ ] ,
5962 } ) ;
6063 const { startList, attrList, configList } = state ;
64+ const isAllow = ( record : any ) : boolean => {
65+ return state ?. isNode && record ?. primaryField ;
66+ } ;
6167 useEffect ( ( ) => {
6268 onSwitch ?.( onShow , onClose ) ;
6369 } , [ ] ) ;
6470 useEffect ( ( ) => {
6571 onVisible ?.( visible ) ;
6672 } , [ visible ] ) ;
67-
73+ useEffect ( ( ) => {
74+ updateState ( draft => {
75+ draft . isNode = type === 'node' ;
76+ } ) ;
77+ } , [ type ] ) ;
6878 const propertyList = ( ) => {
6979 const attrPropertyNames = map (
7080 filter ( attrList , attr => ! attr . optional && ! attr . primaryField ) ,
@@ -195,10 +205,10 @@ export const AddNodesEdges: React.FC<Prop> = ({
195205 inputType : EditType . SELECT ,
196206 prop : {
197207 defaultValue : false ,
198- disabled : record . primaryField ,
208+ disabled : isAllow ( record ) ,
199209 options : [
200210 {
201- label : record . primaryField ? '否(主键)' : '否' ,
211+ label : isAllow ( record ) ? '否(主键)' : '否' ,
202212 value : false ,
203213 } ,
204214 { label : '是' , value : true } ,
@@ -211,8 +221,8 @@ export const AddNodesEdges: React.FC<Prop> = ({
211221 title : '操作' ,
212222 dataIndex : 'operate' ,
213223 key : 'operate' ,
214- render : ( _ , record : any ) =>
215- record . primaryField ? (
224+ render : ( _ , record : any ) => {
225+ return isAllow ( record ) ? (
216226 < Button
217227 disabled
218228 type = "text"
@@ -239,7 +249,8 @@ export const AddNodesEdges: React.FC<Prop> = ({
239249 >
240250 < a style = { { color : 'rgba(54,55,64,1)' } } > 删除</ a >
241251 </ Popconfirm >
242- ) ,
252+ ) ;
253+ } ,
243254 } ,
244255 ] ;
245256 const nodeConfigColumns : EditColumnsType < IndexData > = [
@@ -423,7 +434,7 @@ export const AddNodesEdges: React.FC<Prop> = ({
423434 >
424435 < div className = { styles [ `${ PUBLIC_PERFIX_CLASS } -container-content` ] } >
425436 < div className = { styles [ `${ PUBLIC_PERFIX_CLASS } -container-header` ] } >
426- < span > 添加{ `${ isNode ? '点' : '边' } ` } 类型</ span >
437+ < span > 添加{ `${ state . isNode ? '点' : '边' } ` } 类型</ span >
427438 < div >
428439 < span style = { { marginRight : 4 } } > 命令行建模</ span >
429440 < a href = "https://tugraph.antgroup.com/doc" target = "_blank" >
@@ -434,7 +445,7 @@ export const AddNodesEdges: React.FC<Prop> = ({
434445 < div >
435446 < Form layout = "vertical" form = { form } >
436447 < Form . Item
437- label = { `${ isNode ? '点' : '边' } 类型名称` }
448+ label = { `${ state . isNode ? '点' : '边' } 类型名称` }
438449 name = { 'name' }
439450 rules = { [
440451 {
@@ -443,7 +454,7 @@ export const AddNodesEdges: React.FC<Prop> = ({
443454 var reg = new RegExp ( '^[a-zA-Z0-9_\u4e00-\u9fa5]+$' ) ;
444455 if ( ! value ) {
445456 return Promise . reject (
446- `请填写${ isNode ? '点' : '边' } 类型名称!` ,
457+ `请填写${ state . isNode ? '点' : '边' } 类型名称!` ,
447458 ) ;
448459 }
449460 if ( ! reg . test ( value ) ) {
@@ -459,7 +470,7 @@ export const AddNodesEdges: React.FC<Prop> = ({
459470 >
460471 < Input
461472 autoComplete = "off"
462- placeholder = { `请输入${ isNode ? '点' : '边' } 类型名称` }
473+ placeholder = { `请输入${ state . isNode ? '点' : '边' } 类型名称` }
463474 className = { styles [ `${ PUBLIC_PERFIX_CLASS } -container-name` ] }
464475 />
465476 </ Form . Item >
@@ -484,7 +495,7 @@ export const AddNodesEdges: React.FC<Prop> = ({
484495 />
485496 { addButton ( addNodeAttr ) }
486497 </ div >
487- { ! isNode && (
498+ { ! state . isNode && (
488499 < div >
489500 < p className = { styles [ `${ PUBLIC_PERFIX_CLASS } -container-title` ] } >
490501 < Tooltip title = "如果不选择,则表示起点和终点可以为任意点类型" >
@@ -510,7 +521,7 @@ export const AddNodesEdges: React.FC<Prop> = ({
510521 { addButton ( addEdge , '添加起点和终点' ) }
511522 </ div >
512523 ) }
513- { isNode && (
524+ { state . isNode && (
514525 < div >
515526 < p className = { styles [ `${ PUBLIC_PERFIX_CLASS } -container-title` ] } >
516527 索引列表
0 commit comments