Skip to Content
FrontendBundlesCRUDHooksusePriorityNeighbors

usePriorityNeighbors

usePriorityNeighbors fetches the entity with the closest lower priority and the closest higher priority relative to a given value. GeneralDetails uses it on the show page to display where an entity sits in the priority order.

This is priority ordering, not tree ordering. Priority is a flat numeric field swapped by the Priority Up / Priority Down listing actions; it has nothing to do with lft/rgt. For tree siblings use useTreeNeighbors.


Import

import { usePriorityNeighbors } from "@phpcreation/frontend-crud-react-nextjs-bundle/utils/hooks";

Signature

const { before, after, fetching } = usePriorityNeighbors( priority, // number | null | undefined, the current entity's priority resource, // API resource name tenant, // tenant identifier enabled, // skip fetching until true );
type PriorityNeighbor = { id: number; priority: number; [key: string]: any; } | null; // returns { before: PriorityNeighbor; // closest lower priority, or null after: PriorityNeighbor; // closest higher priority, or null fetching: boolean; }

How it queries

Two parallel one-item requests:

ResultQuery
beforepriority_range[lt]=<priority>, order[priority]=desc, itemsPerPage=1
afterpriority_range[gt]=<priority>, order[priority]=asc, itemsPerPage=1

Failures are swallowed; the neighbors just stay null.


Usage

From GeneralDetails:

const { before: priorityBefore, after: priorityAfter, fetching: priorityFetching, } = usePriorityNeighbors( data?.priority, resource, tenant, hasPriorityFields && !loading, );

Last updated on