@backstage/plugin-catalog-react 1.2.2-next.1 → 1.2.2-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @backstage/plugin-catalog-react
2
2
 
3
+ ## 1.2.2-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/core-components@0.12.1-next.3
9
+ - @backstage/catalog-client@1.2.0-next.1
10
+ - @backstage/catalog-model@1.1.4-next.1
11
+ - @backstage/core-plugin-api@1.2.0-next.2
12
+ - @backstage/errors@1.1.4-next.1
13
+ - @backstage/integration@1.4.1-next.1
14
+ - @backstage/theme@0.2.16
15
+ - @backstage/types@1.0.2-next.1
16
+ - @backstage/version-bridge@1.0.3-next.0
17
+ - @backstage/plugin-catalog-common@1.0.9-next.2
18
+ - @backstage/plugin-permission-common@0.7.2-next.1
19
+ - @backstage/plugin-permission-react@0.4.8-next.2
20
+
21
+ ## 1.2.2-next.2
22
+
23
+ ### Patch Changes
24
+
25
+ - 6ffa47bb0a: Cleanup and small fixes for the kind selector
26
+ - Updated dependencies
27
+ - @backstage/core-plugin-api@1.2.0-next.2
28
+ - @backstage/core-components@0.12.1-next.2
29
+ - @backstage/plugin-permission-react@0.4.8-next.2
30
+ - @backstage/catalog-client@1.2.0-next.1
31
+ - @backstage/catalog-model@1.1.4-next.1
32
+ - @backstage/errors@1.1.4-next.1
33
+ - @backstage/integration@1.4.1-next.1
34
+ - @backstage/theme@0.2.16
35
+ - @backstage/types@1.0.2-next.1
36
+ - @backstage/version-bridge@1.0.3-next.0
37
+ - @backstage/plugin-catalog-common@1.0.9-next.2
38
+ - @backstage/plugin-permission-common@0.7.2-next.1
39
+
3
40
  ## 1.2.2-next.1
4
41
 
5
42
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-react",
3
- "version": "1.2.2-next.1",
3
+ "version": "1.2.2-next.3",
4
4
  "main": "../dist/index.esm.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -191,6 +191,11 @@ export declare const EntityKindPicker: (props: EntityKindPickerProps) => JSX.Ele
191
191
  * @public
192
192
  */
193
193
  export declare interface EntityKindPickerProps {
194
+ /**
195
+ * Entity kinds to show in the dropdown; by default all kinds are fetched from the catalog and
196
+ * displayed.
197
+ */
198
+ allowedKinds?: string[];
194
199
  initialFilter?: string;
195
200
  hidden?: boolean;
196
201
  }
@@ -191,6 +191,11 @@ export declare const EntityKindPicker: (props: EntityKindPickerProps) => JSX.Ele
191
191
  * @public
192
192
  */
193
193
  export declare interface EntityKindPickerProps {
194
+ /**
195
+ * Entity kinds to show in the dropdown; by default all kinds are fetched from the catalog and
196
+ * displayed.
197
+ */
198
+ allowedKinds?: string[];
194
199
  initialFilter?: string;
195
200
  hidden?: boolean;
196
201
  }
package/dist/index.d.ts CHANGED
@@ -191,6 +191,11 @@ export declare const EntityKindPicker: (props: EntityKindPickerProps) => JSX.Ele
191
191
  * @public
192
192
  */
193
193
  export declare interface EntityKindPickerProps {
194
+ /**
195
+ * Entity kinds to show in the dropdown; by default all kinds are fetched from the catalog and
196
+ * displayed.
197
+ */
198
+ allowedKinds?: string[];
194
199
  initialFilter?: string;
195
200
  hidden?: boolean;
196
201
  }
package/dist/index.esm.js CHANGED
@@ -5,11 +5,9 @@ import React, { useState, forwardRef, createContext, useMemo, useCallback, useCo
5
5
  import { Grid, useMediaQuery, useTheme, Button, Drawer, Box, Typography, Tooltip, makeStyles, FormControlLabel, Checkbox, TextField, Toolbar, FormControl, Input, InputAdornment, IconButton, withStyles, DialogContentText, ListItemText as ListItemText$1, ListSubheader as ListSubheader$1, Card, CardContent, ListItem, ListItemIcon, List, Dialog, DialogTitle, DialogContent, Tabs, Tab, DialogActions, Divider, MenuItem, ListItemSecondaryAction } from '@material-ui/core';
6
6
  import FilterListIcon from '@material-ui/icons/FilterList';
7
7
  import { Link, Progress, ErrorPanel, Select, OverflowTooltip, Table, ResponseErrorPanel, DependencyGraph, DependencyGraphTypes, CodeSnippet } from '@backstage/core-components';
8
- import capitalize from 'lodash/capitalize';
9
- import sortBy from 'lodash/sortBy';
10
- import useAsync from 'react-use/lib/useAsync';
11
8
  import { DEFAULT_NAMESPACE, parseEntityRef, ANNOTATION_SOURCE_LOCATION, parseLocationRef, RELATION_MEMBER_OF, getCompoundEntityRef, stringifyEntityRef, RELATION_OWNED_BY, RELATION_PART_OF, ANNOTATION_LOCATION, ANNOTATION_ORIGIN_LOCATION } from '@backstage/catalog-model';
12
9
  import { getOrCreateGlobalSingleton, createVersionedContext, createVersionedValueMap, useVersionedContext } from '@backstage/version-bridge';
10
+ import useAsync from 'react-use/lib/useAsync';
13
11
  import { compact, isEqual, groupBy, chunk } from 'lodash';
14
12
  import qs from 'qs';
15
13
  import { useLocation, useNavigate } from 'react-router';
@@ -17,6 +15,7 @@ import useAsyncFn from 'react-use/lib/useAsyncFn';
17
15
  import useDebounce from 'react-use/lib/useDebounce';
18
16
  import useMountedState from 'react-use/lib/useMountedState';
19
17
  import isEqual$1 from 'lodash/isEqual';
18
+ import sortBy from 'lodash/sortBy';
20
19
  import useObservable from 'react-use/lib/useObservable';
21
20
  import { usePermission } from '@backstage/plugin-permission-react';
22
21
  import CheckBoxIcon from '@material-ui/icons/CheckBox';
@@ -852,38 +851,42 @@ function useEntityPermission(permission) {
852
851
  return { loading: false, allowed, error: permissionError };
853
852
  }
854
853
 
855
- function useAvailableKinds() {
854
+ function useAllKinds() {
856
855
  const catalogApi = useApi(catalogApiRef);
857
- const [availableKinds, setAvailableKinds] = useState([]);
858
856
  const {
859
857
  error,
860
858
  loading,
861
- value: facets
859
+ value: allKinds
862
860
  } = useAsync(async () => {
863
- const facet = "kind";
864
- const items = await catalogApi.getEntityFacets({
865
- facets: [facet]
866
- }).then((response) => response.facets[facet] || []);
861
+ const items = await catalogApi.getEntityFacets({ facets: ["kind"] }).then((response) => {
862
+ var _a;
863
+ return ((_a = response.facets.kind) == null ? void 0 : _a.map((f) => f.value).sort()) || [];
864
+ });
867
865
  return items;
868
866
  }, [catalogApi]);
869
- const facetsRef = useRef(facets);
870
- useEffect(() => {
871
- const oldFacets = facetsRef.current;
872
- facetsRef.current = facets;
873
- if (loading || oldFacets === facets || !facets) {
874
- return;
875
- }
876
- const newKinds = [
877
- ...new Set(
878
- sortBy(facets, (f) => f.value).map(
879
- (f) => f.value.toLocaleLowerCase("en-US")
880
- )
867
+ return { loading, error, allKinds: allKinds != null ? allKinds : [] };
868
+ }
869
+ function filterKinds(allKinds, allowedKinds, forcedKinds) {
870
+ let availableKinds = allKinds;
871
+ if (allowedKinds) {
872
+ availableKinds = availableKinds.filter(
873
+ (k) => allowedKinds.some(
874
+ (a) => a.toLocaleLowerCase("en-US") === k.toLocaleLowerCase("en-US")
881
875
  )
882
- ];
883
- setAvailableKinds(newKinds);
884
- }, [loading, facets, setAvailableKinds]);
885
- return { loading, error, availableKinds };
876
+ );
877
+ }
878
+ if (forcedKinds && !allKinds.some(
879
+ (a) => a.toLocaleLowerCase("en-US") === forcedKinds.toLocaleLowerCase("en-US")
880
+ )) {
881
+ availableKinds = availableKinds.concat([forcedKinds]);
882
+ }
883
+ const kindsMap = availableKinds.sort().reduce((acc, kind) => {
884
+ acc[kind.toLocaleLowerCase("en-US")] = kind;
885
+ return acc;
886
+ }, {});
887
+ return kindsMap;
886
888
  }
889
+
887
890
  function useEntityKindFilter(opts) {
888
891
  var _a, _b;
889
892
  const {
@@ -891,42 +894,42 @@ function useEntityKindFilter(opts) {
891
894
  queryParameters: { kind: kindParameter },
892
895
  updateFilters
893
896
  } = useEntityList();
894
- const flattenedQueryKind = useMemo(
897
+ const queryParamKind = useMemo(
895
898
  () => [kindParameter].flat()[0],
896
899
  [kindParameter]
897
900
  );
898
901
  const [selectedKind, setSelectedKind] = useState(
899
- (_b = flattenedQueryKind != null ? flattenedQueryKind : (_a = filters.kind) == null ? void 0 : _a.value) != null ? _b : opts.initialFilter
902
+ (_b = queryParamKind != null ? queryParamKind : (_a = filters.kind) == null ? void 0 : _a.value) != null ? _b : opts.initialFilter
900
903
  );
901
904
  useEffect(() => {
902
- if (flattenedQueryKind) {
903
- setSelectedKind(flattenedQueryKind);
905
+ if (queryParamKind) {
906
+ setSelectedKind(queryParamKind);
904
907
  }
905
- }, [flattenedQueryKind]);
908
+ }, [queryParamKind]);
906
909
  useEffect(() => {
907
910
  var _a2, _b2;
908
911
  if ((_a2 = filters.kind) == null ? void 0 : _a2.value) {
909
912
  setSelectedKind((_b2 = filters.kind) == null ? void 0 : _b2.value);
910
913
  }
911
914
  }, [filters.kind]);
912
- const { availableKinds, loading, error } = useAvailableKinds();
913
915
  useEffect(() => {
914
916
  updateFilters({
915
917
  kind: selectedKind ? new EntityKindFilter(selectedKind) : void 0
916
918
  });
917
919
  }, [selectedKind, updateFilters]);
920
+ const { allKinds, loading, error } = useAllKinds();
918
921
  return {
919
922
  loading,
920
923
  error,
921
- availableKinds,
924
+ allKinds: allKinds != null ? allKinds : [],
922
925
  selectedKind,
923
926
  setSelectedKind
924
927
  };
925
928
  }
926
929
  const EntityKindPicker = (props) => {
927
- const { hidden, initialFilter = "component" } = props;
930
+ const { allowedKinds, hidden, initialFilter = "component" } = props;
928
931
  const alertApi = useApi(alertApiRef);
929
- const { error, availableKinds, selectedKind, setSelectedKind } = useEntityKindFilter({
932
+ const { error, allKinds, selectedKind, setSelectedKind } = useEntityKindFilter({
930
933
  initialFilter
931
934
  });
932
935
  useEffect(() => {
@@ -937,20 +940,19 @@ const EntityKindPicker = (props) => {
937
940
  });
938
941
  }
939
942
  }, [error, alertApi]);
940
- if ((availableKinds == null ? void 0 : availableKinds.length) === 0 || error)
943
+ if (error)
941
944
  return null;
942
- const items = [
943
- ...availableKinds.map((kind) => ({
944
- value: kind,
945
- label: capitalize(kind)
946
- }))
947
- ];
945
+ const options = filterKinds(allKinds, allowedKinds, selectedKind);
946
+ const items = Object.keys(options).map((key) => ({
947
+ value: key,
948
+ label: options[key]
949
+ }));
948
950
  return hidden ? null : /* @__PURE__ */ React.createElement(Box, { pb: 1, pt: 1 }, /* @__PURE__ */ React.createElement(
949
951
  Select,
950
952
  {
951
953
  label: "Kind",
952
954
  items,
953
- selected: selectedKind,
955
+ selected: selectedKind.toLocaleLowerCase("en-US"),
954
956
  onChange: (value) => setSelectedKind(String(value))
955
957
  }
956
958
  ));