Merge pull request 'feat: git revert 005b5a313dee5f73010225e906b307fe05912388' (#551) from feat_revert_datablockrequestprovider into @hera/dev
Reviewed-on: daoyoucloud/tachycode#551
This commit is contained in:
commit
b5b042ba94
@ -7,7 +7,6 @@ import { AllDataBlockProps, useDataBlockProps } from './DataBlockProvider';
|
||||
import { useDataBlockResource } from './DataBlockResourceProvider';
|
||||
import { useDataSourceHeaders } from '../utils';
|
||||
import { useDataLoadingMode } from '../../modules/blocks/data-blocks/details-multi/setDataLoadingModeSettingsItem';
|
||||
import { useCollection, useCollectionManager } from '../collection';
|
||||
|
||||
export const BlockRequestContext = createContext<UseRequestResult<any>>(null);
|
||||
BlockRequestContext.displayName = 'BlockRequestContext';
|
||||
@ -56,7 +55,6 @@ function useCurrentRequest<T>(options: Omit<AllDataBlockProps, 'type'>) {
|
||||
function useParentRequest<T>(options: Omit<AllDataBlockProps, 'type'>) {
|
||||
const { sourceId, association, parentRecord } = options;
|
||||
const api = useAPIClient();
|
||||
const cm = useCollectionManager();
|
||||
const dataBlockProps = useDataBlockProps();
|
||||
const headers = useDataSourceHeaders(dataBlockProps.dataSource);
|
||||
return useRequest<T>(
|
||||
@ -65,12 +63,8 @@ function useParentRequest<T>(options: Omit<AllDataBlockProps, 'type'>) {
|
||||
if (!association) return Promise.resolve({ data: undefined });
|
||||
// "association": "Collection.Field"
|
||||
const arr = association.split('.');
|
||||
const field = cm.getCollectionField(association);
|
||||
const isM2O = field.interface === 'm2o';
|
||||
const filterTargetKey = cm.getCollection(arr[0]).getOption('filterTargetKey');
|
||||
const filterKey = isM2O ? filterTargetKey : field.sourceKey;
|
||||
// <collection>:get?filter[filterKey]=sourceId
|
||||
const url = `${arr[0]}:get?filter[${filterKey}]=${sourceId}`;
|
||||
// <collection>:get/<filterByTk>
|
||||
const url = `${arr[0]}:get/${sourceId}`;
|
||||
const res = await api.request({ url, headers });
|
||||
return res.data;
|
||||
},
|
||||
@ -94,7 +88,6 @@ export const BlockRequestProvider: FC = ({ children }) => {
|
||||
requestOptions,
|
||||
requestService,
|
||||
} = props;
|
||||
|
||||
const currentRequest = useCurrentRequest<{ data: any }>({
|
||||
action,
|
||||
sourceId,
|
||||
|
Loading…
Reference in New Issue
Block a user