refactor: code improve

This commit is contained in:
katherinehhh 2023-05-11 19:00:23 +08:00
parent 1f62857a9a
commit 515e730048

View File

@ -7,18 +7,26 @@ import { InternalSubTable } from './InternalSubTable';
import { FileManageReadPretty } from './FileManager';
import { useAssociationFieldContext } from './hooks';
export const ReadPretty = observer((props: any) => {
const ReadPrettyAssociationField = observer((props: any) => {
const { isFileCollection } = useAssociationFieldContext();
const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select'));
useEffect(() => {
props.mode && setCurrentMode(props.mode);
}, [props.mode]);
return (
<AssociationFieldProvider>
<>
{['Select', 'Picker'].includes(currentMode) && <ReadPrettyInternalViewer {...props} />}
{currentMode === 'Nester' && <InternalNester {...props} />}
{currentMode === 'SubTable' && <InternalSubTable {...props} />}
{currentMode === 'FileManager' && <FileManageReadPretty {...props} />}
</>
);
});
export const ReadPretty = observer((props) => {
return (
<AssociationFieldProvider>
<ReadPrettyAssociationField {...props} />
</AssociationFieldProvider>
);
});