mirror of
https://github.com/apache/superset.git
synced 2024-09-06 22:07:34 -04:00
better names
This commit is contained in:
parent
8f6cfcffc0
commit
2c6fd0abb8
@ -144,7 +144,7 @@ export function useApiResourceFullBody<RESULT>(
|
||||
* @param transformFn a callback that transforms the result object into the shape you want.
|
||||
* Make sure to use a persistent function for this so it doesn't constantly recalculate!
|
||||
*/
|
||||
export function useResourceTransform<IN, OUT>(
|
||||
export function useTransformedResource<IN, OUT>(
|
||||
resource: Resource<IN>,
|
||||
transformFn: (result: IN) => OUT,
|
||||
): Resource<OUT> {
|
||||
@ -161,7 +161,8 @@ export function useResourceTransform<IN, OUT>(
|
||||
}
|
||||
|
||||
// returns the "result" field from a fetched API v1 endpoint
|
||||
const innerResult = <T>(responseBody: { result: T }) => responseBody.result;
|
||||
const extractInnerResult = <T>(responseBody: { result: T }) =>
|
||||
responseBody.result;
|
||||
|
||||
/**
|
||||
* A general-purpose hook to fetch a Superset resource from a v1 API endpoint.
|
||||
@ -173,8 +174,8 @@ const innerResult = <T>(responseBody: { result: T }) => responseBody.result;
|
||||
* @param endpoint The url where the resource is located.
|
||||
*/
|
||||
export function useApiV1Resource<RESULT>(endpoint: string): Resource<RESULT> {
|
||||
return useResourceTransform(
|
||||
return useTransformedResource(
|
||||
useApiResourceFullBody<{ result: RESULT }>(endpoint),
|
||||
innerResult,
|
||||
extractInnerResult,
|
||||
);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
import rison from 'rison';
|
||||
import Chart from 'src/types/Chart';
|
||||
import { useApiV1Resource, useResourceTransform } from './apiResources';
|
||||
import { useApiV1Resource, useTransformedResource } from './apiResources';
|
||||
|
||||
function extractOwnerNames({ owners }: Chart) {
|
||||
if (!owners) return null;
|
||||
@ -32,7 +32,7 @@ const ownerNamesQuery = rison.encode({
|
||||
});
|
||||
|
||||
export function useChartOwnerNames(chartId: string) {
|
||||
return useResourceTransform(
|
||||
return useTransformedResource(
|
||||
useApiV1Resource<Chart>(`/api/v1/chart/${chartId}?q=${ownerNamesQuery}`),
|
||||
extractOwnerNames,
|
||||
);
|
||||
|
@ -20,10 +20,10 @@
|
||||
export {
|
||||
useApiResourceFullBody,
|
||||
useApiV1Resource,
|
||||
useResourceTransform,
|
||||
useTransformedResource,
|
||||
} from './apiResources';
|
||||
|
||||
// A central catalog of API hooks.
|
||||
// A central catalog of API Resource hooks.
|
||||
// Add new API hooks here, organized under
|
||||
// different files for different resource types.
|
||||
export { useChartOwnerNames } from './charts';
|
||||
|
Loading…
Reference in New Issue
Block a user