@backstage/plugin-org-react 0.0.0-nightly-20221105024614

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 ADDED
@@ -0,0 +1,17 @@
1
+ # @backstage/plugin-org-react
2
+
3
+ ## 0.0.0-nightly-20221105024614
4
+
5
+ ### Minor Changes
6
+
7
+ - e96274f1fe: Implemented the org-react plugin, with it's first component being: a `GroupListPicker` component that will give the user the ability to choose a group
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @backstage/plugin-catalog-react@0.0.0-nightly-20221105024614
13
+ - @backstage/core-components@0.0.0-nightly-20221105024614
14
+ - @backstage/core-plugin-api@0.0.0-nightly-20221105024614
15
+ - @backstage/catalog-model@0.0.0-nightly-20221105024614
16
+ - @backstage/catalog-client@0.0.0-nightly-20221105024614
17
+ - @backstage/theme@0.2.16
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # org-react
2
+
3
+ ## features
4
+
5
+ - Group list picker component
6
+
7
+ ### GroupListPicker
8
+
9
+ The `GroupListPicker` component displays a select box which also has autocomplete functionality.
10
+
11
+ To use the `GroupListPicker` component you'll need to import it and add it to your desired place.
12
+
13
+ ```diff
14
+ + import { GroupListPicker } from '@backstage/plugin-org-react';
15
+ + import React, { useState } from 'react';
16
+
17
+ + const [group, setGroup] = useState<GroupEntity | undefined>();
18
+
19
+ <Grid container spacing={3}>
20
+ <Grid item xs={12}>
21
+ + <GroupListPicker groupTypes={['team']} placeholder='Search for a team' onChange={setGroup}/>
22
+ </Grid>
23
+ </Grid>
24
+ ```
25
+
26
+ The `GroupListPicker` comes with three props:
27
+
28
+ - `groupTypes`: gives the user the option which group types the component should load. If no value is provided all group types will be loaded in;
29
+ - `placeholder`: the placeholder that the select box in the component should display. This might be helpful in informing your users what the functionality of the component is.
30
+ - `onChange`: a prop to help the user to give access to the selected group
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { GroupEntity } from '@backstage/catalog-model';
3
+
4
+ /**
5
+ * Props for {@link GroupListPicker}.
6
+ *
7
+ * @public
8
+ */
9
+ declare type GroupListPickerProps = {
10
+ placeholder?: string;
11
+ groupTypes?: Array<string>;
12
+ onChange: (value: GroupEntity | undefined) => void;
13
+ };
14
+ /** @public */
15
+ declare const GroupListPicker: (props: GroupListPickerProps) => JSX.Element;
16
+
17
+ export { GroupListPicker, GroupListPickerProps };
@@ -0,0 +1,121 @@
1
+ import React, { useCallback } from 'react';
2
+ import { catalogApiRef, humanizeEntityRef } from '@backstage/plugin-catalog-react';
3
+ import TextField from '@material-ui/core/TextField';
4
+ import Autocomplete from '@material-ui/lab/Autocomplete';
5
+ import useAsync from 'react-use/lib/useAsync';
6
+ import Popover from '@material-ui/core/Popover';
7
+ import { useApi } from '@backstage/core-plugin-api';
8
+ import { ResponseErrorPanel } from '@backstage/core-components';
9
+ import { makeStyles, Button, Typography } from '@material-ui/core';
10
+ import KeyboardArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';
11
+ import PeopleIcon from '@material-ui/icons/People';
12
+
13
+ const useStyles = makeStyles((theme) => ({
14
+ btn: {
15
+ margin: 0,
16
+ padding: 10,
17
+ width: "100%",
18
+ cursor: "pointer",
19
+ justifyContent: "space-between"
20
+ },
21
+ title: {
22
+ fontSize: "1.5rem",
23
+ fontStyle: "normal",
24
+ fontWeight: theme.typography.fontWeightBold,
25
+ letterSpacing: "-0.25px",
26
+ lineHeight: "32px",
27
+ marginBottom: 0,
28
+ textTransform: "none"
29
+ },
30
+ icon: {
31
+ transform: "scale(1.5)"
32
+ }
33
+ }));
34
+ const GroupListPickerButton = (props) => {
35
+ const { handleClick, group } = props;
36
+ const classes = useStyles();
37
+ return /* @__PURE__ */ React.createElement(Button, {
38
+ onClick: handleClick,
39
+ "data-testid": "group-list-picker-button",
40
+ "aria-describedby": "group-list-popover",
41
+ startIcon: /* @__PURE__ */ React.createElement(PeopleIcon, {
42
+ className: classes.icon
43
+ }),
44
+ className: classes.btn,
45
+ size: "large",
46
+ endIcon: /* @__PURE__ */ React.createElement(KeyboardArrowDownIcon, {
47
+ className: classes.icon
48
+ })
49
+ }, /* @__PURE__ */ React.createElement(Typography, {
50
+ className: classes.title
51
+ }, group));
52
+ };
53
+
54
+ const GroupListPicker = (props) => {
55
+ const catalogApi = useApi(catalogApiRef);
56
+ const { onChange, groupTypes, placeholder = "" } = props;
57
+ const [anchorEl, setAnchorEl] = React.useState(null);
58
+ const [inputValue, setInputValue] = React.useState("");
59
+ const handleClick = (event) => {
60
+ setAnchorEl(event.currentTarget);
61
+ };
62
+ const handleClose = () => {
63
+ setAnchorEl(null);
64
+ };
65
+ const open = Boolean(anchorEl);
66
+ const {
67
+ loading,
68
+ error,
69
+ value: groups
70
+ } = useAsync(async () => {
71
+ const groupsList = await catalogApi.getEntities({
72
+ filter: {
73
+ kind: "Group",
74
+ "spec.type": groupTypes || []
75
+ }
76
+ });
77
+ return groupsList.items;
78
+ }, [catalogApi, groupTypes]);
79
+ const handleChange = useCallback(
80
+ (_, v) => {
81
+ onChange(v != null ? v : void 0);
82
+ },
83
+ [onChange]
84
+ );
85
+ if (error) {
86
+ return /* @__PURE__ */ React.createElement(ResponseErrorPanel, {
87
+ error
88
+ });
89
+ }
90
+ const getHumanEntityRef = (entity) => humanizeEntityRef(entity);
91
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Popover, {
92
+ anchorEl,
93
+ open,
94
+ onClose: handleClose,
95
+ anchorOrigin: { horizontal: "left", vertical: "bottom" }
96
+ }, /* @__PURE__ */ React.createElement(Autocomplete, {
97
+ "data-testid": "group-list-picker-input",
98
+ loading,
99
+ options: groups != null ? groups : [],
100
+ groupBy: (option) => option.spec.type,
101
+ getOptionLabel: (option) => {
102
+ var _a, _b;
103
+ return (_b = (_a = option.spec.profile) == null ? void 0 : _a.displayName) != null ? _b : getHumanEntityRef(option);
104
+ },
105
+ inputValue,
106
+ onInputChange: (_, value) => setInputValue(value),
107
+ onChange: handleChange,
108
+ style: { width: "300px" },
109
+ renderInput: (params) => /* @__PURE__ */ React.createElement(TextField, {
110
+ ...params,
111
+ placeholder,
112
+ variant: "outlined"
113
+ })
114
+ })), /* @__PURE__ */ React.createElement(GroupListPickerButton, {
115
+ handleClick,
116
+ group: inputValue
117
+ }));
118
+ };
119
+
120
+ export { GroupListPicker };
121
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/components/GroupListPicker/GroupListPickerButton.tsx","../src/components/GroupListPicker/GroupListPicker.tsx"],"sourcesContent":["/*\n * Copyright 2022 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 React from 'react';\nimport { BackstageTheme } from '@backstage/theme';\nimport { makeStyles, Typography, Button } from '@material-ui/core';\nimport KeyboardArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';\nimport PeopleIcon from '@material-ui/icons/People';\n\nconst useStyles = makeStyles((theme: BackstageTheme) => ({\n btn: {\n margin: 0,\n padding: 10,\n width: '100%',\n cursor: 'pointer',\n justifyContent: 'space-between',\n },\n title: {\n fontSize: '1.5rem',\n fontStyle: 'normal',\n fontWeight: theme.typography.fontWeightBold,\n letterSpacing: '-0.25px',\n lineHeight: '32px',\n marginBottom: 0,\n textTransform: 'none',\n },\n icon: {\n transform: 'scale(1.5)',\n },\n}));\n\ntype GroupListPickerButtonProps = {\n handleClick: (event: React.MouseEvent<HTMLElement>) => void;\n group: string | undefined;\n};\n\n/** @public */\nexport const GroupListPickerButton = (props: GroupListPickerButtonProps) => {\n const { handleClick, group } = props;\n const classes = useStyles();\n\n return (\n <Button\n onClick={handleClick}\n data-testid=\"group-list-picker-button\"\n aria-describedby=\"group-list-popover\"\n startIcon={<PeopleIcon className={classes.icon} />}\n className={classes.btn}\n size=\"large\"\n endIcon={<KeyboardArrowDownIcon className={classes.icon} />}\n >\n <Typography className={classes.title}>{group}</Typography>\n </Button>\n );\n};\n","/*\n * Copyright 2022 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 React, { useCallback } from 'react';\nimport {\n catalogApiRef,\n humanizeEntityRef,\n} from '@backstage/plugin-catalog-react';\nimport TextField from '@material-ui/core/TextField';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\nimport useAsync from 'react-use/lib/useAsync';\nimport Popover from '@material-ui/core/Popover';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { ResponseErrorPanel } from '@backstage/core-components';\nimport { Entity, GroupEntity } from '@backstage/catalog-model';\nimport { GroupListPickerButton } from './GroupListPickerButton';\n\n/**\n * Props for {@link GroupListPicker}.\n *\n * @public\n */\nexport type GroupListPickerProps = {\n placeholder?: string;\n groupTypes?: Array<string>;\n onChange: (value: GroupEntity | undefined) => void;\n};\n\n/** @public */\nexport const GroupListPicker = (props: GroupListPickerProps) => {\n const catalogApi = useApi(catalogApiRef);\n\n const { onChange, groupTypes, placeholder = '' } = props;\n const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null);\n const [inputValue, setInputValue] = React.useState('');\n\n const handleClick = (event: React.MouseEvent<HTMLElement>) => {\n setAnchorEl(event.currentTarget);\n };\n\n const handleClose = () => {\n setAnchorEl(null);\n };\n\n const open = Boolean(anchorEl);\n\n const {\n loading,\n error,\n value: groups,\n } = useAsync(async () => {\n const groupsList = await catalogApi.getEntities({\n filter: {\n kind: 'Group',\n 'spec.type': groupTypes || [],\n },\n });\n\n return groupsList.items as GroupEntity[];\n }, [catalogApi, groupTypes]);\n\n const handleChange = useCallback(\n (_, v: GroupEntity | null) => {\n onChange(v ?? undefined);\n },\n [onChange],\n );\n\n if (error) {\n return <ResponseErrorPanel error={error} />;\n }\n\n const getHumanEntityRef = (entity: Entity) => humanizeEntityRef(entity);\n\n return (\n <>\n <Popover\n anchorEl={anchorEl}\n open={open}\n onClose={handleClose}\n anchorOrigin={{ horizontal: 'left', vertical: 'bottom' }}\n >\n <Autocomplete\n data-testid=\"group-list-picker-input\"\n loading={loading}\n options={groups ?? []}\n groupBy={option => option.spec.type}\n getOptionLabel={option =>\n option.spec.profile?.displayName ?? getHumanEntityRef(option)\n }\n inputValue={inputValue}\n onInputChange={(_, value) => setInputValue(value)}\n onChange={handleChange}\n style={{ width: '300px' }}\n renderInput={params => (\n <TextField\n {...params}\n placeholder={placeholder}\n variant=\"outlined\"\n />\n )}\n />\n </Popover>\n <GroupListPickerButton handleClick={handleClick} group={inputValue} />\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAsBA,MAAM,SAAA,GAAY,UAAW,CAAA,CAAC,KAA2B,MAAA;AAAA,EACvD,GAAK,EAAA;AAAA,IACH,MAAQ,EAAA,CAAA;AAAA,IACR,OAAS,EAAA,EAAA;AAAA,IACT,KAAO,EAAA,MAAA;AAAA,IACP,MAAQ,EAAA,SAAA;AAAA,IACR,cAAgB,EAAA,eAAA;AAAA,GAClB;AAAA,EACA,KAAO,EAAA;AAAA,IACL,QAAU,EAAA,QAAA;AAAA,IACV,SAAW,EAAA,QAAA;AAAA,IACX,UAAA,EAAY,MAAM,UAAW,CAAA,cAAA;AAAA,IAC7B,aAAe,EAAA,SAAA;AAAA,IACf,UAAY,EAAA,MAAA;AAAA,IACZ,YAAc,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,IACT,YAAc,EAAA,EAAE,UAAY,EAAA,MAAA,EAAQ,UAAU,QAAS,EAAA;AAAA,GAAA,kBAEtD,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA;AAAA,IACC,aAAY,EAAA,yBAAA;AAAA,IACZ,OAAA;AAAA,IACA,OAAA,EAAS,0BAAU,EAAC;AAAA,IACpB,OAAA,EAAS,CAAU,MAAA,KAAA,MAAA,CAAO,IAAK,CAAA,IAAA;AAAA,IAC/B,gBAAgB,CAAO,MAAA,KAAA;AApGjC,MAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAqGY,MAAA,OAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,KAAK,OAAZ,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAqB,WAArB,KAAA,IAAA,GAAA,EAAA,GAAoC,kBAAkB,MAAM,CAAA,CAAA;AAAA,KAAA;AAAA,IAE9D,UAAA;AAAA,IACA,aAAe,EAAA,CAAC,CAAG,EAAA,KAAA,KAAU,cAAc,KAAK,CAAA;AAAA,IAChD,QAAU,EAAA,YAAA;AAAA,IACV,KAAA,EAAO,EAAE,KAAA,EAAO,OAAQ,EAAA;AAAA,IACxB,WAAA,EAAa,4BACV,KAAA,CAAA,aAAA,CAAA,SAAA,EAAA;AAAA,MACE,GAAG,MAAA;AAAA,MACJ,WAAA;AAAA,MACA,OAAQ,EAAA,UAAA;AAAA,KACV,CAAA;AAAA,GAEJ,CACF,mBACC,KAAA,CAAA,aAAA,CAAA,qBAAA,EAAA;AAAA,IAAsB,WAAA;AAAA,IAA0B,KAAO,EAAA,UAAA;AAAA,GAAY,CACtE,CAAA,CAAA;AAEJ;;;;"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@backstage/plugin-org-react",
3
+ "version": "0.0.0-nightly-20221105024614",
4
+ "main": "dist/index.esm.js",
5
+ "types": "dist/index.d.ts",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "main": "dist/index.esm.js",
10
+ "types": "dist/index.d.ts"
11
+ },
12
+ "backstage": {
13
+ "role": "web-library"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/backstage/backstage",
18
+ "directory": "plugins/org-react"
19
+ },
20
+ "keywords": [
21
+ "backstage"
22
+ ],
23
+ "scripts": {
24
+ "start": "backstage-cli package start",
25
+ "build": "backstage-cli package build",
26
+ "lint": "backstage-cli package lint",
27
+ "test": "backstage-cli package test",
28
+ "clean": "backstage-cli package clean",
29
+ "prepack": "backstage-cli package prepack",
30
+ "postpack": "backstage-cli package postpack"
31
+ },
32
+ "dependencies": {
33
+ "@backstage/catalog-client": "^0.0.0-nightly-20221105024614",
34
+ "@backstage/catalog-model": "^0.0.0-nightly-20221105024614",
35
+ "@backstage/core-components": "^0.0.0-nightly-20221105024614",
36
+ "@backstage/core-plugin-api": "^0.0.0-nightly-20221105024614",
37
+ "@backstage/plugin-catalog-react": "^0.0.0-nightly-20221105024614",
38
+ "@backstage/theme": "^0.2.16",
39
+ "@material-ui/core": "^4.9.13",
40
+ "@material-ui/icons": "^4.9.1",
41
+ "@material-ui/lab": "^4.0.0-alpha.57",
42
+ "react-use": "^17.2.4"
43
+ },
44
+ "peerDependencies": {
45
+ "react": "^16.13.1 || ^17.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@backstage/cli": "^0.0.0-nightly-20221105024614",
49
+ "@backstage/core-app-api": "^0.0.0-nightly-20221105024614",
50
+ "@backstage/dev-utils": "^0.0.0-nightly-20221105024614",
51
+ "@backstage/test-utils": "^0.0.0-nightly-20221105024614",
52
+ "@testing-library/jest-dom": "^5.10.1",
53
+ "@testing-library/react": "^12.1.3",
54
+ "@testing-library/user-event": "^14.0.0",
55
+ "@types/node": "*",
56
+ "cross-fetch": "^3.1.5",
57
+ "msw": "^0.47.0"
58
+ },
59
+ "files": [
60
+ "dist"
61
+ ]
62
+ }