-
Notifications
You must be signed in to change notification settings - Fork 66
Talking to APIs
these just do a http request (using ky
) with the right csrf token
use in actions and other hooks
use*Request
seem to be similar to the above, with more error handling?
eg. useGetRequest
returns a function (url, query?)
for use by useSWR
useGet
takes (url, query?, refreshInterval?)
and returns { data, error, refresh, isLoading }
- using useSWR
use in detail screen
use in list screens
import { useHubView } from '../useHubView';
import { hubAPI, pulpIdKeyFn } from '../api';
// const toolbarFilters = useApprovalFilters();
// const tableColumns = useApprovalsColumns();
const view = useHubView<Approval>({
url: hubAPI`/_ui/v1/collection-versions/`,
keyFn: pulpIdKeyFn, // how to tell items apart: id (idKeyFn), pulp_id (pulpIdKeyFn) , pulp_href (pulpHrefKeyFn), name (nameKeyFn)
toolbarFilters,
tableColumns,
queryParams: { 'foo': 'bar' }, // extra params
});
// <PageTable {...view} />
import { usePulpView } from '../usePulpView';
import { pulpAPI, pulpHrefKeyFn } from '../api';
// const toolbarFilters = useTaskFilters();
// const tableColumns = useTaskColumns();
const view = usePulpView<Task>({
url: pulpAPI`/tasks/`,
keyFn: pulpHrefKeyFn,
toolbarFilters,
tableColumns
});
// <PageTable {...view} />
under the hood, these use useSWR (via framework/useView
)
and the view returns:
// from useView
page, setPage, perPage, setPerPage,
sort, setSort, sortDirection, setSortDirection,
filters, setFilters, clearAllFilters,
// from useSelected
selectedItems, selectItem, unselectItem, isSelected,
selectItems, selectAll, unselectAll, allSelected,
keyFn, unselectItems,
// only in useHubView
unselectItemsAndRefresh,
// common
error
itemCount
pageItems
refresh
PageFramework
PageHeader
PageLayout
PageDashboard
PageDashboardCarousel
PageDetails
PageForm
PageTable
PageTabs
PageToolbar
BulkActionDialog
BulkConfirmationDialog
EmptyState
PageCarousel
ReorderItems
useBreakPoint
useFrameworkTranslations
useInMemoryView
useIsMounted
useOpen
usePageNavigate
useSearchParams
useSelectDialog
useTableItems
useView
useWindowLocation
useDeleteRequest
useGet
useGetAllPagesAWX
useGetItem
useGetRequest
useOptions
usePatchRequest
usePostRequest