@backstage/plugin-catalog-react 0.0.0-nightly-20230604023641 → 0.0.0-nightly-20230606023337

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,6 +1,6 @@
1
1
  # @backstage/plugin-catalog-react
2
2
 
3
- ## 0.0.0-nightly-20230604023641
3
+ ## 0.0.0-nightly-20230606023337
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -11,21 +11,22 @@
11
11
 
12
12
  ### Patch Changes
13
13
 
14
+ - d68692aee97e: Make `useRelatedEntities` use `getEntitiesByRefs` under the hood
14
15
  - 429319d080cd: `EntityAutocompletePicker` add `initialSelectedOptions` prop
15
16
  - 429319d080cd: `EntityLifecycleFilter` loads data using the facets endpoint
16
17
  - Updated dependencies
17
- - @backstage/catalog-client@0.0.0-nightly-20230604023641
18
- - @backstage/integration@0.0.0-nightly-20230604023641
19
- - @backstage/errors@0.0.0-nightly-20230604023641
20
- - @backstage/core-components@0.0.0-nightly-20230604023641
21
- - @backstage/catalog-model@0.0.0-nightly-20230604023641
22
- - @backstage/core-plugin-api@0.0.0-nightly-20230604023641
23
- - @backstage/theme@0.0.0-nightly-20230604023641
24
- - @backstage/plugin-permission-common@0.0.0-nightly-20230604023641
25
- - @backstage/plugin-catalog-common@0.0.0-nightly-20230604023641
18
+ - @backstage/catalog-client@0.0.0-nightly-20230606023337
19
+ - @backstage/integration@0.0.0-nightly-20230606023337
20
+ - @backstage/errors@0.0.0-nightly-20230606023337
21
+ - @backstage/core-components@0.0.0-nightly-20230606023337
22
+ - @backstage/catalog-model@0.0.0-nightly-20230606023337
23
+ - @backstage/core-plugin-api@0.0.0-nightly-20230606023337
24
+ - @backstage/theme@0.0.0-nightly-20230606023337
25
+ - @backstage/plugin-permission-common@0.0.0-nightly-20230606023337
26
+ - @backstage/plugin-catalog-common@0.0.0-nightly-20230606023337
26
27
  - @backstage/types@1.0.2
27
28
  - @backstage/version-bridge@1.0.4
28
- - @backstage/plugin-permission-react@0.0.0-nightly-20230604023641
29
+ - @backstage/plugin-permission-react@0.0.0-nightly-20230606023337
29
30
 
30
31
  ## 1.7.0-next.1
31
32
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-react",
3
- "version": "0.0.0-nightly-20230604023641",
3
+ "version": "0.0.0-nightly-20230606023337",
4
4
  "main": "../dist/alpha.esm.js",
5
5
  "module": "../dist/alpha.esm.js",
6
6
  "types": "../dist/alpha.d.ts"
package/dist/index.d.ts CHANGED
@@ -569,7 +569,12 @@ declare function useEntityTypeFilter(): {
569
569
  setSelectedTypes: (types: string[]) => void;
570
570
  };
571
571
 
572
- /** @public */
572
+ /**
573
+ * Fetches all entities that appear in the entity's relations, optionally
574
+ * filtered by relation type and kind.
575
+ *
576
+ * @public
577
+ */
573
578
  declare function useRelatedEntities(entity: Entity, relationFilter: {
574
579
  type?: string;
575
580
  kind?: string;
package/dist/index.esm.js CHANGED
@@ -8,7 +8,7 @@ import { Select, Link, Progress, ErrorPanel, ResponseErrorPanel, OverflowTooltip
8
8
  import { ANNOTATION_SOURCE_LOCATION, parseLocationRef, stringifyEntityRef, parseEntityRef, RELATION_OWNED_BY, DEFAULT_NAMESPACE, getCompoundEntityRef, isUserEntity, isGroupEntity, RELATION_PART_OF, ANNOTATION_LOCATION, ANNOTATION_ORIGIN_LOCATION } from '@backstage/catalog-model';
9
9
  import { g as getEntityRelations } from './esm/useEntity-de64059a.esm.js';
10
10
  export { A as AsyncEntityProvider, E as EntityProvider, g as getEntityRelations, a as useAsyncEntity, u as useEntity } from './esm/useEntity-de64059a.esm.js';
11
- import { compact, isEqual, groupBy, chunk, debounce } from 'lodash';
11
+ import { compact, isEqual, debounce } from 'lodash';
12
12
  import qs from 'qs';
13
13
  import { useLocation, useNavigate } from 'react-router-dom';
14
14
  import useAsyncFn from 'react-use/lib/useAsyncFn';
@@ -38,7 +38,7 @@ import Star from '@material-ui/icons/Star';
38
38
  import StarBorder from '@material-ui/icons/StarBorder';
39
39
  import WorkIcon from '@material-ui/icons/Work';
40
40
  import HelpOutlineIcon from '@material-ui/icons/HelpOutline';
41
- import groupBy$1 from 'lodash/groupBy';
41
+ import groupBy from 'lodash/groupBy';
42
42
  import DialogContentText$1 from '@material-ui/core/DialogContentText';
43
43
  import YAML from 'yaml';
44
44
  import Alert$1 from '@material-ui/lab/Alert';
@@ -489,7 +489,6 @@ function useEntityTypeFilter() {
489
489
  };
490
490
  }
491
491
 
492
- const BATCH_SIZE = 20;
493
492
  function useRelatedEntities(entity, relationFilter) {
494
493
  var _a, _b;
495
494
  const filterByTypeLower = (_a = relationFilter == null ? void 0 : relationFilter.type) == null ? void 0 : _a.toLocaleLowerCase("en-US");
@@ -501,43 +500,16 @@ function useRelatedEntities(entity, relationFilter) {
501
500
  error
502
501
  } = useAsync(async () => {
503
502
  var _a2;
504
- const relations = (_a2 = entity.relations) == null ? void 0 : _a2.map((r) => ({ type: r.type, target: parseEntityRef(r.targetRef) })).filter(
505
- (r) => (!filterByTypeLower || r.type.toLocaleLowerCase("en-US") === filterByTypeLower) && (!filterByKindLower || r.target.kind === filterByKindLower)
503
+ const relations = (_a2 = entity.relations) == null ? void 0 : _a2.filter(
504
+ (r) => (!filterByTypeLower || r.type.toLocaleLowerCase("en-US") === filterByTypeLower) && (!filterByKindLower || parseEntityRef(r.targetRef).kind === filterByKindLower)
506
505
  );
507
- if (!relations) {
506
+ if (!(relations == null ? void 0 : relations.length)) {
508
507
  return [];
509
508
  }
510
- const relationsByKindAndNamespace = Object.values(
511
- groupBy(relations, ({ target }) => {
512
- return `${target.kind}:${target.namespace}`.toLocaleLowerCase("en-US");
513
- })
514
- );
515
- const batchedRelationsByKindAndNamespace = [];
516
- for (const rs of relationsByKindAndNamespace) {
517
- batchedRelationsByKindAndNamespace.push({
518
- // All relations in a group have the same kind and namespace, so its arbitrary which we pick
519
- kind: rs[0].target.kind,
520
- namespace: rs[0].target.namespace,
521
- nameBatches: chunk(
522
- rs.map((r) => r.target.name),
523
- BATCH_SIZE
524
- )
525
- });
526
- }
527
- const results = await Promise.all(
528
- batchedRelationsByKindAndNamespace.flatMap((rs) => {
529
- return rs.nameBatches.map((names) => {
530
- return catalogApi.getEntities({
531
- filter: {
532
- kind: rs.kind,
533
- "metadata.namespace": rs.namespace,
534
- "metadata.name": names
535
- }
536
- });
537
- });
538
- })
539
- );
540
- return results.flatMap((r) => r.items);
509
+ const { items } = await catalogApi.getEntitiesByRefs({
510
+ entityRefs: relations.map((r) => r.targetRef)
511
+ });
512
+ return items.filter((x) => Boolean(x));
541
513
  }, [entity, filterByTypeLower, filterByKindLower]);
542
514
  return {
543
515
  entities,
@@ -1996,7 +1968,7 @@ function OverviewPage(props) {
1996
1968
  relations = [],
1997
1969
  status = {}
1998
1970
  } = props.entity;
1999
- const groupedRelations = groupBy$1(
1971
+ const groupedRelations = groupBy(
2000
1972
  sortBy(relations, (r) => r.targetRef),
2001
1973
  "type"
2002
1974
  );