diff --git a/packages/core/client/src/block-provider/BlockProvider.tsx b/packages/core/client/src/block-provider/BlockProvider.tsx index 9d622e976e..0f0e39b006 100644 --- a/packages/core/client/src/block-provider/BlockProvider.tsx +++ b/packages/core/client/src/block-provider/BlockProvider.tsx @@ -281,13 +281,14 @@ export const useBlockAssociationContext = () => { return useContext(BlockAssociationContext) || association; }; -export const useFilterByTk = () => { +export const useFilterByTk = (blockProps?: any) => { const { resource, __parent } = useBlockRequestContext(); const recordIndex = useRecordIndex(); const recordData = useCollectionRecordData(); const collection = useCollection_deprecated(); const { getCollectionField } = useCollectionManager_deprecated(); - const assoc = useBlockAssociationContext(); + const association = useBlockAssociationContext(); + const assoc = blockProps?.association || association; const withoutTableFieldResource = useContext(WithoutTableFieldResource); if (!withoutTableFieldResource) { @@ -336,8 +337,8 @@ export const useSourceIdFromParentRecord = () => { * @internal * @returns */ -export const useParamsFromRecord = () => { - const filterByTk = useFilterByTk(); +export const useParamsFromRecord = (props?: any) => { + const filterByTk = useFilterByTk(props); const record = useRecord(); const { fields } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); diff --git a/packages/core/client/src/modules/blocks/data-blocks/details-single/hooks/useDetailsDecoratorProps.ts b/packages/core/client/src/modules/blocks/data-blocks/details-single/hooks/useDetailsDecoratorProps.ts index 20d4967f6b..ff33c98512 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/details-single/hooks/useDetailsDecoratorProps.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/details-single/hooks/useDetailsDecoratorProps.ts @@ -20,7 +20,7 @@ import { * @returns */ export function useDetailsDecoratorProps(props) { - const params = useParamsFromRecord(); + const params = useParamsFromRecord(props); let parentRecord; // association 的值是固定不变的,所以可以在条件中使用 hooks diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx index 8c009fd1a4..d58e19c3dd 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx @@ -11,7 +11,7 @@ import { observer, useField, useFieldSchema } from '@formily/react'; import { toArr } from '@formily/shared'; import _ from 'lodash'; import React, { FC, Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { useDesignable } from '../../'; +import { useDesignable, usePopupSettings } from '../../'; import { WithoutTableFieldResource } from '../../../block-provider'; import { CollectionRecordProvider, useCollectionManager, useCollectionRecordData } from '../../../data-source'; import { NocoBaseRecursionField } from '../../../formily/NocoBaseRecursionField'; @@ -48,6 +48,7 @@ export interface ButtonListProps { label: string; value: string; }; + onClick?: (props: { recordData: any }) => void; } const RenderRecord = React.memo( @@ -67,6 +68,7 @@ const RenderRecord = React.memo( ellipsisWithTooltipRef, value, setBtnHover, + onClick, }: { fieldNames: any; isTreeCollection: boolean; @@ -83,6 +85,7 @@ const RenderRecord = React.memo( ellipsisWithTooltipRef: React.MutableRefObject; value: any; setBtnHover: any; + onClick?: (props: { recordData: any }) => void; }) => { const [loading, setLoading] = useState(true); const [result, setResult] = useState([]); @@ -138,6 +141,7 @@ const RenderRecord = React.memo( // When first inserting, the fieldSchema instance will be updated to a new instance. // We need to wait for the instance update before opening the popup to prevent configuration loss. setTimeout(() => { + onClick?.({ recordData: record }); openPopup({ recordData: record, parentRecordData: recordData, @@ -146,6 +150,7 @@ const RenderRecord = React.memo( }); needWaitForFieldSchemaUpdatedRef.current = false; } else if (fieldSchema.properties) { + onClick?.({ recordData: record }); openPopup({ recordData: record, parentRecordData: recordData, @@ -230,6 +235,7 @@ const ButtonLinkList: FC = observer((props) => { ellipsisWithTooltipRef={ellipsisWithTooltipRef} value={props.value} setBtnHover={props.setBtnHover} + onClick={props.onClick} /> ); }); @@ -275,12 +281,18 @@ export const ReadPrettyInternalViewer: React.FC = const { visibleWithURL, setVisibleWithURL } = usePopupUtils(); const [btnHover, setBtnHover] = useState(!!visibleWithURL); const { defaultOpenMode } = useOpenModeContext(); - const recordData = useCollectionRecordData(); + const parentRecordData = useCollectionRecordData(); + const [recordData, setRecordData] = useState(null); + const { isPopupVisibleControlledByURL } = usePopupSettings(); + + const onClickItem = useCallback((props: { recordData: any }) => { + setRecordData(props.recordData); + }, []); const btnElement = ( - - + + ); @@ -304,14 +316,29 @@ export const ReadPrettyInternalViewer: React.FC = return btnElement; } - const renderWithoutTableFieldResourceProvider = () => ( - // The recordData here is only provided when the popup is opened, not the current row record - - - - - - ); + const renderWithoutTableFieldResourceProvider = () => { + if (isPopupVisibleControlledByURL()) { + return ( + // The recordData here is only provided when the popup is opened, not the current row record + + + + + + ); + } + + return ( + + {/* The recordData here is only provided when the popup is opened, not the current row record */} + + + + + + + ); + }; return (