UNPKG

@redocly/theme

Version:

Shared UI components lib

20 lines (16 loc) 760 B
import type { UseCatalogEntitiesProps } from '../../types/catalog'; export function useCatalogEntities({ entitiesTypes, excludedEntities }: UseCatalogEntitiesProps) { const initialTypesWithoutAll = entitiesTypes.filter((type) => type !== 'all'); const initialTypesFilter = entitiesTypes.length ? `type:${initialTypesWithoutAll.join(',')}` : ''; const initialExcludedEntitiesFilter = excludedEntities?.length ? `-key:${excludedEntities.map((entity) => entity.key).join(',')}` : ''; if (initialTypesFilter && initialExcludedEntitiesFilter) { return { initialFilter: `(${initialTypesFilter}) AND (${initialExcludedEntitiesFilter})`, }; } return { initialFilter: initialTypesFilter || initialExcludedEntitiesFilter, }; }