Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 1x 8x 8x 8x 8x 8x 8x 8x 34x 1x | import React from 'react';
import { useTranslation } from 'react-i18next';
import { Dropdown, DropdownSkeleton } from '@carbon/react';
import { showSnackbar, useConfig } from '@openmrs/esm-framework';
import { type ConfigObject } from '../../config-schema';
import { useConcept } from '../../stock-lookups/stock-lookups.resource';
import styles from './stock-sources-filter.scss';
const StockSourcesFilter: React.FC<{
onFilterChange: (selectedSourceType: string) => void;
}> = ({ onFilterChange }) => {
const { t } = useTranslation();
const { stockSourceTypeUUID } = useConfig<ConfigObject>();
const { items, isLoading, error } = useConcept(stockSourceTypeUUID);
Iif (isLoading) {
return <DropdownSkeleton size="sm" />;
}
Iif (error) {
showSnackbar({
title: t('errorFetchingStockSourceTypes', 'Error fetching stock source types'),
subtitle: error.message,
kind: 'error',
isLowContrast: true,
});
}
Iif (Object.keys(items).length === 0) {
return null;
}
return (
<div className={styles.filterContainer}>
<Dropdown
id="stockSourcesFilter"
initialSelectedItem={items?.answers?.[0]}
items={[...(items?.answers || [])]}
itemToString={(item) => (item ? item.display : t('notSet', 'Not Set'))}
label=""
onChange={({ selectedItem }) => onFilterChange(selectedItem?.display)}
size="sm"
titleText={t('selectSourceType', 'Select source type')}
type="inline"
/>
</div>
);
};
export default StockSourcesFilter;
|