MetaEntitiesSelect
A component for selecting Tracker meta-entities — projects, portfolios, goals, reports — based on a suggest. Displays each entity with an icon and name, supports asynchronous loading, loading state, error display, and a clear button.
Basic usage
import {MetaEntitiesSelect} from '@weavix/tracker-components';
<MetaEntitiesSelect
getItems={(text) => fetchProjects(text)}
onChange={(entity) => console.log('selected', entity)}
/>;
Usage with Tracker API
import React, {useState} from 'react';
import {MetaEntitiesSelect} from '@weavix/tracker-components';
import type {MetaEntityV2} from '@weavix/tracker-api-types';
interface Props {
trackerApi: TrackerApi;
onChange: (entity: MetaEntityV2) => void;
}
export const ProjectSelect: React.FC<Props> = ({trackerApi, onChange}) => {
const [error, setError] = useState<string | undefined>(undefined);
const getItems = async (input: string): Promise<MetaEntityV2[]> => {
setError(undefined);
try {
const result = await trackerApi.v3.post['/entities/{entityType}/_search']({
pathParams: {entityType: 'project'},
queryParams: {fields: ['summary'], page: 1, perPage: 50},
bodyParams: {filter: {}, filterTypes: ['ALL'], input},
});
return result.data;
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load projects');
return [];
}
};
return (
<MetaEntitiesSelect
getItems={getItems}
onChange={onChange}
error={error}
placeholder="Select project"
/>
);
};
Entity types: the
entityTypeparameter accepts values'portfolio' | 'project' | 'report' | 'goal'.
Main props
|
Prop |
Type |
Default |
Description |
|
|
|
|
— |
Function for loading items. Called on mount and on every text change |
|
|
|
|
— |
Callback when an entity is selected |
|
|
|
|
— |
Callback when the input field text changes |
|
|
|
|
— |
Current input field value (controlled mode) |
|
|
|
|
|
Placeholder for an empty field |
|
|
|
`string |
boolean` |
— |
Error message or error flag |
|
|
|
|
Show clear button (×) |
|
|
|
|
— |
Additional CSS class for the root element |
|
|
|
|
— |
Additional CSS class for each list item |