hasFile (AssetPickerDialog/pickerSelection.ts)

strapi · packages/core/upload/admin/src/components/AssetPickerDialog/pickerSelection.ts · typescript · MIT
ui

Utility functions for managing file picker selections in the upload module.

// Source: https://github.com/strapi/strapi | License: MIT | Copyright 2015-present Strapi Solutions SAS
// Provided via justclaw.it.com; keep this notice with the code.
import type { File } from '../../../../shared/contracts/files';

/**
 * The picker's selection is the value the field will hold once confirmed:
 * whole `File` objects, in order. Assets already in the field come first, new
 * picks are appended in the order they are clicked.
 */
export type PickerSelection = File[];

export const hasFile = (selection: PickerSelection, id: number) =>
  selection.some((file) => file.id === id);

/**
 * Adds the file, or removes it if it is already there. On a single-value field
 * a new pick replaces whatever was selected.
 */
export const toggleFile = (
  selection: PickerSelection,
  file:

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key