All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.utils.getAllPicklists.ts Maven / Gradle / Ivy

The newest version!
/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

import {fetch} from 'frontend-js-web';

import {DEFAULT_FETCH_HEADERS} from './constants';
import openDefaultFailureToast from './openDefaultFailureToast';
import {IPickList} from './types';

export default async function getAllPicklists(
	page: number = 1,
	items: IPickList[] = []
) {
	const response = await fetch(
		`/o/headless-admin-list-type/v1.0/list-type-definitions?pageSize=100&page=${page}`,
		{
			headers: DEFAULT_FETCH_HEADERS,
		}
	);

	if (!response.ok) {
		openDefaultFailureToast();

		return [];
	}

	const responseJSON = await response.json();

	items = [...items, ...responseJSON.items];

	if (responseJSON.lastPage > page) {
		items = await getAllPicklists(page + 1, items);
	}

	return items;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy