Skip to content

resolveFieldOptions

function resolveFieldOptions(input): MaybePromise<FieldOption[]>;

Defined in: filters/resource-options.ts:57

Resolve FieldOptions to its FieldOption[] — calling the getter (with query) or returning the static list. Stays the color of its input: a static list or sync getter resolves synchronously (no microtask), an async getter yields a Promise. await works on either.

Parameter Type
input { options: FieldOptions; query?: OptionsQuery; }
input.options FieldOptions
input.query? OptionsQuery

MaybePromise<FieldOption[]>

A static list resolves synchronously

import { resolveFieldOptions } from "@xtandard/lib/filters";
resolveFieldOptions({ options: [{ value: "open", label: "Open" }] });
// → [{ value: "open", label: "Open" }] (no Promise)

An async getter (search by q, or resolve labels by ids)

const users = [
{ value: "u1", label: "Ada" },
{ value: "u2", label: "Grace" },
];
const options = async ({ q = "", ids }: { q?: string; ids?: string[] }) =>
users.filter((u) => (ids ? ids.includes(u.value) : u.label.toLowerCase().includes(q)));
await resolveFieldOptions({ options, query: { q: "gr" } }); // → [{ value: "u2", label: "Grace" }]
await resolveFieldOptions({ options, query: { ids: ["u1"] } }); // → [{ value: "u1", label: "Ada" }]