UNPKG

@tduniec/backstage-plugin-time-saver

Version:

This plugin provides an implementation of charts and statistics related to your time savings that are coming from usage of your templates. Plugins is built from frontend and backend part. This part of plugin `frontend` is responsible of providing views wi

44 lines (41 loc) 1.5 kB
import { jsx } from 'react/jsx-runtime'; import * as React from 'react'; import { useState, useEffect } from 'react'; import { Autocomplete } from '@mui/material'; import { useApi, configApiRef, fetchApiRef } from '@backstage/core-plugin-api'; import CircularProgress from '@material-ui/core/CircularProgress'; import { TextField } from '@material-ui/core'; function TemplateAutocomplete({ onTemplateChange }) { const [_task, setTask] = React.useState(""); const handleChange = (_event, value) => { const selectedTemplateTaskId = value || ""; setTask(selectedTemplateTaskId); onTemplateChange(selectedTemplateTaskId); }; const [data, setData] = useState(null); const configApi = useApi(configApiRef); const fetchApi = useApi(fetchApiRef); useEffect(() => { fetchApi.fetch( `${configApi.getString("backend.baseUrl")}/api/time-saver/templates` ).then((response) => response.json()).then((dt) => setData(dt)).catch(); }, [configApi, fetchApi]); if (!data) { return /* @__PURE__ */ jsx(CircularProgress, {}); } const templates = data.templates; return /* @__PURE__ */ jsx( Autocomplete, { disablePortal: true, id: "combo-box-demo", options: templates, onChange: handleChange, renderInput: (params) => /* @__PURE__ */ jsx(TextField, { ...params, variant: "outlined", label: "Template Name" }) } ); } export { TemplateAutocomplete as default }; //# sourceMappingURL=TemplateAutocompleteComponent.esm.js.map