@backstage/plugin-org 0.6.26-next.2 → 0.6.27-next.0
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 +32 -0
- package/alpha/package.json +2 -2
- package/dist/components/Cards/Group/MembersList/MembersListCard.esm.js +6 -4
- package/dist/components/Cards/Group/MembersList/MembersListCard.esm.js.map +1 -1
- package/dist/components/Cards/OwnershipCard/ComponentsGrid.esm.js +8 -1
- package/dist/components/Cards/OwnershipCard/ComponentsGrid.esm.js.map +1 -1
- package/dist/components/Cards/OwnershipCard/OwnershipCard.esm.js +12 -12
- package/dist/components/Cards/OwnershipCard/OwnershipCard.esm.js.map +1 -1
- package/dist/components/Cards/OwnershipCard/useGetEntities.esm.js +5 -5
- package/dist/components/Cards/OwnershipCard/useGetEntities.esm.js.map +1 -1
- package/dist/helpers/helpers.esm.js +5 -4
- package/dist/helpers/helpers.esm.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/package.json +14 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @backstage/plugin-org
|
|
2
2
|
|
|
3
|
+
## 0.6.27-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c307ef4: Added `relationType` property to EntityMembersListCard component that allows for display users related to a group via some other relationship aside from `memberOf`.
|
|
8
|
+
|
|
9
|
+
Also, as a side effect, the `relationsType` property has been deprecated in favor of a more accurately named `relationAggregation` property.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/core-components@0.14.9-next.0
|
|
13
|
+
- @backstage/plugin-catalog-react@1.12.2-next.0
|
|
14
|
+
- @backstage/frontend-plugin-api@0.6.7-next.0
|
|
15
|
+
- @backstage/core-compat-api@0.2.7-next.0
|
|
16
|
+
- @backstage/core-plugin-api@1.9.3
|
|
17
|
+
- @backstage/catalog-model@1.5.0
|
|
18
|
+
- @backstage/plugin-catalog-common@1.0.24
|
|
19
|
+
|
|
20
|
+
## 0.6.26
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- d8e2f53: The `catalogIndex` external route is now optional and will by default bind to the catalog index page if it is available.
|
|
25
|
+
- d44a20a: Added additional plugin metadata to `package.json`.
|
|
26
|
+
- Updated dependencies
|
|
27
|
+
- @backstage/core-components@0.14.8
|
|
28
|
+
- @backstage/core-compat-api@0.2.6
|
|
29
|
+
- @backstage/core-plugin-api@1.9.3
|
|
30
|
+
- @backstage/plugin-catalog-common@1.0.24
|
|
31
|
+
- @backstage/plugin-catalog-react@1.12.1
|
|
32
|
+
- @backstage/frontend-plugin-api@0.6.6
|
|
33
|
+
- @backstage/catalog-model@1.5.0
|
|
34
|
+
|
|
3
35
|
## 0.6.26-next.2
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/alpha/package.json
CHANGED
|
@@ -97,8 +97,9 @@ const MembersListCard = (props) => {
|
|
|
97
97
|
memberDisplayTitle = "Members",
|
|
98
98
|
pageSize = 50,
|
|
99
99
|
showAggregateMembersToggle,
|
|
100
|
-
|
|
100
|
+
relationType = "memberof"
|
|
101
101
|
} = props;
|
|
102
|
+
const relationAggregation = props.relationAggregation ?? props.relationsType ?? "direct";
|
|
102
103
|
const classes = useListStyles();
|
|
103
104
|
const { entity: groupEntity } = useEntity();
|
|
104
105
|
const {
|
|
@@ -113,7 +114,7 @@ const MembersListCard = (props) => {
|
|
|
113
114
|
setPage(pageIndex);
|
|
114
115
|
};
|
|
115
116
|
const [showAggregateMembers, setShowAggregateMembers] = useState(
|
|
116
|
-
|
|
117
|
+
relationAggregation === "aggregated"
|
|
117
118
|
);
|
|
118
119
|
const { loading: loadingDescendantMembers, value: descendantMembers } = useAsync(async () => {
|
|
119
120
|
if (!showAggregateMembers) {
|
|
@@ -121,7 +122,8 @@ const MembersListCard = (props) => {
|
|
|
121
122
|
}
|
|
122
123
|
return await getAllDesendantMembersForGroupEntity(
|
|
123
124
|
groupEntity,
|
|
124
|
-
catalogApi
|
|
125
|
+
catalogApi,
|
|
126
|
+
relationType
|
|
125
127
|
);
|
|
126
128
|
}, [catalogApi, groupEntity, showAggregateMembers]);
|
|
127
129
|
const {
|
|
@@ -132,7 +134,7 @@ const MembersListCard = (props) => {
|
|
|
132
134
|
const membersList = await catalogApi.getEntities({
|
|
133
135
|
filter: {
|
|
134
136
|
kind: "User",
|
|
135
|
-
|
|
137
|
+
[`relations.${relationType.toLocaleLowerCase("en-US")}`]: [
|
|
136
138
|
stringifyEntityRef({
|
|
137
139
|
kind: "group",
|
|
138
140
|
namespace: groupNamespace.toLocaleLowerCase("en-US"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MembersListCard.esm.js","sources":["../../../../../src/components/Cards/Group/MembersList/MembersListCard.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DEFAULT_NAMESPACE,\n GroupEntity,\n UserEntity,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { catalogApiRef, useEntity } from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport Grid from '@material-ui/core/Grid';\nimport Switch from '@material-ui/core/Switch';\nimport Typography from '@material-ui/core/Typography';\nimport { createStyles, makeStyles, Theme } from '@material-ui/core/styles';\nimport Pagination from '@material-ui/lab/Pagination';\nimport React, { useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\n\nimport {\n Avatar,\n InfoCard,\n Progress,\n ResponseErrorPanel,\n Link,\n OverflowTooltip,\n} from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n getAllDesendantMembersForGroupEntity,\n removeDuplicateEntitiesFrom,\n} from '../../../../helpers/helpers';\nimport { EntityRefLink } from '@backstage/plugin-catalog-react';\nimport { EntityRelationAggregation } from '../../types';\n\nconst useStyles = makeStyles(\n (theme: Theme) =>\n createStyles({\n card: {\n border: `1px solid ${theme.palette.divider}`,\n boxShadow: theme.shadows[2],\n borderRadius: '4px',\n overflow: 'visible',\n position: 'relative',\n margin: theme.spacing(4, 1, 1),\n flex: '1',\n minWidth: '0px',\n },\n avatar: {\n position: 'absolute',\n top: '-2rem',\n },\n }),\n { name: 'MembersListCardComponent' },\n);\n\nconst MemberComponent = (props: { member: UserEntity }) => {\n const classes = useStyles();\n const {\n metadata: { name: metaName, description },\n spec: { profile },\n } = props.member;\n const displayName = profile?.displayName ?? metaName;\n\n return (\n <Box className={classes.card}>\n <Box\n display=\"flex\"\n flexDirection=\"column\"\n m={3}\n alignItems=\"center\"\n justifyContent=\"center\"\n >\n <Avatar\n displayName={displayName}\n picture={profile?.picture}\n classes={classes}\n />\n <Box\n pt={2}\n sx={{\n width: '100%',\n }}\n textAlign=\"center\"\n >\n <Typography variant=\"h6\">\n <EntityRefLink\n data-testid=\"user-link\"\n entityRef={props.member}\n title={displayName}\n />\n </Typography>\n {profile?.email && (\n <Link to={`mailto:${profile.email}`}>\n <OverflowTooltip text={profile.email} />\n </Link>\n )}\n {description && (\n <Typography variant=\"subtitle2\">{description}</Typography>\n )}\n </Box>\n </Box>\n </Box>\n );\n};\n\nconst useListStyles = makeStyles(theme => ({\n root: {\n height: '100%',\n },\n cardContent: {\n overflow: 'auto',\n },\n memberList: {\n display: 'grid',\n gap: theme.spacing(1.5),\n gridTemplateColumns: `repeat(auto-fit, minmax(auto, ${theme.spacing(\n 34,\n )}px))`,\n },\n}));\n\n/** @public */\nexport const MembersListCard = (props: {\n memberDisplayTitle?: string;\n pageSize?: number;\n showAggregateMembersToggle?: boolean;\n relationsType?: EntityRelationAggregation;\n}) => {\n const {\n memberDisplayTitle = 'Members',\n pageSize = 50,\n showAggregateMembersToggle,\n relationsType = 'direct',\n } = props;\n const classes = useListStyles();\n\n const { entity: groupEntity } = useEntity<GroupEntity>();\n const {\n metadata: { name: groupName, namespace: grpNamespace },\n spec: { profile },\n } = groupEntity;\n const catalogApi = useApi(catalogApiRef);\n\n const displayName = profile?.displayName ?? groupName;\n\n const groupNamespace = grpNamespace || DEFAULT_NAMESPACE;\n\n const [page, setPage] = React.useState(1);\n const pageChange = (_: React.ChangeEvent<unknown>, pageIndex: number) => {\n setPage(pageIndex);\n };\n\n const [showAggregateMembers, setShowAggregateMembers] = useState(\n relationsType === 'aggregated',\n );\n\n const { loading: loadingDescendantMembers, value: descendantMembers } =\n useAsync(async () => {\n if (!showAggregateMembers) {\n return [] as UserEntity[];\n }\n\n return await getAllDesendantMembersForGroupEntity(\n groupEntity,\n catalogApi,\n );\n }, [catalogApi, groupEntity, showAggregateMembers]);\n const {\n loading,\n error,\n value: directMembers,\n } = useAsync(async () => {\n const membersList = await catalogApi.getEntities({\n filter: {\n kind: 'User',\n 'relations.memberof': [\n stringifyEntityRef({\n kind: 'group',\n namespace: groupNamespace.toLocaleLowerCase('en-US'),\n name: groupName.toLocaleLowerCase('en-US'),\n }),\n ],\n },\n });\n\n return membersList.items as UserEntity[];\n }, [catalogApi, groupEntity]);\n\n const members = removeDuplicateEntitiesFrom(\n [\n ...(directMembers ?? []),\n ...(descendantMembers && showAggregateMembers ? descendantMembers : []),\n ].sort((a, b) =>\n stringifyEntityRef(a).localeCompare(stringifyEntityRef(b)),\n ),\n ) as UserEntity[];\n\n if (loading) {\n return <Progress />;\n } else if (error) {\n return <ResponseErrorPanel error={error} />;\n }\n\n const nbPages = Math.ceil((members?.length || 0) / pageSize);\n const paginationLabel = nbPages < 2 ? '' : `, page ${page} of ${nbPages}`;\n\n const pagination = (\n <Pagination\n count={nbPages}\n page={page}\n onChange={pageChange}\n showFirstButton\n showLastButton\n />\n );\n\n let memberList: React.JSX.Element;\n if (members && members.length > 0) {\n memberList = (\n <Box className={classes.memberList}>\n {members.slice(pageSize * (page - 1), pageSize * page).map(member => (\n <MemberComponent member={member} key={stringifyEntityRef(member)} />\n ))}\n </Box>\n );\n } else {\n memberList = (\n <Box p={2}>\n <Typography>\n This group has no {memberDisplayTitle.toLocaleLowerCase()}.\n </Typography>\n </Box>\n );\n }\n\n return (\n <Grid item className={classes.root}>\n <InfoCard\n title={`${memberDisplayTitle} (${\n members?.length || 0\n }${paginationLabel})`}\n subheader={`of ${displayName}`}\n {...(nbPages <= 1 ? {} : { actions: pagination })}\n className={classes.root}\n cardClassName={classes.cardContent}\n >\n {showAggregateMembersToggle && (\n <>\n Direct Members\n <Switch\n color=\"primary\"\n checked={showAggregateMembers}\n onChange={() => {\n setShowAggregateMembers(!showAggregateMembers);\n }}\n inputProps={{ 'aria-label': 'Users Type Switch' }}\n />\n Aggregated Members\n </>\n )}\n {showAggregateMembers && loadingDescendantMembers ? (\n <Progress />\n ) : (\n memberList\n )}\n </InfoCard>\n </Grid>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAgDA,MAAM,SAAY,GAAA,UAAA;AAAA,EAChB,CAAC,UACC,YAAa,CAAA;AAAA,IACX,IAAM,EAAA;AAAA,MACJ,MAAQ,EAAA,CAAA,UAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,OAAO,CAAA,CAAA;AAAA,MAC1C,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MAC1B,YAAc,EAAA,KAAA;AAAA,MACd,QAAU,EAAA,SAAA;AAAA,MACV,QAAU,EAAA,UAAA;AAAA,MACV,MAAQ,EAAA,KAAA,CAAM,OAAQ,CAAA,CAAA,EAAG,GAAG,CAAC,CAAA;AAAA,MAC7B,IAAM,EAAA,GAAA;AAAA,MACN,QAAU,EAAA,KAAA;AAAA,KACZ;AAAA,IACA,MAAQ,EAAA;AAAA,MAC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AAe,OAAQ,CAAA,WAAA;AAAA,KAAA;AAAA,IAEtB,0BAAA,8DACG,gBAEA,kBAAA,KAAA,CAAA,aAAA;AAAA,MAAC,MAAA;AAAA,MAAA;AAAA,QACC,KAAM,EAAA,SAAA;AAAA,QACN,OAAS,EAAA,oBAAA;AAAA,QACT,UAAU,MAAM;AACd,UAAA,uBAAA,CAAwB,CAAC,oBAAoB,CAAA,CAAA;AAAA,SAC/C;AAAA,QACA,UAAA,EAAY,EAAE,YAAA,EAAc,mBAAoB,EAAA;AAAA,OAAA;AAAA,OAChD,oBAEJ,CAAA;AAAA,IAED,oBAAwB,IAAA,wBAAA,mBACtB,KAAA,CAAA,aAAA,CAAA,QAAA,EAAA,IAAS,CAEV,GAAA,UAAA;AAAA,GAGN,CAAA,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"MembersListCard.esm.js","sources":["../../../../../src/components/Cards/Group/MembersList/MembersListCard.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DEFAULT_NAMESPACE,\n GroupEntity,\n UserEntity,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { catalogApiRef, useEntity } from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport Grid from '@material-ui/core/Grid';\nimport Switch from '@material-ui/core/Switch';\nimport Typography from '@material-ui/core/Typography';\nimport { createStyles, makeStyles, Theme } from '@material-ui/core/styles';\nimport Pagination from '@material-ui/lab/Pagination';\nimport React, { useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\n\nimport {\n Avatar,\n InfoCard,\n Progress,\n ResponseErrorPanel,\n Link,\n OverflowTooltip,\n} from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n getAllDesendantMembersForGroupEntity,\n removeDuplicateEntitiesFrom,\n} from '../../../../helpers/helpers';\nimport { EntityRefLink } from '@backstage/plugin-catalog-react';\nimport { EntityRelationAggregation } from '../../types';\n\nconst useStyles = makeStyles(\n (theme: Theme) =>\n createStyles({\n card: {\n border: `1px solid ${theme.palette.divider}`,\n boxShadow: theme.shadows[2],\n borderRadius: '4px',\n overflow: 'visible',\n position: 'relative',\n margin: theme.spacing(4, 1, 1),\n flex: '1',\n minWidth: '0px',\n },\n avatar: {\n position: 'absolute',\n top: '-2rem',\n },\n }),\n { name: 'MembersListCardComponent' },\n);\n\nconst MemberComponent = (props: { member: UserEntity }) => {\n const classes = useStyles();\n const {\n metadata: { name: metaName, description },\n spec: { profile },\n } = props.member;\n const displayName = profile?.displayName ?? metaName;\n\n return (\n <Box className={classes.card}>\n <Box\n display=\"flex\"\n flexDirection=\"column\"\n m={3}\n alignItems=\"center\"\n justifyContent=\"center\"\n >\n <Avatar\n displayName={displayName}\n picture={profile?.picture}\n classes={classes}\n />\n <Box\n pt={2}\n sx={{\n width: '100%',\n }}\n textAlign=\"center\"\n >\n <Typography variant=\"h6\">\n <EntityRefLink\n data-testid=\"user-link\"\n entityRef={props.member}\n title={displayName}\n />\n </Typography>\n {profile?.email && (\n <Link to={`mailto:${profile.email}`}>\n <OverflowTooltip text={profile.email} />\n </Link>\n )}\n {description && (\n <Typography variant=\"subtitle2\">{description}</Typography>\n )}\n </Box>\n </Box>\n </Box>\n );\n};\n\nconst useListStyles = makeStyles(theme => ({\n root: {\n height: '100%',\n },\n cardContent: {\n overflow: 'auto',\n },\n memberList: {\n display: 'grid',\n gap: theme.spacing(1.5),\n gridTemplateColumns: `repeat(auto-fit, minmax(auto, ${theme.spacing(\n 34,\n )}px))`,\n },\n}));\n\n/** @public */\nexport const MembersListCard = (props: {\n memberDisplayTitle?: string;\n pageSize?: number;\n showAggregateMembersToggle?: boolean;\n relationType?: string;\n /** @deprecated Please use `relationAggregation` instead */\n relationsType?: EntityRelationAggregation;\n relationAggregation?: EntityRelationAggregation;\n}) => {\n const {\n memberDisplayTitle = 'Members',\n pageSize = 50,\n showAggregateMembersToggle,\n relationType = 'memberof',\n } = props;\n const relationAggregation =\n props.relationAggregation ?? props.relationsType ?? 'direct';\n const classes = useListStyles();\n\n const { entity: groupEntity } = useEntity<GroupEntity>();\n const {\n metadata: { name: groupName, namespace: grpNamespace },\n spec: { profile },\n } = groupEntity;\n const catalogApi = useApi(catalogApiRef);\n\n const displayName = profile?.displayName ?? groupName;\n\n const groupNamespace = grpNamespace || DEFAULT_NAMESPACE;\n\n const [page, setPage] = React.useState(1);\n const pageChange = (_: React.ChangeEvent<unknown>, pageIndex: number) => {\n setPage(pageIndex);\n };\n\n const [showAggregateMembers, setShowAggregateMembers] = useState(\n relationAggregation === 'aggregated',\n );\n\n const { loading: loadingDescendantMembers, value: descendantMembers } =\n useAsync(async () => {\n if (!showAggregateMembers) {\n return [] as UserEntity[];\n }\n\n return await getAllDesendantMembersForGroupEntity(\n groupEntity,\n catalogApi,\n relationType,\n );\n }, [catalogApi, groupEntity, showAggregateMembers]);\n const {\n loading,\n error,\n value: directMembers,\n } = useAsync(async () => {\n const membersList = await catalogApi.getEntities({\n filter: {\n kind: 'User',\n [`relations.${relationType.toLocaleLowerCase('en-US')}`]: [\n stringifyEntityRef({\n kind: 'group',\n namespace: groupNamespace.toLocaleLowerCase('en-US'),\n name: groupName.toLocaleLowerCase('en-US'),\n }),\n ],\n },\n });\n\n return membersList.items as UserEntity[];\n }, [catalogApi, groupEntity]);\n\n const members = removeDuplicateEntitiesFrom(\n [\n ...(directMembers ?? []),\n ...(descendantMembers && showAggregateMembers ? descendantMembers : []),\n ].sort((a, b) =>\n stringifyEntityRef(a).localeCompare(stringifyEntityRef(b)),\n ),\n ) as UserEntity[];\n\n if (loading) {\n return <Progress />;\n } else if (error) {\n return <ResponseErrorPanel error={error} />;\n }\n\n const nbPages = Math.ceil((members?.length || 0) / pageSize);\n const paginationLabel = nbPages < 2 ? '' : `, page ${page} of ${nbPages}`;\n\n const pagination = (\n <Pagination\n count={nbPages}\n page={page}\n onChange={pageChange}\n showFirstButton\n showLastButton\n />\n );\n\n let memberList: React.JSX.Element;\n if (members && members.length > 0) {\n memberList = (\n <Box className={classes.memberList}>\n {members.slice(pageSize * (page - 1), pageSize * page).map(member => (\n <MemberComponent member={member} key={stringifyEntityRef(member)} />\n ))}\n </Box>\n );\n } else {\n memberList = (\n <Box p={2}>\n <Typography>\n This group has no {memberDisplayTitle.toLocaleLowerCase()}.\n </Typography>\n </Box>\n );\n }\n\n return (\n <Grid item className={classes.root}>\n <InfoCard\n title={`${memberDisplayTitle} (${\n members?.length || 0\n }${paginationLabel})`}\n subheader={`of ${displayName}`}\n {...(nbPages <= 1 ? {} : { actions: pagination })}\n className={classes.root}\n cardClassName={classes.cardContent}\n >\n {showAggregateMembersToggle && (\n <>\n Direct Members\n <Switch\n color=\"primary\"\n checked={showAggregateMembers}\n onChange={() => {\n setShowAggregateMembers(!showAggregateMembers);\n }}\n inputProps={{ 'aria-label': 'Users Type Switch' }}\n />\n Aggregated Members\n </>\n )}\n {showAggregateMembers && loadingDescendantMembers ? (\n <Progress />\n ) : (\n memberList\n )}\n </InfoCard>\n </Grid>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAgDA,MAAM,SAAY,GAAA,UAAA;AAAA,EAChB,CAAC,UACC,YAAa,CAAA;AAAA,IACX,IAAM,EAAA;AAAA,MACJ,MAAQ,EAAA,CAAA,UAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,OAAO,CAAA,CAAA;AAAA,MAC1C,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MAC1B,YAAc,EAAA,KAAA;AAAA,MACd,QAAU,EAAA,SAAA;AAAA,M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A,EAAW,QAAQ,IAC5B,EAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,KAAA,EAAO,GAAG,kBAAkB,CAAA,EAAA,EAC1B,SAAS,MAAU,IAAA,CACrB,GAAG,eAAe,CAAA,CAAA,CAAA;AAAA,MAClB,SAAA,EAAW,MAAM,WAAW,CAAA,CAAA;AAAA,MAC3B,GAAI,OAAW,IAAA,CAAA,GAAI,EAAK,GAAA,EAAE,SAAS,UAAW,EAAA;AAAA,MAC/C,WAAW,OAAQ,CAAA,IAAA;AAAA,MACnB,eAAe,OAAQ,CAAA,WAAA;AAAA,KAAA;AAAA,IAEtB,0BAAA,8DACG,gBAEA,kBAAA,KAAA,CAAA,aAAA;AAAA,MAAC,MAAA;AAAA,MAAA;AAAA,QACC,KAAM,EAAA,SAAA;AAAA,QACN,OAAS,EAAA,oBAAA;AAAA,QACT,UAAU,MAAM;AACd,UAAA,uBAAA,CAAwB,CAAC,oBAAoB,CAAA,CAAA;AAAA,SAC/C;AAAA,QACA,UAAA,EAAY,EAAE,YAAA,EAAc,mBAAoB,EAAA;AAAA,OAAA;AAAA,OAChD,oBAEJ,CAAA;AAAA,IAED,oBAAwB,IAAA,wBAAA,mBACtB,KAAA,CAAA,aAAA,CAAA,QAAA,EAAA,IAAS,CAEV,GAAA,UAAA;AAAA,GAGN,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -76,13 +76,20 @@ const ComponentsGrid = ({
|
|
|
76
76
|
className,
|
|
77
77
|
entity,
|
|
78
78
|
relationsType,
|
|
79
|
+
relationAggregation,
|
|
79
80
|
entityFilterKind,
|
|
80
81
|
entityLimit = 6
|
|
81
82
|
}) => {
|
|
82
83
|
const catalogLink = useRouteRef(catalogIndexRouteRef);
|
|
84
|
+
if (!relationsType && !relationAggregation) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
"The relationAggregation property must be set as an EntityRelationAggregation type."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
83
89
|
const { componentsWithCounters, loading, error } = useGetEntities(
|
|
84
90
|
entity,
|
|
85
|
-
relationsType,
|
|
91
|
+
relationAggregation ?? relationsType,
|
|
92
|
+
// we can safely use the non-null assertion here because of the run-time check above
|
|
86
93
|
entityFilterKind,
|
|
87
94
|
entityLimit
|
|
88
95
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentsGrid.esm.js","sources":["../../../../src/components/Cards/OwnershipCard/ComponentsGrid.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity } from '@backstage/catalog-model';\nimport {\n Link,\n OverflowTooltip,\n Progress,\n ResponseErrorPanel,\n} from '@backstage/core-components';\nimport { useRouteRef } from '@backstage/core-plugin-api';\nimport Box from '@material-ui/core/Box';\nimport Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport { createStyles, makeStyles } from '@material-ui/core/styles';\nimport React from 'react';\nimport pluralize from 'pluralize';\nimport { catalogIndexRouteRef } from '../../../routes';\nimport { useGetEntities } from './useGetEntities';\nimport { EntityRelationAggregation } from '../types';\n\nconst useStyles = makeStyles(theme =>\n createStyles({\n card: {\n border: `1px solid ${theme.palette.divider}`,\n boxShadow: theme.shadows[2],\n borderRadius: '4px',\n padding: theme.spacing(2),\n transition: `${theme.transitions.duration.standard}ms`,\n '&:hover': {\n boxShadow: theme.shadows[4],\n },\n height: '100%',\n },\n bold: {\n fontWeight: theme.typography.fontWeightBold,\n },\n smallFont: {\n fontSize: theme.typography.body2.fontSize,\n },\n entityTypeBox: {\n background: (props: { type: string }) =>\n theme.getPageTheme({ themeId: props.type }).backgroundImage,\n color: (props: { type: string }) =>\n theme.getPageTheme({ themeId: props.type }).fontColor,\n },\n }),\n);\n\nconst EntityCountTile = ({\n counter,\n type,\n kind,\n url,\n}: {\n counter: number;\n type?: string;\n kind: string;\n url?: string;\n}) => {\n const classes = useStyles({ type: type ?? kind });\n\n const rawTitle = type ?? kind;\n const isLongText = rawTitle.length > 10;\n\n const tile = (\n <Box\n className={`${classes.card} ${classes.entityTypeBox}`}\n display=\"flex\"\n flexDirection=\"column\"\n alignItems=\"center\"\n >\n <Typography className={classes.bold} variant=\"h6\">\n {counter}\n </Typography>\n <Box sx={{ width: '100%', textAlign: 'center' }}>\n <Typography\n className={`${classes.bold} ${isLongText && classes.smallFont}`}\n variant=\"h6\"\n >\n <OverflowTooltip\n text={pluralize(rawTitle.toLocaleUpperCase('en-US'), counter)}\n />\n </Typography>\n </Box>\n {type && <Typography variant=\"subtitle1\">{kind}</Typography>}\n </Box>\n );\n\n if (url) {\n return (\n <Link to={url} variant=\"body2\">\n {tile}\n </Link>\n );\n }\n return tile;\n};\n\nexport const ComponentsGrid = ({\n className,\n entity,\n relationsType,\n entityFilterKind,\n entityLimit = 6,\n}: {\n className?: string;\n entity: Entity;\n relationsType
|
|
1
|
+
{"version":3,"file":"ComponentsGrid.esm.js","sources":["../../../../src/components/Cards/OwnershipCard/ComponentsGrid.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity } from '@backstage/catalog-model';\nimport {\n Link,\n OverflowTooltip,\n Progress,\n ResponseErrorPanel,\n} from '@backstage/core-components';\nimport { useRouteRef } from '@backstage/core-plugin-api';\nimport Box from '@material-ui/core/Box';\nimport Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport { createStyles, makeStyles } from '@material-ui/core/styles';\nimport React from 'react';\nimport pluralize from 'pluralize';\nimport { catalogIndexRouteRef } from '../../../routes';\nimport { useGetEntities } from './useGetEntities';\nimport { EntityRelationAggregation } from '../types';\n\nconst useStyles = makeStyles(theme =>\n createStyles({\n card: {\n border: `1px solid ${theme.palette.divider}`,\n boxShadow: theme.shadows[2],\n borderRadius: '4px',\n padding: theme.spacing(2),\n transition: `${theme.transitions.duration.standard}ms`,\n '&:hover': {\n boxShadow: theme.shadows[4],\n },\n height: '100%',\n },\n bold: {\n fontWeight: theme.typography.fontWeightBold,\n },\n smallFont: {\n fontSize: theme.typography.body2.fontSize,\n },\n entityTypeBox: {\n background: (props: { type: string }) =>\n theme.getPageTheme({ themeId: props.type }).backgroundImage,\n color: (props: { type: string }) =>\n theme.getPageTheme({ themeId: props.type }).fontColor,\n },\n }),\n);\n\nconst EntityCountTile = ({\n counter,\n type,\n kind,\n url,\n}: {\n counter: number;\n type?: string;\n kind: string;\n url?: string;\n}) => {\n const classes = useStyles({ type: type ?? kind });\n\n const rawTitle = type ?? kind;\n const isLongText = rawTitle.length > 10;\n\n const tile = (\n <Box\n className={`${classes.card} ${classes.entityTypeBox}`}\n display=\"flex\"\n flexDirection=\"column\"\n alignItems=\"center\"\n >\n <Typography className={classes.bold} variant=\"h6\">\n {counter}\n </Typography>\n <Box sx={{ width: '100%', textAlign: 'center' }}>\n <Typography\n className={`${classes.bold} ${isLongText && classes.smallFont}`}\n variant=\"h6\"\n >\n <OverflowTooltip\n text={pluralize(rawTitle.toLocaleUpperCase('en-US'), counter)}\n />\n </Typography>\n </Box>\n {type && <Typography variant=\"subtitle1\">{kind}</Typography>}\n </Box>\n );\n\n if (url) {\n return (\n <Link to={url} variant=\"body2\">\n {tile}\n </Link>\n );\n }\n return tile;\n};\n\nexport const ComponentsGrid = ({\n className,\n entity,\n relationsType,\n relationAggregation,\n entityFilterKind,\n entityLimit = 6,\n}: {\n className?: string;\n entity: Entity;\n /** @deprecated Please use relationAggregation instead */\n relationsType?: EntityRelationAggregation;\n relationAggregation?: EntityRelationAggregation;\n entityFilterKind?: string[];\n entityLimit?: number;\n}) => {\n const catalogLink = useRouteRef(catalogIndexRouteRef);\n if (!relationsType && !relationAggregation) {\n throw new Error(\n 'The relationAggregation property must be set as an EntityRelationAggregation type.',\n );\n }\n const { componentsWithCounters, loading, error } = useGetEntities(\n entity,\n (relationAggregation ?? relationsType)!, // we can safely use the non-null assertion here because of the run-time check above\n entityFilterKind,\n entityLimit,\n );\n\n if (loading) {\n return <Progress />;\n } else if (error) {\n return <ResponseErrorPanel error={error} />;\n }\n\n return (\n <Grid container className={className}>\n {componentsWithCounters?.map(c => (\n <Grid item xs={6} md={6} lg={4} key={c.type ?? c.kind}>\n <EntityCountTile\n counter={c.counter}\n kind={c.kind}\n type={c.type}\n url={catalogLink && `${catalogLink()}/?${c.queryParams}`}\n />\n </Grid>\n ))}\n </Grid>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAkCA,MAAM,SAAY,GAAA,UAAA;AAAA,EAAW,WAC3B,YAAa,CAAA;AAAA,IACX,IAAM,EAAA;AAAA,MACJ,MAAQ,EAAA,CAAA,UAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,OAAO,CAAA,CAAA;AAAA,MAC1C,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MAC1B,YAAc,EAAA,KAAA;AAAA,MACd,OAAA,EAAS,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACxB,UAAY,EAAA,CAAA,EAAG,KAAM,CAAA,WAAA,CAAY,SAAS,QAAQ,CAAA,EAAA,CAAA;AAAA,MAClD,SAAW,EAAA;AAAA,QACT,SAAA,EAA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,KAAA,EAAU,GAAA,cAAA;AAAA,IACjD,MAAA;AAAA,IACC,mBAAuB,IAAA,aAAA;AAAA;AAAA,IACxB,gBAAA;AAAA,IACA,WAAA;AAAA,GACF,CAAA;AAEA,EAAA,IAAI,OAAS,EAAA;AACX,IAAA,2CAAQ,QAAS,EAAA,IAAA,CAAA,CAAA;AAAA,aACR,KAAO,EAAA;AAChB,IAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,sBAAmB,KAAc,EAAA,CAAA,CAAA;AAAA,GAC3C;AAEA,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,QAAK,SAAS,EAAA,IAAA,EAAC,aACb,sBAAwB,EAAA,GAAA,CAAI,CAC3B,CAAA,qBAAA,KAAA,CAAA,aAAA,CAAC,IAAK,EAAA,EAAA,IAAA,EAAI,MAAC,EAAI,EAAA,CAAA,EAAG,IAAI,CAAG,EAAA,EAAA,EAAI,GAAG,GAAK,EAAA,CAAA,CAAE,IAAQ,IAAA,CAAA,CAAE,IAC/C,EAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,eAAA;AAAA,IAAA;AAAA,MACC,SAAS,CAAE,CAAA,OAAA;AAAA,MACX,MAAM,CAAE,CAAA,IAAA;AAAA,MACR,MAAM,CAAE,CAAA,IAAA;AAAA,MACR,KAAK,WAAe,IAAA,CAAA,EAAG,aAAa,CAAA,EAAA,EAAK,EAAE,WAAW,CAAA,CAAA;AAAA,KAAA;AAAA,GAE1D,CACD,CACH,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -49,21 +49,21 @@ const OwnershipCard = (props) => {
|
|
|
49
49
|
variant,
|
|
50
50
|
entityFilterKind,
|
|
51
51
|
hideRelationsToggle,
|
|
52
|
-
relationsType,
|
|
53
52
|
entityLimit = 6
|
|
54
53
|
} = props;
|
|
54
|
+
const relationAggregation = props.relationAggregation ?? props.relationsType;
|
|
55
55
|
const relationsToggle = hideRelationsToggle === void 0 ? false : hideRelationsToggle;
|
|
56
56
|
const classes = useStyles();
|
|
57
57
|
const { entity } = useEntity();
|
|
58
|
-
const
|
|
59
|
-
const [
|
|
60
|
-
|
|
58
|
+
const defaultRelationAggregation = entity.kind === "User" ? "aggregated" : "direct";
|
|
59
|
+
const [getRelationAggregation, setRelationAggregation] = useState(
|
|
60
|
+
relationAggregation ?? defaultRelationAggregation
|
|
61
61
|
);
|
|
62
62
|
useEffect(() => {
|
|
63
|
-
if (!
|
|
64
|
-
|
|
63
|
+
if (!relationAggregation) {
|
|
64
|
+
setRelationAggregation(defaultRelationAggregation);
|
|
65
65
|
}
|
|
66
|
-
}, [
|
|
66
|
+
}, [setRelationAggregation, defaultRelationAggregation, relationAggregation]);
|
|
67
67
|
return /* @__PURE__ */ React.createElement(
|
|
68
68
|
InfoCard,
|
|
69
69
|
{
|
|
@@ -83,16 +83,16 @@ const OwnershipCard = (props) => {
|
|
|
83
83
|
{
|
|
84
84
|
placement: "top",
|
|
85
85
|
arrow: true,
|
|
86
|
-
title: `${
|
|
86
|
+
title: `${getRelationAggregation === "direct" ? "Direct" : "Aggregated"} Relations`
|
|
87
87
|
},
|
|
88
88
|
/* @__PURE__ */ React.createElement(
|
|
89
89
|
Switch,
|
|
90
90
|
{
|
|
91
91
|
color: "primary",
|
|
92
|
-
checked:
|
|
92
|
+
checked: getRelationAggregation !== "direct",
|
|
93
93
|
onChange: () => {
|
|
94
|
-
const
|
|
95
|
-
|
|
94
|
+
const updatedRelationAggregation = getRelationAggregation === "direct" ? "aggregated" : "direct";
|
|
95
|
+
setRelationAggregation(updatedRelationAggregation);
|
|
96
96
|
},
|
|
97
97
|
name: "pin",
|
|
98
98
|
inputProps: { "aria-label": "Ownership Type Switch" }
|
|
@@ -107,7 +107,7 @@ const OwnershipCard = (props) => {
|
|
|
107
107
|
className: classes.grid,
|
|
108
108
|
entity,
|
|
109
109
|
entityLimit,
|
|
110
|
-
|
|
110
|
+
relationAggregation: getRelationAggregation,
|
|
111
111
|
entityFilterKind
|
|
112
112
|
}
|
|
113
113
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OwnershipCard.esm.js","sources":["../../../../src/components/Cards/OwnershipCard/OwnershipCard.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InfoCard, InfoCardVariants } from '@backstage/core-components';\nimport { useEntity } from '@backstage/plugin-catalog-react';\nimport List from '@material-ui/core/List';\nimport ListItem from '@material-ui/core/ListItem';\nimport ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';\nimport ListItemText from '@material-ui/core/ListItemText';\nimport Switch from '@material-ui/core/Switch';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { makeStyles } from '@material-ui/core/styles';\nimport React, { useEffect, useState } from 'react';\nimport { ComponentsGrid } from './ComponentsGrid';\nimport { EntityRelationAggregation } from '../types';\n\nconst useStyles = makeStyles(theme => ({\n card: {\n maxHeight: '100%',\n },\n cardContent: {\n display: 'flex',\n flexDirection: 'column',\n overflow: 'hidden',\n },\n list: {\n [theme.breakpoints.down('xs')]: {\n padding: `0 0 12px`,\n },\n },\n listItemText: {\n [theme.breakpoints.down('xs')]: {\n paddingRight: 0,\n paddingLeft: 0,\n },\n },\n listItemSecondaryAction: {\n [theme.breakpoints.down('xs')]: {\n width: '100%',\n top: 'auto',\n right: 'auto',\n position: 'relative',\n transform: 'unset',\n },\n },\n grid: {\n overflowY: 'auto',\n marginTop: 0,\n },\n}));\n\n/** @public */\nexport const OwnershipCard = (props: {\n variant?: InfoCardVariants;\n entityFilterKind?: string[];\n hideRelationsToggle?: boolean;\n relationsType?: EntityRelationAggregation;\n entityLimit?: number;\n}) => {\n const {\n variant,\n entityFilterKind,\n hideRelationsToggle,\n
|
|
1
|
+
{"version":3,"file":"OwnershipCard.esm.js","sources":["../../../../src/components/Cards/OwnershipCard/OwnershipCard.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InfoCard, InfoCardVariants } from '@backstage/core-components';\nimport { useEntity } from '@backstage/plugin-catalog-react';\nimport List from '@material-ui/core/List';\nimport ListItem from '@material-ui/core/ListItem';\nimport ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';\nimport ListItemText from '@material-ui/core/ListItemText';\nimport Switch from '@material-ui/core/Switch';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { makeStyles } from '@material-ui/core/styles';\nimport React, { useEffect, useState } from 'react';\nimport { ComponentsGrid } from './ComponentsGrid';\nimport { EntityRelationAggregation } from '../types';\n\nconst useStyles = makeStyles(theme => ({\n card: {\n maxHeight: '100%',\n },\n cardContent: {\n display: 'flex',\n flexDirection: 'column',\n overflow: 'hidden',\n },\n list: {\n [theme.breakpoints.down('xs')]: {\n padding: `0 0 12px`,\n },\n },\n listItemText: {\n [theme.breakpoints.down('xs')]: {\n paddingRight: 0,\n paddingLeft: 0,\n },\n },\n listItemSecondaryAction: {\n [theme.breakpoints.down('xs')]: {\n width: '100%',\n top: 'auto',\n right: 'auto',\n position: 'relative',\n transform: 'unset',\n },\n },\n grid: {\n overflowY: 'auto',\n marginTop: 0,\n },\n}));\n\n/** @public */\nexport const OwnershipCard = (props: {\n variant?: InfoCardVariants;\n entityFilterKind?: string[];\n hideRelationsToggle?: boolean;\n /** @deprecated Please use relationAggregation instead */\n relationsType?: EntityRelationAggregation;\n relationAggregation?: EntityRelationAggregation;\n entityLimit?: number;\n}) => {\n const {\n variant,\n entityFilterKind,\n hideRelationsToggle,\n entityLimit = 6,\n } = props;\n const relationAggregation = props.relationAggregation ?? props.relationsType;\n const relationsToggle =\n hideRelationsToggle === undefined ? false : hideRelationsToggle;\n const classes = useStyles();\n const { entity } = useEntity();\n\n const defaultRelationAggregation =\n entity.kind === 'User' ? 'aggregated' : 'direct';\n const [getRelationAggregation, setRelationAggregation] = useState(\n relationAggregation ?? defaultRelationAggregation,\n );\n\n useEffect(() => {\n if (!relationAggregation) {\n setRelationAggregation(defaultRelationAggregation);\n }\n }, [setRelationAggregation, defaultRelationAggregation, relationAggregation]);\n\n return (\n <InfoCard\n title=\"Ownership\"\n variant={variant}\n className={classes.card}\n cardClassName={classes.cardContent}\n >\n {!relationsToggle && (\n <List dense>\n <ListItem className={classes.list}>\n <ListItemText className={classes.listItemText} />\n <ListItemSecondaryAction\n className={classes.listItemSecondaryAction}\n >\n Direct Relations\n <Tooltip\n placement=\"top\"\n arrow\n title={`${\n getRelationAggregation === 'direct' ? 'Direct' : 'Aggregated'\n } Relations`}\n >\n <Switch\n color=\"primary\"\n checked={getRelationAggregation !== 'direct'}\n onChange={() => {\n const updatedRelationAggregation =\n getRelationAggregation === 'direct'\n ? 'aggregated'\n : 'direct';\n setRelationAggregation(updatedRelationAggregation);\n }}\n name=\"pin\"\n inputProps={{ 'aria-label': 'Ownership Type Switch' }}\n />\n </Tooltip>\n Aggregated Relations\n </ListItemSecondaryAction>\n </ListItem>\n </List>\n )}\n <ComponentsGrid\n className={classes.grid}\n entity={entity}\n entityLimit={entityLimit}\n relationAggregation={getRelationAggregation}\n entityFilterKind={entityFilterKind}\n />\n </InfoCard>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AA6BA,MAAM,SAAA,GAAY,WAAW,CAAU,K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AAK,EAAA,IAAA;AAAA,UACL,KAAO,EAAA,CAAA,EACL,sBAA2B,KAAA,QAAA,GAAW,WAAW,YACnD,CAAA,UAAA,CAAA;AAAA,SAAA;AAAA,wBAEA,KAAA,CAAA,aAAA;AAAA,UAAC,MAAA;AAAA,UAAA;AAAA,YACC,KAAM,EAAA,SAAA;AAAA,YACN,SAAS,sBAA2B,KAAA,QAAA;AAAA,YACpC,UAAU,MAAM;AACd,cAAM,MAAA,0BAAA,GACJ,sBAA2B,KAAA,QAAA,GACvB,YACA,GAAA,QAAA,CAAA;AACN,cAAA,sBAAA,CAAuB,0BAA0B,CAAA,CAAA;AAAA,aACnD;AAAA,YACA,IAAK,EAAA,KAAA;AAAA,YACL,UAAA,EAAY,EAAE,YAAA,EAAc,uBAAwB,EAAA;AAAA,WAAA;AAAA,SACtD;AAAA,OACF;AAAA,MAAU,sBAAA;AAAA,KAGd,CACF,CAAA;AAAA,oBAEF,KAAA,CAAA,aAAA;AAAA,MAAC,cAAA;AAAA,MAAA;AAAA,QACC,WAAW,OAAQ,CAAA,IAAA;AAAA,QACnB,MAAA;AAAA,QACA,WAAA;AAAA,QACA,mBAAqB,EAAA,sBAAA;AAAA,QACrB,gBAAA;AAAA,OAAA;AAAA,KACF;AAAA,GACF,CAAA;AAEJ;;;;"}
|
|
@@ -66,9 +66,9 @@ const getChildOwnershipEntityRefs = async (entity, catalogApi, alreadyRetrievedP
|
|
|
66
66
|
}
|
|
67
67
|
return [entityRef];
|
|
68
68
|
};
|
|
69
|
-
const getOwners = async (entity,
|
|
69
|
+
const getOwners = async (entity, relationAggregation, catalogApi) => {
|
|
70
70
|
const isGroup = entity.kind === "Group";
|
|
71
|
-
const isAggregated =
|
|
71
|
+
const isAggregated = relationAggregation === "aggregated";
|
|
72
72
|
const isUserEntity = entity.kind === "User";
|
|
73
73
|
if (isAggregated && isGroup) {
|
|
74
74
|
return getChildOwnershipEntityRefs(entity, catalogApi);
|
|
@@ -93,7 +93,7 @@ const getOwnedEntitiesByOwners = (owners, kinds, catalogApi) => catalogApi.getEn
|
|
|
93
93
|
"relations"
|
|
94
94
|
]
|
|
95
95
|
});
|
|
96
|
-
function useGetEntities(entity,
|
|
96
|
+
function useGetEntities(entity, relationAggregation, entityFilterKind, entityLimit = 6) {
|
|
97
97
|
const catalogApi = useApi(catalogApiRef);
|
|
98
98
|
const kinds = entityFilterKind ?? ["Component", "API", "System"];
|
|
99
99
|
const {
|
|
@@ -101,7 +101,7 @@ function useGetEntities(entity, relations, entityFilterKind, entityLimit = 6) {
|
|
|
101
101
|
error,
|
|
102
102
|
value: componentsWithCounters
|
|
103
103
|
} = useAsync(async () => {
|
|
104
|
-
const owners = await getOwners(entity,
|
|
104
|
+
const owners = await getOwners(entity, relationAggregation, catalogApi);
|
|
105
105
|
const ownedEntitiesList = await getOwnedEntitiesByOwners(
|
|
106
106
|
owners,
|
|
107
107
|
kinds,
|
|
@@ -132,7 +132,7 @@ function useGetEntities(entity, relations, entityFilterKind, entityLimit = 6) {
|
|
|
132
132
|
kind: topOwnedEntity.kind,
|
|
133
133
|
queryParams: getQueryParams(owners, topOwnedEntity)
|
|
134
134
|
}));
|
|
135
|
-
}, [catalogApi, entity,
|
|
135
|
+
}, [catalogApi, entity, relationAggregation]);
|
|
136
136
|
return {
|
|
137
137
|
componentsWithCounters,
|
|
138
138
|
loading,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetEntities.esm.js","sources":["../../../../src/components/Cards/OwnershipCard/useGetEntities.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Entity,\n parseEntityRef,\n RELATION_MEMBER_OF,\n RELATION_PARENT_OF,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport {\n CatalogApi,\n catalogApiRef,\n getEntityRelations,\n humanizeEntityRef,\n} from '@backstage/plugin-catalog-react';\nimport limiterFactory from 'p-limit';\nimport { useApi } from '@backstage/core-plugin-api';\nimport useAsync from 'react-use/esm/useAsync';\nimport qs from 'qs';\nimport { EntityRelationAggregation } from '../types';\nimport { uniq } from 'lodash';\n\nconst limiter = limiterFactory(5);\n\ntype EntityTypeProps = {\n kind: string;\n type?: string;\n count: number;\n};\n\nconst getQueryParams = (\n ownersEntityRef: string[],\n selectedEntity: EntityTypeProps,\n): string => {\n const { kind, type } = selectedEntity;\n const owners = ownersEntityRef.map(owner =>\n humanizeEntityRef(parseEntityRef(owner), { defaultKind: 'group' }),\n );\n const filters = {\n kind: kind.toLocaleLowerCase('en-US'),\n type,\n owners,\n user: 'all',\n };\n return qs.stringify({ filters }, { arrayFormat: 'repeat' });\n};\n\nconst getMemberOfEntityRefs = (owner: Entity): string[] => {\n const parentGroups = getEntityRelations(owner, RELATION_MEMBER_OF, {\n kind: 'Group',\n });\n\n const ownerGroupsNames = parentGroups.map(({ kind, namespace, name }) =>\n stringifyEntityRef({\n kind,\n namespace,\n name,\n }),\n );\n\n return [...ownerGroupsNames, stringifyEntityRef(owner)];\n};\n\nconst isEntity = (entity: Entity | undefined): entity is Entity =>\n entity !== undefined;\n\nconst getChildOwnershipEntityRefs = async (\n entity: Entity,\n catalogApi: CatalogApi,\n alreadyRetrievedParentRefs: string[] = [],\n): Promise<string[]> => {\n const childGroups = getEntityRelations(entity, RELATION_PARENT_OF, {\n kind: 'Group',\n });\n\n const hasChildGroups = childGroups.length > 0;\n\n const entityRef = stringifyEntityRef(entity);\n if (hasChildGroups) {\n const entityRefs = childGroups.map(r => stringifyEntityRef(r));\n const childGroupResponse = await limiter(() =>\n catalogApi.getEntitiesByRefs({\n fields: ['kind', 'metadata.namespace', 'metadata.name', 'relations'],\n entityRefs,\n }),\n );\n const childGroupEntities = childGroupResponse.items.filter(isEntity);\n\n const unknownChildren = childGroupEntities.filter(\n childGroupEntity =>\n !alreadyRetrievedParentRefs.includes(\n stringifyEntityRef(childGroupEntity),\n ),\n );\n const childrenRefs = (\n await Promise.all(\n unknownChildren.map(childGroupEntity =>\n getChildOwnershipEntityRefs(childGroupEntity, catalogApi, [\n ...alreadyRetrievedParentRefs,\n entityRef,\n ]),\n ),\n )\n ).flatMap(aggregated => aggregated);\n\n return uniq([...childrenRefs, entityRef]);\n }\n\n return [entityRef];\n};\n\nconst getOwners = async (\n entity: Entity,\n relations: EntityRelationAggregation,\n catalogApi: CatalogApi,\n): Promise<string[]> => {\n const isGroup = entity.kind === 'Group';\n const isAggregated = relations === 'aggregated';\n const isUserEntity = entity.kind === 'User';\n\n if (isAggregated && isGroup) {\n return getChildOwnershipEntityRefs(entity, catalogApi);\n }\n\n if (isAggregated && isUserEntity) {\n return getMemberOfEntityRefs(entity);\n }\n\n return [stringifyEntityRef(entity)];\n};\n\nconst getOwnedEntitiesByOwners = (\n owners: string[],\n kinds: string[],\n catalogApi: CatalogApi,\n) =>\n catalogApi.getEntities({\n filter: [\n {\n kind: kinds,\n 'relations.ownedBy': owners,\n },\n ],\n fields: [\n 'kind',\n 'metadata.name',\n 'metadata.namespace',\n 'spec.type',\n 'relations',\n ],\n });\n\nexport function useGetEntities(\n entity: Entity,\n relations: EntityRelationAggregation,\n entityFilterKind?: string[],\n entityLimit = 6,\n): {\n componentsWithCounters:\n | {\n counter: number;\n type: string;\n kind: string;\n queryParams: string;\n }[]\n | undefined;\n loading: boolean;\n error?: Error;\n} {\n const catalogApi = useApi(catalogApiRef);\n const kinds = entityFilterKind ?? ['Component', 'API', 'System'];\n\n const {\n loading,\n error,\n value: componentsWithCounters,\n } = useAsync(async () => {\n const owners = await getOwners(entity, relations, catalogApi);\n\n const ownedEntitiesList = await getOwnedEntitiesByOwners(\n owners,\n kinds,\n catalogApi,\n );\n\n const counts = ownedEntitiesList.items.reduce(\n (acc: EntityTypeProps[], ownedEntity) => {\n const match = acc.find(\n x => x.kind === ownedEntity.kind && x.type === ownedEntity.spec?.type,\n );\n if (match) {\n match.count += 1;\n } else {\n acc.push({\n kind: ownedEntity.kind,\n type: ownedEntity.spec?.type?.toString(),\n count: 1,\n });\n }\n return acc;\n },\n [],\n );\n\n // Return top N (entityLimit) entities to be displayed in ownership boxes\n const topN = counts.sort((a, b) => b.count - a.count).slice(0, entityLimit);\n\n return topN.map(topOwnedEntity => ({\n counter: topOwnedEntity.count,\n type: topOwnedEntity.type,\n kind: topOwnedEntity.kind,\n queryParams: getQueryParams(owners, topOwnedEntity),\n })) as Array<{\n counter: number;\n type: string;\n kind: string;\n queryParams: string;\n }>;\n }, [catalogApi, entity, relations]);\n\n return {\n componentsWithCounters,\n loading,\n error,\n };\n}\n"],"names":[],"mappings":";;;;;;;;AAoCA,MAAM,OAAA,GAAU,eAAe,CAAC,CAAA,CAAA;AAQhC,MAAM,cAAA,GAAiB,CACrB,eAAA,EACA,cACW,KAAA;AACX,EAAM,MAAA,EAAE,IAAM,EAAA,IAAA,EAAS,GAAA,cAAA,CAAA;AACvB,EAAA,MAAM,SAAS,eAAgB,CAAA,GAAA;AAAA,IAAI,CAAA,KAAA,KACjC,kBAAkB,cAAe,CAAA,KAAK,GAAG,EAAE,WAAA,EAAa,SAAS,CAAA;AAAA,GACnE,CAAA;AACA,EAAA,MAAM,OAAU,GAAA;AAAA,IACd,IAAA,EAAM,IAAK,CAAA,iBAAA,CAAkB,OAAO,CAAA;AAAA,IACpC,IAAA;AAAA,IACA,MAAA;AAAA,IACA,IAAM,EAAA,KAAA;AAAA,GACR,CAAA;AACA,EAAO,OAAA,EAAA,CAAG,UAAU,EAAE,OAAA,IAAW,EAAE,WAAA,EAAa,UAAU,CAAA,CAAA;AAC5D,CAAA,CAAA;AAEA,MAAM,qBAAA,GAAwB,CAAC,KAA4B,KAAA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A;AAAA,YAClB,IAAM,EAAA,WAAA,CAAY,IAAM,EAAA,IAAA,EAAM,QAAS,EAAA;AAAA,YACvC,KAAO,EAAA,CAAA;AAAA,WACR,CAAA,CAAA;AAAA,SACH;AACA,QAAO,OAAA,GAAA,CAAA;AAAA,OACT;AAAA,MACA,EAAC;AAAA,KACH,CAAA;AAGA,IAAA,MAAM,IAAO,GAAA,MAAA,CAAO,IAAK,CAAA,CAAC,CAAG,EAAA,CAAA,KAAM,CAAE,CAAA,KAAA,GAAQ,CAAE,CAAA,KAAK,CAAE,CAAA,KAAA,CAAM,GAAG,WAAW,CAAA,CAAA;AAE1E,IAAO,OAAA,IAAA,CAAK,IAAI,CAAmB,cAAA,MAAA;AAAA,MACjC,SAAS,cAAe,CAAA,KAAA;AAAA,MACxB,MAAM,cAAe,CAAA,IAAA;AAAA,MACrB,MAAM,cAAe,CAAA,IAAA;AAAA,MACrB,WAAA,EAAa,cAAe,CAAA,MAAA,EAAQ,cAAc,CAAA;AAAA,KAClD,CAAA,CAAA,CAAA;AAAA,GAMD,EAAA,CAAC,UAAY,EAAA,MAAA,EAAQ,SAAS,CAAC,CAAA,CAAA;AAElC,EAAO,OAAA;AAAA,IACL,sBAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,GACF,CAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"useGetEntities.esm.js","sources":["../../../../src/components/Cards/OwnershipCard/useGetEntities.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Entity,\n parseEntityRef,\n RELATION_MEMBER_OF,\n RELATION_PARENT_OF,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport {\n CatalogApi,\n catalogApiRef,\n getEntityRelations,\n humanizeEntityRef,\n} from '@backstage/plugin-catalog-react';\nimport limiterFactory from 'p-limit';\nimport { useApi } from '@backstage/core-plugin-api';\nimport useAsync from 'react-use/esm/useAsync';\nimport qs from 'qs';\nimport { EntityRelationAggregation } from '../types';\nimport { uniq } from 'lodash';\n\nconst limiter = limiterFactory(5);\n\ntype EntityTypeProps = {\n kind: string;\n type?: string;\n count: number;\n};\n\nconst getQueryParams = (\n ownersEntityRef: string[],\n selectedEntity: EntityTypeProps,\n): string => {\n const { kind, type } = selectedEntity;\n const owners = ownersEntityRef.map(owner =>\n humanizeEntityRef(parseEntityRef(owner), { defaultKind: 'group' }),\n );\n const filters = {\n kind: kind.toLocaleLowerCase('en-US'),\n type,\n owners,\n user: 'all',\n };\n return qs.stringify({ filters }, { arrayFormat: 'repeat' });\n};\n\nconst getMemberOfEntityRefs = (owner: Entity): string[] => {\n const parentGroups = getEntityRelations(owner, RELATION_MEMBER_OF, {\n kind: 'Group',\n });\n\n const ownerGroupsNames = parentGroups.map(({ kind, namespace, name }) =>\n stringifyEntityRef({\n kind,\n namespace,\n name,\n }),\n );\n\n return [...ownerGroupsNames, stringifyEntityRef(owner)];\n};\n\nconst isEntity = (entity: Entity | undefined): entity is Entity =>\n entity !== undefined;\n\nconst getChildOwnershipEntityRefs = async (\n entity: Entity,\n catalogApi: CatalogApi,\n alreadyRetrievedParentRefs: string[] = [],\n): Promise<string[]> => {\n const childGroups = getEntityRelations(entity, RELATION_PARENT_OF, {\n kind: 'Group',\n });\n\n const hasChildGroups = childGroups.length > 0;\n\n const entityRef = stringifyEntityRef(entity);\n if (hasChildGroups) {\n const entityRefs = childGroups.map(r => stringifyEntityRef(r));\n const childGroupResponse = await limiter(() =>\n catalogApi.getEntitiesByRefs({\n fields: ['kind', 'metadata.namespace', 'metadata.name', 'relations'],\n entityRefs,\n }),\n );\n const childGroupEntities = childGroupResponse.items.filter(isEntity);\n\n const unknownChildren = childGroupEntities.filter(\n childGroupEntity =>\n !alreadyRetrievedParentRefs.includes(\n stringifyEntityRef(childGroupEntity),\n ),\n );\n const childrenRefs = (\n await Promise.all(\n unknownChildren.map(childGroupEntity =>\n getChildOwnershipEntityRefs(childGroupEntity, catalogApi, [\n ...alreadyRetrievedParentRefs,\n entityRef,\n ]),\n ),\n )\n ).flatMap(aggregated => aggregated);\n\n return uniq([...childrenRefs, entityRef]);\n }\n\n return [entityRef];\n};\n\nconst getOwners = async (\n entity: Entity,\n relationAggregation: EntityRelationAggregation,\n catalogApi: CatalogApi,\n): Promise<string[]> => {\n const isGroup = entity.kind === 'Group';\n const isAggregated = relationAggregation === 'aggregated';\n const isUserEntity = entity.kind === 'User';\n\n if (isAggregated && isGroup) {\n return getChildOwnershipEntityRefs(entity, catalogApi);\n }\n\n if (isAggregated && isUserEntity) {\n return getMemberOfEntityRefs(entity);\n }\n\n return [stringifyEntityRef(entity)];\n};\n\nconst getOwnedEntitiesByOwners = (\n owners: string[],\n kinds: string[],\n catalogApi: CatalogApi,\n) =>\n catalogApi.getEntities({\n filter: [\n {\n kind: kinds,\n 'relations.ownedBy': owners,\n },\n ],\n fields: [\n 'kind',\n 'metadata.name',\n 'metadata.namespace',\n 'spec.type',\n 'relations',\n ],\n });\n\nexport function useGetEntities(\n entity: Entity,\n relationAggregation: EntityRelationAggregation,\n entityFilterKind?: string[],\n entityLimit = 6,\n): {\n componentsWithCounters:\n | {\n counter: number;\n type: string;\n kind: string;\n queryParams: string;\n }[]\n | undefined;\n loading: boolean;\n error?: Error;\n} {\n const catalogApi = useApi(catalogApiRef);\n const kinds = entityFilterKind ?? ['Component', 'API', 'System'];\n\n const {\n loading,\n error,\n value: componentsWithCounters,\n } = useAsync(async () => {\n const owners = await getOwners(entity, relationAggregation, catalogApi);\n\n const ownedEntitiesList = await getOwnedEntitiesByOwners(\n owners,\n kinds,\n catalogApi,\n );\n\n const counts = ownedEntitiesList.items.reduce(\n (acc: EntityTypeProps[], ownedEntity) => {\n const match = acc.find(\n x => x.kind === ownedEntity.kind && x.type === ownedEntity.spec?.type,\n );\n if (match) {\n match.count += 1;\n } else {\n acc.push({\n kind: ownedEntity.kind,\n type: ownedEntity.spec?.type?.toString(),\n count: 1,\n });\n }\n return acc;\n },\n [],\n );\n\n // Return top N (entityLimit) entities to be displayed in ownership boxes\n const topN = counts.sort((a, b) => b.count - a.count).slice(0, entityLimit);\n\n return topN.map(topOwnedEntity => ({\n counter: topOwnedEntity.count,\n type: topOwnedEntity.type,\n kind: topOwnedEntity.kind,\n queryParams: getQueryParams(owners, topOwnedEntity),\n })) as Array<{\n counter: number;\n type: string;\n kind: string;\n queryParams: string;\n }>;\n }, [catalogApi, entity, relationAggregation]);\n\n return {\n componentsWithCounters,\n loading,\n error,\n };\n}\n"],"names":[],"mappings":";;;;;;;;AAoCA,MAAM,OAAA,GAAU,eAAe,CAAC,CAAA,CAAA;AAQhC,MAAM,cAAA,GAAiB,CACrB,eAAA,EACA,cACW,KAAA;AACX,EAAM,MAAA,EAAE,IAAM,EAAA,IAAA,EAAS,GAAA,cAAA,CAAA;AACvB,EAAA,MAAM,SAAS,eAAgB,CAAA,GAAA;AAAA,IAAI,CAAA,KAAA,KACjC,kBAAkB,cAAe,CAAA,KAAK,GAAG,EAAE,WAAA,EAAa,SAAS,CAAA;AAAA,GACnE,CAAA;AACA,EAAA,MAAM,OAAU,GAAA;AAAA,IACd,IAAA,EAAM,IAAK,CAAA,iBAAA,CAAkB,OAAO,CAAA;AAAA,IACpC,IAAA;AAAA,IACA,MAAA;AAAA,IACA,IAAM,EAAA,KAAA;AAAA,GACR,CAAA;AACA,EAAO,OAAA,EAAA,CAAG,UAAU,EAAE,OAAA,IAAW,EAAE,WAAA,EAAa,UAAU,CAAA,CAAA;AAC5D,CAAA,CAAA;AAEA,MAAM,qBAAA,GAAwB,CAAC,KAA4B,KAAA;AACzD,EAAM,MAA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YAClB,IAAM,EAAA,WAAA,CAAY,IAAM,EAAA,IAAA,EAAM,QAAS,EAAA;AAAA,YACvC,KAAO,EAAA,CAAA;AAAA,WACR,CAAA,CAAA;AAAA,SACH;AACA,QAAO,OAAA,GAAA,CAAA;AAAA,OACT;AAAA,MACA,EAAC;AAAA,KACH,CAAA;AAGA,IAAA,MAAM,IAAO,GAAA,MAAA,CAAO,IAAK,CAAA,CAAC,CAAG,EAAA,CAAA,KAAM,CAAE,CAAA,KAAA,GAAQ,CAAE,CAAA,KAAK,CAAE,CAAA,KAAA,CAAM,GAAG,WAAW,CAAA,CAAA;AAE1E,IAAO,OAAA,IAAA,CAAK,IAAI,CAAmB,cAAA,MAAA;AAAA,MACjC,SAAS,cAAe,CAAA,KAAA;AAAA,MACxB,MAAM,cAAe,CAAA,IAAA;AAAA,MACrB,MAAM,cAAe,CAAA,IAAA;AAAA,MACrB,WAAA,EAAa,cAAe,CAAA,MAAA,EAAQ,cAAc,CAAA;AAAA,KAClD,CAAA,CAAA,CAAA;AAAA,GAMD,EAAA,CAAC,UAAY,EAAA,MAAA,EAAQ,mBAAmB,CAAC,CAAA,CAAA;AAE5C,EAAO,OAAA;AAAA,IACL,sBAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,GACF,CAAA;AACF;;;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { stringifyEntityRef, DEFAULT_NAMESPACE, RELATION_PARENT_OF } from '@backstage/catalog-model';
|
|
2
2
|
import { getEntityRelations } from '@backstage/plugin-catalog-react';
|
|
3
3
|
|
|
4
|
-
const getMembersFromGroups = async (groups, catalogApi) => {
|
|
4
|
+
const getMembersFromGroups = async (groups, catalogApi, relationship = "memberof") => {
|
|
5
5
|
const membersList = groups.length === 0 ? { items: [] } : await catalogApi.getEntities({
|
|
6
6
|
filter: {
|
|
7
7
|
kind: "User",
|
|
8
|
-
|
|
8
|
+
[`relations.${relationship.toLocaleLowerCase("en-US")}`]: groups.map(
|
|
9
9
|
(group) => stringifyEntityRef({
|
|
10
10
|
kind: "group",
|
|
11
11
|
namespace: group.namespace.toLocaleLowerCase("en-US"),
|
|
@@ -50,9 +50,10 @@ const getDescendantGroupsFromGroup = async (group, catalogApi) => {
|
|
|
50
50
|
}
|
|
51
51
|
return resultantGroupRefs;
|
|
52
52
|
};
|
|
53
|
-
const getAllDesendantMembersForGroupEntity = async (groupEntity, catalogApi) => getMembersFromGroups(
|
|
53
|
+
const getAllDesendantMembersForGroupEntity = async (groupEntity, catalogApi, relationship = "memberof") => getMembersFromGroups(
|
|
54
54
|
await getDescendantGroupsFromGroup(groupEntity, catalogApi),
|
|
55
|
-
catalogApi
|
|
55
|
+
catalogApi,
|
|
56
|
+
relationship
|
|
56
57
|
);
|
|
57
58
|
const removeDuplicateEntitiesFrom = (entityArray) => {
|
|
58
59
|
const seenEntities = /* @__PURE__ */ new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.esm.js","sources":["../../src/helpers/helpers.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n CompoundEntityRef,\n DEFAULT_NAMESPACE,\n Entity,\n GroupEntity,\n RELATION_PARENT_OF,\n stringifyEntityRef,\n UserEntity,\n} from '@backstage/catalog-model';\nimport {\n CatalogApi,\n getEntityRelations,\n} from '@backstage/plugin-catalog-react';\n\nexport const getMembersFromGroups = async (\n groups: CompoundEntityRef[],\n catalogApi: CatalogApi,\n) => {\n const membersList =\n groups.length === 0\n ? { items: [] }\n : await catalogApi.getEntities({\n filter: {\n kind: 'User',\n
|
|
1
|
+
{"version":3,"file":"helpers.esm.js","sources":["../../src/helpers/helpers.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n CompoundEntityRef,\n DEFAULT_NAMESPACE,\n Entity,\n GroupEntity,\n RELATION_PARENT_OF,\n stringifyEntityRef,\n UserEntity,\n} from '@backstage/catalog-model';\nimport {\n CatalogApi,\n getEntityRelations,\n} from '@backstage/plugin-catalog-react';\n\nexport const getMembersFromGroups = async (\n groups: CompoundEntityRef[],\n catalogApi: CatalogApi,\n relationship = 'memberof',\n) => {\n const membersList =\n groups.length === 0\n ? { items: [] }\n : await catalogApi.getEntities({\n filter: {\n kind: 'User',\n [`relations.${relationship.toLocaleLowerCase('en-US')}`]:\n groups.map(group =>\n stringifyEntityRef({\n kind: 'group',\n namespace: group.namespace.toLocaleLowerCase('en-US'),\n name: group.name.toLocaleLowerCase('en-US'),\n }),\n ),\n },\n });\n\n return membersList.items as UserEntity[];\n};\n\nexport const getDescendantGroupsFromGroup = async (\n group: GroupEntity,\n catalogApi: CatalogApi,\n) => {\n const alreadyQueuedOrExpandedGroupNames = new Map<string, boolean>();\n const groupRef: CompoundEntityRef = {\n kind: group.kind,\n namespace: group.metadata.namespace ?? DEFAULT_NAMESPACE,\n name: group.metadata.name,\n };\n\n const groupQueue = [groupRef];\n const resultantGroupRefs: CompoundEntityRef[] = [];\n\n // Continue expanding groups until there are no more\n while (groupQueue.length > 0) {\n const activeGroupRef = groupQueue.shift() as CompoundEntityRef;\n const activeGroup = await catalogApi.getEntityByRef(activeGroupRef);\n alreadyQueuedOrExpandedGroupNames.set(\n stringifyEntityRef(activeGroupRef),\n true,\n );\n\n const childGroups = getEntityRelations(activeGroup, RELATION_PARENT_OF, {\n kind: 'Group',\n }).filter(\n currentGroup =>\n !alreadyQueuedOrExpandedGroupNames.has(\n stringifyEntityRef(currentGroup),\n ),\n );\n childGroups.forEach(childGroup =>\n alreadyQueuedOrExpandedGroupNames.set(\n stringifyEntityRef(childGroup),\n true,\n ),\n );\n\n groupQueue.push(...childGroups);\n resultantGroupRefs.push(...childGroups);\n }\n\n return resultantGroupRefs;\n};\n\nexport const getAllDesendantMembersForGroupEntity = async (\n groupEntity: GroupEntity,\n catalogApi: CatalogApi,\n relationship = 'memberof',\n) =>\n getMembersFromGroups(\n await getDescendantGroupsFromGroup(groupEntity, catalogApi),\n catalogApi,\n relationship,\n );\n\nexport const removeDuplicateEntitiesFrom = (entityArray: Entity[]) => {\n const seenEntities = new Map<string, boolean>();\n\n return entityArray.filter(entity => {\n const stringifiedEntity = stringifyEntityRef(entity);\n const isDuplicate = seenEntities.has(stringifiedEntity);\n\n seenEntities.set(stringifiedEntity, true);\n return !isDuplicate;\n });\n};\n"],"names":[],"mappings":";;;AA8BO,MAAM,oBAAuB,GAAA,OAClC,MACA,EAAA,UAAA,EACA,eAAe,UACZ,KAAA;AACH,EAAM,MAAA,WAAA,GACJ,MAAO,CAAA,MAAA,KAAW,CACd,GAAA,EAAE,KAAO,EAAA,EAAG,EAAA,GACZ,MAAM,UAAA,CAAW,WAAY,CAAA;AAAA,IAC3B,MAAQ,EAAA;AAAA,MACN,IAAM,EAAA,MAAA;AAAA,MACN,CAAC,aAAa,YAAa,CAAA,iBAAA,CAAkB,OAAO,CAAC,CAAA,CAAE,GACrD,MAAO,CAAA,GAAA;AAAA,QAAI,WACT,kBAAmB,CAAA;AAAA,UACjB,IAAM,EAAA,OAAA;AAAA,UACN,SAAW,EAAA,KAAA,CAAM,SAAU,CAAA,iBAAA,CAAkB,OAAO,CAAA;AAAA,UAC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B,IAAA;AAAA,OACF;AAAA,KACF,CAAA;AAEA,IAAW,UAAA,CAAA,IAAA,CAAK,GAAG,WAAW,CAAA,CAAA;AAC9B,IAAmB,kBAAA,CAAA,IAAA,CAAK,GAAG,WAAW,CAAA,CAAA;AAAA,GACxC;AAEA,EAAO,OAAA,kBAAA,CAAA;AACT,EAAA;AAEO,MAAM,oCAAuC,GAAA,OAClD,WACA,EAAA,UAAA,EACA,eAAe,UAEf,KAAA,oBAAA;AAAA,EACE,MAAM,4BAA6B,CAAA,WAAA,EAAa,UAAU,CAAA;AAAA,EAC1D,UAAA;AAAA,EACA,YAAA;AACF,EAAA;AAEW,MAAA,2BAAA,GAA8B,CAAC,WAA0B,KAAA;AACpE,EAAM,MAAA,YAAA,uBAAmB,GAAqB,EAAA,CAAA;AAE9C,EAAO,OAAA,WAAA,CAAY,OAAO,CAAU,MAAA,KAAA;AAClC,IAAM,MAAA,iBAAA,GAAoB,mBAAmB,MAAM,CAAA,CAAA;AACnD,IAAM,MAAA,WAAA,GAAc,YAAa,CAAA,GAAA,CAAI,iBAAiB,CAAA,CAAA;AAEtD,IAAa,YAAA,CAAA,GAAA,CAAI,mBAAmB,IAAI,CAAA,CAAA;AACxC,IAAA,OAAO,CAAC,WAAA,CAAA;AAAA,GACT,CAAA,CAAA;AACH;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,10 @@ declare const MembersListCard: (props: {
|
|
|
14
14
|
memberDisplayTitle?: string;
|
|
15
15
|
pageSize?: number;
|
|
16
16
|
showAggregateMembersToggle?: boolean;
|
|
17
|
+
relationType?: string;
|
|
18
|
+
/** @deprecated Please use `relationAggregation` instead */
|
|
17
19
|
relationsType?: EntityRelationAggregation;
|
|
20
|
+
relationAggregation?: EntityRelationAggregation;
|
|
18
21
|
}) => React__default.JSX.Element;
|
|
19
22
|
|
|
20
23
|
/** @public */
|
|
@@ -34,7 +37,9 @@ declare const OwnershipCard: (props: {
|
|
|
34
37
|
variant?: InfoCardVariants;
|
|
35
38
|
entityFilterKind?: string[];
|
|
36
39
|
hideRelationsToggle?: boolean;
|
|
40
|
+
/** @deprecated Please use relationAggregation instead */
|
|
37
41
|
relationsType?: EntityRelationAggregation;
|
|
42
|
+
relationAggregation?: EntityRelationAggregation;
|
|
38
43
|
entityLimit?: number;
|
|
39
44
|
}) => React__default.JSX.Element;
|
|
40
45
|
|
|
@@ -64,7 +69,9 @@ declare const EntityMembersListCard: (props: {
|
|
|
64
69
|
memberDisplayTitle?: string | undefined;
|
|
65
70
|
pageSize?: number | undefined;
|
|
66
71
|
showAggregateMembersToggle?: boolean | undefined;
|
|
72
|
+
relationType?: string | undefined;
|
|
67
73
|
relationsType?: EntityRelationAggregation | undefined;
|
|
74
|
+
relationAggregation?: EntityRelationAggregation | undefined;
|
|
68
75
|
}) => React.JSX.Element;
|
|
69
76
|
/** @public */
|
|
70
77
|
declare const EntityOwnershipCard: (props: {
|
|
@@ -72,6 +79,7 @@ declare const EntityOwnershipCard: (props: {
|
|
|
72
79
|
entityFilterKind?: string[] | undefined;
|
|
73
80
|
hideRelationsToggle?: boolean | undefined;
|
|
74
81
|
relationsType?: EntityRelationAggregation | undefined;
|
|
82
|
+
relationAggregation?: EntityRelationAggregation | undefined;
|
|
75
83
|
entityLimit?: number | undefined;
|
|
76
84
|
}) => React.JSX.Element;
|
|
77
85
|
/** @public */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-org",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.27-next.0",
|
|
4
4
|
"description": "A Backstage plugin that helps you create entity pages for your organization",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "frontend-plugin",
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@backstage/catalog-model": "^1.5.0",
|
|
54
|
-
"@backstage/core-compat-api": "^0.2.
|
|
55
|
-
"@backstage/core-components": "^0.14.
|
|
56
|
-
"@backstage/core-plugin-api": "^1.9.3
|
|
57
|
-
"@backstage/frontend-plugin-api": "^0.6.
|
|
58
|
-
"@backstage/plugin-catalog-common": "^1.0.24
|
|
59
|
-
"@backstage/plugin-catalog-react": "^1.12.
|
|
54
|
+
"@backstage/core-compat-api": "^0.2.7-next.0",
|
|
55
|
+
"@backstage/core-components": "^0.14.9-next.0",
|
|
56
|
+
"@backstage/core-plugin-api": "^1.9.3",
|
|
57
|
+
"@backstage/frontend-plugin-api": "^0.6.7-next.0",
|
|
58
|
+
"@backstage/plugin-catalog-common": "^1.0.24",
|
|
59
|
+
"@backstage/plugin-catalog-react": "^1.12.2-next.0",
|
|
60
60
|
"@material-ui/core": "^4.12.2",
|
|
61
61
|
"@material-ui/icons": "^4.9.1",
|
|
62
62
|
"@material-ui/lab": "4.0.0-alpha.61",
|
|
@@ -69,13 +69,13 @@
|
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@backstage/catalog-client": "^1.6.5",
|
|
72
|
-
"@backstage/cli": "^0.26.
|
|
73
|
-
"@backstage/core-app-api": "^1.
|
|
74
|
-
"@backstage/dev-utils": "^1.0.
|
|
75
|
-
"@backstage/plugin-catalog": "^1.21.
|
|
76
|
-
"@backstage/plugin-permission-common": "^0.7.14
|
|
77
|
-
"@backstage/plugin-permission-react": "^0.4.23
|
|
78
|
-
"@backstage/test-utils": "^1.5.
|
|
72
|
+
"@backstage/cli": "^0.26.10-next.0",
|
|
73
|
+
"@backstage/core-app-api": "^1.13.0-next.0",
|
|
74
|
+
"@backstage/dev-utils": "^1.0.34-next.0",
|
|
75
|
+
"@backstage/plugin-catalog": "^1.21.1-next.0",
|
|
76
|
+
"@backstage/plugin-permission-common": "^0.7.14",
|
|
77
|
+
"@backstage/plugin-permission-react": "^0.4.23",
|
|
78
|
+
"@backstage/test-utils": "^1.5.7-next.0",
|
|
79
79
|
"@backstage/types": "^1.1.1",
|
|
80
80
|
"@testing-library/dom": "^10.0.0",
|
|
81
81
|
"@testing-library/jest-dom": "^6.0.0",
|