fix(data-template): titleField undefined (#2398)
* fix: titleField undefined * refactor: code improve
This commit is contained in:
		
							parent
							
								
									a6030a5151
								
							
						
					
					
						commit
						d25b9080b1
					
				@ -101,7 +101,11 @@ export const Templates = ({ style = {}, form }) => {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }, []);
 | 
					  }, []);
 | 
				
			||||||
 | 
					  useEffect(() => {
 | 
				
			||||||
 | 
					    if (!templateOptions?.some((v) => v.key === targetTemplate)) {
 | 
				
			||||||
 | 
					      handleTemplateChange('none');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }, [templateOptions]);
 | 
				
			||||||
  const wrapperStyle = useMemo(() => {
 | 
					  const wrapperStyle = useMemo(() => {
 | 
				
			||||||
    return { display: 'flex', alignItems: 'center', backgroundColor: token.colorFillAlter, padding: '1em', ...style };
 | 
					    return { display: 'flex', alignItems: 'center', backgroundColor: token.colorFillAlter, padding: '1em', ...style };
 | 
				
			||||||
  }, [style, token.colorFillAlter]);
 | 
					  }, [style, token.colorFillAlter]);
 | 
				
			||||||
@ -115,7 +119,7 @@ export const Templates = ({ style = {}, form }) => {
 | 
				
			|||||||
    return { fontSize: token.fontSize, fontWeight: 'bold', whiteSpace: 'nowrap', marginRight: token.marginXS };
 | 
					    return { fontSize: token.fontSize, fontWeight: 'bold', whiteSpace: 'nowrap', marginRight: token.marginXS };
 | 
				
			||||||
  }, [token.fontSize, token.marginXS]);
 | 
					  }, [token.fontSize, token.marginXS]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const handleTemplateChange = useCallback(async (value, option) => {
 | 
					  const handleTemplateChange = useCallback(async (value) => {
 | 
				
			||||||
    setTargetTemplate(value);
 | 
					    setTargetTemplate(value);
 | 
				
			||||||
    setTemplateData(null);
 | 
					    setTemplateData(null);
 | 
				
			||||||
    form?.reset();
 | 
					    form?.reset();
 | 
				
			||||||
@ -148,7 +152,6 @@ export const Templates = ({ style = {}, form }) => {
 | 
				
			|||||||
    return null;
 | 
					    return null;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  const template = templateOptions?.find((v) => v.key === targetTemplate);
 | 
					  const template = templateOptions?.find((v) => v.key === targetTemplate);
 | 
				
			||||||
 | 
					 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div style={wrapperStyle}>
 | 
					    <div style={wrapperStyle}>
 | 
				
			||||||
      <Space wrap>
 | 
					      <Space wrap>
 | 
				
			||||||
@ -160,7 +163,7 @@ export const Templates = ({ style = {}, form }) => {
 | 
				
			|||||||
          value={targetTemplate}
 | 
					          value={targetTemplate}
 | 
				
			||||||
          onChange={handleTemplateChange}
 | 
					          onChange={handleTemplateChange}
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
        {targetTemplate !== 'none' && (
 | 
					        {targetTemplate !== 'none' && template && (
 | 
				
			||||||
          <RemoteSelect
 | 
					          <RemoteSelect
 | 
				
			||||||
            style={{ width: 220 }}
 | 
					            style={{ width: 220 }}
 | 
				
			||||||
            fieldNames={{ label: template?.titleField, value: 'id' }}
 | 
					            fieldNames={{ label: template?.titleField, value: 'id' }}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user