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 { useDataBlockResource } from './DataBlockResourceProvider';
|
||||||
import { useDataSourceHeaders } from '../utils';
|
import { useDataSourceHeaders } from '../utils';
|
||||||
import { useDataLoadingMode } from '../../modules/blocks/data-blocks/details-multi/setDataLoadingModeSettingsItem';
|
import { useDataLoadingMode } from '../../modules/blocks/data-blocks/details-multi/setDataLoadingModeSettingsItem';
|
||||||
import { useCollection, useCollectionManager } from '../collection';
|
|
||||||
|
|
||||||
export const BlockRequestContext = createContext<UseRequestResult<any>>(null);
|
export const BlockRequestContext = createContext<UseRequestResult<any>>(null);
|
||||||
BlockRequestContext.displayName = 'BlockRequestContext';
|
BlockRequestContext.displayName = 'BlockRequestContext';
|
||||||
@ -56,7 +55,6 @@ function useCurrentRequest<T>(options: Omit<AllDataBlockProps, 'type'>) {
|
|||||||
function useParentRequest<T>(options: Omit<AllDataBlockProps, 'type'>) {
|
function useParentRequest<T>(options: Omit<AllDataBlockProps, 'type'>) {
|
||||||
const { sourceId, association, parentRecord } = options;
|
const { sourceId, association, parentRecord } = options;
|
||||||
const api = useAPIClient();
|
const api = useAPIClient();
|
||||||
const cm = useCollectionManager();
|
|
||||||
const dataBlockProps = useDataBlockProps();
|
const dataBlockProps = useDataBlockProps();
|
||||||
const headers = useDataSourceHeaders(dataBlockProps.dataSource);
|
const headers = useDataSourceHeaders(dataBlockProps.dataSource);
|
||||||
return useRequest<T>(
|
return useRequest<T>(
|
||||||
@ -65,12 +63,8 @@ function useParentRequest<T>(options: Omit<AllDataBlockProps, 'type'>) {
|
|||||||
if (!association) return Promise.resolve({ data: undefined });
|
if (!association) return Promise.resolve({ data: undefined });
|
||||||
// "association": "Collection.Field"
|
// "association": "Collection.Field"
|
||||||
const arr = association.split('.');
|
const arr = association.split('.');
|
||||||
const field = cm.getCollectionField(association);
|
// <collection>:get/<filterByTk>
|
||||||
const isM2O = field.interface === 'm2o';
|
const url = `${arr[0]}:get/${sourceId}`;
|
||||||
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}`;
|
|
||||||
const res = await api.request({ url, headers });
|
const res = await api.request({ url, headers });
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
@ -94,7 +88,6 @@ export const BlockRequestProvider: FC = ({ children }) => {
|
|||||||
requestOptions,
|
requestOptions,
|
||||||
requestService,
|
requestService,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const currentRequest = useCurrentRequest<{ data: any }>({
|
const currentRequest = useCurrentRequest<{ data: any }>({
|
||||||
action,
|
action,
|
||||||
sourceId,
|
sourceId,
|
||||||
|
Loading…
Reference in New Issue
Block a user