@backstage-community/plugin-entity-feedback 0.2.19 → 0.3.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 +6 -0
- package/README.md +19 -0
- package/dist/components/FeedbackResponseDialog/FeedbackResponseDialog.esm.js +76 -19
- package/dist/components/FeedbackResponseDialog/FeedbackResponseDialog.esm.js.map +1 -1
- package/dist/components/FeedbackResponseTable/FeedbackResponseTable.esm.js +25 -1
- package/dist/components/FeedbackResponseTable/FeedbackResponseTable.esm.js.map +1 -1
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @backstage-community/plugin-entity-feedback
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f4e4277: Add comment boxes for each checked option in the Feedback Dialog box. Display those option responses as bullet points in the Feedback Response table.
|
|
8
|
+
|
|
3
9
|
## 0.2.19
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -138,3 +138,22 @@ const groupPage = (
|
|
|
138
138
|
```
|
|
139
139
|
|
|
140
140
|
Note: For a full example of this you can look at [this EntityPage](../../packages/app/src/components/catalog/EntityPage.tsx).
|
|
141
|
+
|
|
142
|
+
## Local Development
|
|
143
|
+
|
|
144
|
+
To start the mocked example you need to run the front and backend.
|
|
145
|
+
Start the backend from `workspaces/entity-feedback/plugins/entity-feedback-backend`
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
yarn install
|
|
149
|
+
yarn start
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Then start the frontend example from `workspaces/entity-feedback/plugins/entity-feedback`
|
|
153
|
+
|
|
154
|
+
```sh
|
|
155
|
+
yarn install
|
|
156
|
+
yarn start
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Once that is running you can navigate to `http://localhost:3000/feedback`
|
|
@@ -3,6 +3,7 @@ import { Progress } from '@backstage/core-components';
|
|
|
3
3
|
import { useApi, errorApiRef } from '@backstage/core-plugin-api';
|
|
4
4
|
import Button from '@material-ui/core/Button';
|
|
5
5
|
import Checkbox from '@material-ui/core/Checkbox';
|
|
6
|
+
import Collapse from '@material-ui/core/Collapse';
|
|
6
7
|
import Dialog from '@material-ui/core/Dialog';
|
|
7
8
|
import DialogActions from '@material-ui/core/DialogActions';
|
|
8
9
|
import DialogContent from '@material-ui/core/DialogContent';
|
|
@@ -24,18 +25,36 @@ import { entityFeedbackApiRef } from '../../api/EntityFeedbackApi.esm.js';
|
|
|
24
25
|
const defaultFeedbackResponses = [
|
|
25
26
|
{ id: "incorrect", label: "Incorrect info" },
|
|
26
27
|
{ id: "missing", label: "Missing info" },
|
|
27
|
-
{ id: "other", label: "Other
|
|
28
|
+
{ id: "other", label: "Other" }
|
|
28
29
|
];
|
|
29
|
-
const useStyles = makeStyles(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
30
|
+
const useStyles = makeStyles(
|
|
31
|
+
(theme) => ({
|
|
32
|
+
contactConsent: {
|
|
33
|
+
marginTop: theme.spacing(1.5)
|
|
34
|
+
},
|
|
35
|
+
commentBoxes: {
|
|
36
|
+
marginBottom: theme.spacing(1.5)
|
|
37
|
+
},
|
|
38
|
+
boxContainer: {
|
|
39
|
+
marginBottom: theme.spacing(1.5),
|
|
40
|
+
marginTop: theme.spacing(1.5),
|
|
41
|
+
marginLeft: theme.spacing(1),
|
|
42
|
+
paddingRight: theme.spacing(1)
|
|
43
|
+
},
|
|
44
|
+
formLabel: {
|
|
45
|
+
marginBottom: theme.spacing(1.5)
|
|
46
|
+
},
|
|
47
|
+
dialogActions: {
|
|
48
|
+
justifyContent: "flex-start"
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
{ name: "BackstageEntityFeedbackDialog" }
|
|
52
|
+
);
|
|
34
53
|
const FeedbackResponseDialog = (props) => {
|
|
35
54
|
const {
|
|
36
55
|
entity,
|
|
37
56
|
feedbackDialogResponses = defaultFeedbackResponses,
|
|
38
|
-
feedbackDialogTitle = "
|
|
57
|
+
feedbackDialogTitle = "Tell us what could be better",
|
|
39
58
|
open,
|
|
40
59
|
onClose
|
|
41
60
|
} = props;
|
|
@@ -45,12 +64,27 @@ const FeedbackResponseDialog = (props) => {
|
|
|
45
64
|
const [responseSelections, setResponseSelections] = useState(
|
|
46
65
|
Object.fromEntries(feedbackDialogResponses.map((r) => [r.id, false]))
|
|
47
66
|
);
|
|
48
|
-
const [comments, setComments] = useState(
|
|
67
|
+
const [comments, setComments] = useState({
|
|
68
|
+
responseComments: {},
|
|
69
|
+
additionalComments: ""
|
|
70
|
+
});
|
|
49
71
|
const [consent, setConsent] = useState(true);
|
|
50
72
|
const [{ loading: saving }, saveResponse] = useAsyncFn(async () => {
|
|
73
|
+
const filteredResponseComments = Object.entries(
|
|
74
|
+
comments.responseComments
|
|
75
|
+
).reduce((entry, [key, value]) => {
|
|
76
|
+
if (responseSelections[key]) {
|
|
77
|
+
entry[key] = value;
|
|
78
|
+
}
|
|
79
|
+
return entry;
|
|
80
|
+
}, {});
|
|
81
|
+
const filteredComments = {
|
|
82
|
+
...comments,
|
|
83
|
+
responseComments: filteredResponseComments
|
|
84
|
+
};
|
|
51
85
|
try {
|
|
52
86
|
await feedbackApi.recordResponse(stringifyEntityRef(entity), {
|
|
53
|
-
comments,
|
|
87
|
+
comments: JSON.stringify(filteredComments),
|
|
54
88
|
consent,
|
|
55
89
|
response: Object.keys(responseSelections).filter((id) => responseSelections[id]).join(",")
|
|
56
90
|
});
|
|
@@ -59,10 +93,9 @@ const FeedbackResponseDialog = (props) => {
|
|
|
59
93
|
errorApi.post(e);
|
|
60
94
|
}
|
|
61
95
|
}, [comments, consent, entity, feedbackApi, onClose, responseSelections]);
|
|
62
|
-
return /* @__PURE__ */ React.createElement(Dialog, { open, onClose: () => !saving && onClose() }, saving && /* @__PURE__ */ React.createElement(Progress, null), /* @__PURE__ */ React.createElement(DialogTitle, null, feedbackDialogTitle), /* @__PURE__ */ React.createElement(DialogContent, null, /* @__PURE__ */ React.createElement(FormControl, { component: "fieldset" }, /* @__PURE__ */ React.createElement(FormLabel, { component: "legend" }, "
|
|
96
|
+
return /* @__PURE__ */ React.createElement(Dialog, { open, onClose: () => !saving && onClose() }, saving && /* @__PURE__ */ React.createElement(Progress, null), /* @__PURE__ */ React.createElement(DialogTitle, null, feedbackDialogTitle), /* @__PURE__ */ React.createElement(DialogContent, null, /* @__PURE__ */ React.createElement(FormControl, { component: "fieldset", fullWidth: true }, /* @__PURE__ */ React.createElement(FormLabel, { component: "legend" }, "Select all that apply"), /* @__PURE__ */ React.createElement(FormGroup, { className: classes.boxContainer }, feedbackDialogResponses.map((response) => /* @__PURE__ */ React.createElement(Grid, { container: true, key: response.id, direction: "column", spacing: 1 }, /* @__PURE__ */ React.createElement(
|
|
63
97
|
FormControlLabel,
|
|
64
98
|
{
|
|
65
|
-
key: response.id,
|
|
66
99
|
control: /* @__PURE__ */ React.createElement(
|
|
67
100
|
Checkbox,
|
|
68
101
|
{
|
|
@@ -72,31 +105,55 @@ const FeedbackResponseDialog = (props) => {
|
|
|
72
105
|
onChange: (e) => setResponseSelections({
|
|
73
106
|
...responseSelections,
|
|
74
107
|
[e.target.name]: e.target.checked
|
|
75
|
-
})
|
|
108
|
+
}),
|
|
109
|
+
color: "primary"
|
|
76
110
|
}
|
|
77
111
|
),
|
|
78
112
|
label: response.label
|
|
79
113
|
}
|
|
80
|
-
)
|
|
114
|
+
), /* @__PURE__ */ React.createElement(Collapse, { in: responseSelections[response.id] }, /* @__PURE__ */ React.createElement(
|
|
115
|
+
TextField,
|
|
116
|
+
{
|
|
117
|
+
"data-testid": `feedback-response-dialog-collapse-comments-input-${responseSelections[response.id]}`,
|
|
118
|
+
disabled: saving,
|
|
119
|
+
className: classes.commentBoxes,
|
|
120
|
+
multiline: true,
|
|
121
|
+
minRows: 2,
|
|
122
|
+
fullWidth: true,
|
|
123
|
+
variant: "outlined",
|
|
124
|
+
value: comments.responseComments[response.id] || "",
|
|
125
|
+
onChange: (e) => setComments((prevComments) => ({
|
|
126
|
+
responseComments: {
|
|
127
|
+
...prevComments.responseComments,
|
|
128
|
+
[response.id]: e.target.value
|
|
129
|
+
},
|
|
130
|
+
additionalComments: prevComments.additionalComments
|
|
131
|
+
}))
|
|
132
|
+
}
|
|
133
|
+
)))))), /* @__PURE__ */ React.createElement(FormControl, { fullWidth: true }, /* @__PURE__ */ React.createElement(FormLabel, { component: "legend", className: classes.formLabel }, "Additional comments"), /* @__PURE__ */ React.createElement(
|
|
81
134
|
TextField,
|
|
82
135
|
{
|
|
83
136
|
"data-testid": "feedback-response-dialog-comments-input",
|
|
84
137
|
disabled: saving,
|
|
85
|
-
label: "Additional comments",
|
|
86
138
|
multiline: true,
|
|
87
139
|
minRows: 2,
|
|
88
|
-
onChange: (e) => setComments(
|
|
140
|
+
onChange: (e) => setComments((prevComments) => ({
|
|
141
|
+
responseComments: {
|
|
142
|
+
...prevComments.responseComments
|
|
143
|
+
},
|
|
144
|
+
additionalComments: e.target.value
|
|
145
|
+
})),
|
|
89
146
|
variant: "outlined",
|
|
90
|
-
value: comments
|
|
147
|
+
value: comments.additionalComments || ""
|
|
91
148
|
}
|
|
92
|
-
)), /* @__PURE__ */ React.createElement(Typography, { className: classes.contactConsent }, "
|
|
149
|
+
)), /* @__PURE__ */ React.createElement(Typography, { className: classes.contactConsent }, "May we contact you about your feedback?", /* @__PURE__ */ React.createElement(Grid, { component: "label", container: true, alignItems: "center", spacing: 1 }, /* @__PURE__ */ React.createElement(Grid, { item: true }, "No"), /* @__PURE__ */ React.createElement(Grid, { item: true }, /* @__PURE__ */ React.createElement(
|
|
93
150
|
Switch,
|
|
94
151
|
{
|
|
95
152
|
checked: consent,
|
|
96
153
|
disabled: saving,
|
|
97
154
|
onChange: (e) => setConsent(e.target.checked)
|
|
98
155
|
}
|
|
99
|
-
)), /* @__PURE__ */ React.createElement(Grid, { item: true }, "Yes")))), /* @__PURE__ */ React.createElement(DialogActions,
|
|
156
|
+
)), /* @__PURE__ */ React.createElement(Grid, { item: true }, "Yes")))), /* @__PURE__ */ React.createElement(DialogActions, { className: classes.dialogActions }, /* @__PURE__ */ React.createElement(
|
|
100
157
|
Button,
|
|
101
158
|
{
|
|
102
159
|
color: "primary",
|
|
@@ -105,7 +162,7 @@ const FeedbackResponseDialog = (props) => {
|
|
|
105
162
|
onClick: saveResponse
|
|
106
163
|
},
|
|
107
164
|
"Submit"
|
|
108
|
-
)));
|
|
165
|
+
), /* @__PURE__ */ React.createElement(Button, { color: "primary", disabled: saving, onClick: onClose }, "Close")));
|
|
109
166
|
};
|
|
110
167
|
|
|
111
168
|
export { FeedbackResponseDialog };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedbackResponseDialog.esm.js","sources":["../../../src/components/FeedbackResponseDialog/FeedbackResponseDialog.tsx"],"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 { Entity, stringifyEntityRef } from '@backstage/catalog-model';\nimport { Progress } from '@backstage/core-components';\nimport { ErrorApiError, errorApiRef, useApi } from '@backstage/core-plugin-api';\nimport Button from '@material-ui/core/Button';\nimport Checkbox from '@material-ui/core/Checkbox';\nimport Dialog from '@material-ui/core/Dialog';\nimport DialogActions from '@material-ui/core/DialogActions';\nimport DialogContent from '@material-ui/core/DialogContent';\nimport DialogTitle from '@material-ui/core/DialogTitle';\nimport FormControl from '@material-ui/core/FormControl';\nimport FormControlLabel from '@material-ui/core/FormControlLabel';\nimport FormGroup from '@material-ui/core/FormGroup';\nimport FormLabel from '@material-ui/core/FormLabel';\nimport Grid from '@material-ui/core/Grid';\nimport Switch from '@material-ui/core/Switch';\nimport TextField from '@material-ui/core/TextField';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles } from '@material-ui/core/styles';\nimport React, { ReactNode, useState } from 'react';\nimport useAsyncFn from 'react-use/esm/useAsyncFn';\n\nimport { entityFeedbackApiRef } from '../../api';\n\n/**\n * @public\n */\nexport interface EntityFeedbackResponse {\n id: string;\n label: string;\n}\n\nconst defaultFeedbackResponses: EntityFeedbackResponse[] = [\n { id: 'incorrect', label: 'Incorrect info' },\n { id: 'missing', label: 'Missing info' },\n { id: 'other', label: 'Other (please specify below)' },\n];\n\n/**\n * @public\n */\nexport interface FeedbackResponseDialogProps {\n entity: Entity;\n feedbackDialogResponses?: EntityFeedbackResponse[];\n feedbackDialogTitle?: ReactNode;\n open: boolean;\n onClose: () => void;\n}\n\nconst useStyles = makeStyles({\n contactConsent: {\n marginTop: '5px',\n },\n});\n\nexport const FeedbackResponseDialog = (props: FeedbackResponseDialogProps) => {\n const {\n entity,\n feedbackDialogResponses = defaultFeedbackResponses,\n feedbackDialogTitle = 'Please provide feedback on what can be improved',\n open,\n onClose,\n } = props;\n const classes = useStyles();\n const errorApi = useApi(errorApiRef);\n const feedbackApi = useApi(entityFeedbackApiRef);\n const [responseSelections, setResponseSelections] = useState(\n Object.fromEntries(feedbackDialogResponses.map(r => [r.id, false])),\n );\n const [comments, setComments] = useState('');\n const [consent, setConsent] = useState(true);\n\n const [{ loading: saving }, saveResponse] = useAsyncFn(async () => {\n try {\n await feedbackApi.recordResponse(stringifyEntityRef(entity), {\n comments,\n consent,\n response: Object.keys(responseSelections)\n .filter(id => responseSelections[id])\n .join(','),\n });\n onClose();\n } catch (e) {\n errorApi.post(e as ErrorApiError);\n }\n }, [comments, consent, entity, feedbackApi, onClose, responseSelections]);\n\n return (\n <Dialog open={open} onClose={() => !saving && onClose()}>\n {saving && <Progress />}\n <DialogTitle>{feedbackDialogTitle}</DialogTitle>\n <DialogContent>\n <FormControl component=\"fieldset\">\n <FormLabel component=\"legend\">Choose all that apply</FormLabel>\n <FormGroup>\n {feedbackDialogResponses.map(response => (\n <FormControlLabel\n key={response.id}\n control={\n <Checkbox\n checked={responseSelections[response.id]}\n disabled={saving}\n name={response.id}\n onChange={e =>\n setResponseSelections({\n ...responseSelections,\n [e.target.name]: e.target.checked,\n })\n }\n />\n }\n label={response.label}\n />\n ))}\n </FormGroup>\n </FormControl>\n <FormControl fullWidth>\n <TextField\n data-testid=\"feedback-response-dialog-comments-input\"\n disabled={saving}\n label=\"Additional comments\"\n multiline\n minRows={2}\n onChange={e => setComments(e.target.value)}\n variant=\"outlined\"\n value={comments}\n />\n </FormControl>\n <Typography className={classes.contactConsent}>\n Can we reach out to you for more info?\n <Grid component=\"label\" container alignItems=\"center\" spacing={1}>\n <Grid item>No</Grid>\n <Grid item>\n <Switch\n checked={consent}\n disabled={saving}\n onChange={e => setConsent(e.target.checked)}\n />\n </Grid>\n <Grid item>Yes</Grid>\n </Grid>\n </Typography>\n </DialogContent>\n <DialogActions>\n <Button color=\"primary\" disabled={saving} onClick={onClose}>\n Close\n </Button>\n <Button\n color=\"primary\"\n data-testid=\"feedback-response-dialog-submit-button\"\n disabled={saving}\n onClick={saveResponse}\n >\n Submit\n </Button>\n </DialogActions>\n </Dialog>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,wBAAqD,GAAA;AAAA,EACzD,EAAE,EAAA,EAAI,WAAa,EAAA,KAAA,EAAO,gBAAiB,EAAA;AAAA,EAC3C,EAAE,EAAA,EAAI,SAAW,EAAA,KAAA,EAAO,cAAe,EAAA;AAAA,EACvC,EAAE,EAAA,EAAI,OAAS,EAAA,KAAA,EAAO,8BAA+B,EAAA;AACvD,CAAA,CAAA;AAaA,MAAM,YAAY,UAAW,CAAA;AAAA,E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CACC,aACC,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,UAAO,KAAM,EAAA,SAAA,EAAU,UAAU,MAAQ,EAAA,OAAA,EAAS,OAAS,EAAA,EAAA,OAE5D,CACA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACC,KAAM,EAAA,SAAA;AAAA,MACN,aAAY,EAAA,wCAAA;AAAA,MACZ,QAAU,EAAA,MAAA;AAAA,MACV,OAAS,EAAA,YAAA;AAAA,KAAA;AAAA,IACV,QAAA;AAAA,GAGH,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"FeedbackResponseDialog.esm.js","sources":["../../../src/components/FeedbackResponseDialog/FeedbackResponseDialog.tsx"],"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 { Entity, stringifyEntityRef } from '@backstage/catalog-model';\nimport { Progress } from '@backstage/core-components';\nimport { ErrorApiError, errorApiRef, useApi } from '@backstage/core-plugin-api';\nimport Button from '@material-ui/core/Button';\nimport Checkbox from '@material-ui/core/Checkbox';\nimport Collapse from '@material-ui/core/Collapse';\nimport Dialog from '@material-ui/core/Dialog';\nimport DialogActions from '@material-ui/core/DialogActions';\nimport DialogContent from '@material-ui/core/DialogContent';\nimport DialogTitle from '@material-ui/core/DialogTitle';\nimport FormControl from '@material-ui/core/FormControl';\nimport FormControlLabel from '@material-ui/core/FormControlLabel';\nimport FormGroup from '@material-ui/core/FormGroup';\nimport FormLabel from '@material-ui/core/FormLabel';\nimport Grid from '@material-ui/core/Grid';\nimport Switch from '@material-ui/core/Switch';\nimport TextField from '@material-ui/core/TextField';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles, Theme } from '@material-ui/core/styles';\nimport React, { ReactNode, useState } from 'react';\nimport useAsyncFn from 'react-use/esm/useAsyncFn';\n\nimport { entityFeedbackApiRef } from '../../api';\n\n/**\n * @public\n */\nexport interface EntityFeedbackResponse {\n id: string;\n label: string;\n}\nexport interface Comments {\n responseComments: {\n [key: string]: string;\n };\n additionalComments?: string;\n}\n\nconst defaultFeedbackResponses: EntityFeedbackResponse[] = [\n { id: 'incorrect', label: 'Incorrect info' },\n { id: 'missing', label: 'Missing info' },\n { id: 'other', label: 'Other' },\n];\n\n/**\n * @public\n */\nexport interface FeedbackResponseDialogProps {\n entity: Entity;\n feedbackDialogResponses?: EntityFeedbackResponse[];\n feedbackDialogTitle?: ReactNode;\n open: boolean;\n onClose: () => void;\n}\n\nconst useStyles = makeStyles<Theme>(\n theme => ({\n contactConsent: {\n marginTop: theme.spacing(1.5),\n },\n commentBoxes: {\n marginBottom: theme.spacing(1.5),\n },\n boxContainer: {\n marginBottom: theme.spacing(1.5),\n marginTop: theme.spacing(1.5),\n marginLeft: theme.spacing(1),\n paddingRight: theme.spacing(1),\n },\n formLabel: {\n marginBottom: theme.spacing(1.5),\n },\n dialogActions: {\n justifyContent: 'flex-start',\n },\n }),\n { name: 'BackstageEntityFeedbackDialog' },\n);\n\nexport const FeedbackResponseDialog = (props: FeedbackResponseDialogProps) => {\n const {\n entity,\n feedbackDialogResponses = defaultFeedbackResponses,\n feedbackDialogTitle = 'Tell us what could be better',\n open,\n onClose,\n } = props;\n const classes = useStyles();\n const errorApi = useApi(errorApiRef);\n const feedbackApi = useApi(entityFeedbackApiRef);\n const [responseSelections, setResponseSelections] = useState(\n Object.fromEntries(feedbackDialogResponses.map(r => [r.id, false])),\n );\n const [comments, setComments] = useState<Comments>({\n responseComments: {},\n additionalComments: '',\n });\n const [consent, setConsent] = useState(true);\n\n const [{ loading: saving }, saveResponse] = useAsyncFn(async () => {\n // filter out responses that were not selected\n const filteredResponseComments = Object.entries(\n comments.responseComments,\n ).reduce((entry, [key, value]) => {\n if (responseSelections[key]) {\n entry[key] = value;\n }\n return entry;\n }, {} as { [key: string]: string });\n\n const filteredComments = {\n ...comments,\n responseComments: filteredResponseComments,\n };\n try {\n await feedbackApi.recordResponse(stringifyEntityRef(entity), {\n comments: JSON.stringify(filteredComments),\n consent,\n response: Object.keys(responseSelections)\n .filter(id => responseSelections[id])\n .join(','),\n });\n onClose();\n } catch (e) {\n errorApi.post(e as ErrorApiError);\n }\n }, [comments, consent, entity, feedbackApi, onClose, responseSelections]);\n\n return (\n <Dialog open={open} onClose={() => !saving && onClose()}>\n {saving && <Progress />}\n <DialogTitle>{feedbackDialogTitle}</DialogTitle>\n <DialogContent>\n <FormControl component=\"fieldset\" fullWidth>\n <FormLabel component=\"legend\">Select all that apply</FormLabel>\n <FormGroup className={classes.boxContainer}>\n {feedbackDialogResponses.map((response: EntityFeedbackResponse) => (\n <Grid container key={response.id} direction=\"column\" spacing={1}>\n <FormControlLabel\n control={\n <Checkbox\n checked={responseSelections[response.id]}\n disabled={saving}\n name={response.id}\n onChange={e =>\n setResponseSelections({\n ...responseSelections,\n [e.target.name]: e.target.checked,\n })\n }\n color=\"primary\"\n />\n }\n label={response.label}\n />\n <Collapse in={responseSelections[response.id]}>\n <TextField\n data-testid={`feedback-response-dialog-collapse-comments-input-${\n responseSelections[response.id]\n }`}\n disabled={saving}\n className={classes.commentBoxes}\n multiline\n minRows={2}\n fullWidth\n variant=\"outlined\"\n value={comments.responseComments[response.id] || ''}\n onChange={e =>\n setComments(prevComments => ({\n responseComments: {\n ...prevComments.responseComments,\n [response.id]: e.target.value,\n },\n additionalComments: prevComments.additionalComments,\n }))\n }\n />\n </Collapse>\n </Grid>\n ))}\n </FormGroup>\n </FormControl>\n <FormControl fullWidth>\n <FormLabel component=\"legend\" className={classes.formLabel}>\n Additional comments\n </FormLabel>\n <TextField\n data-testid=\"feedback-response-dialog-comments-input\"\n disabled={saving}\n multiline\n minRows={2}\n onChange={e =>\n setComments(prevComments => ({\n responseComments: {\n ...prevComments.responseComments,\n },\n additionalComments: e.target.value,\n }))\n }\n variant=\"outlined\"\n value={comments.additionalComments || ''}\n />\n </FormControl>\n <Typography className={classes.contactConsent}>\n May we contact you about your feedback?\n <Grid component=\"label\" container alignItems=\"center\" spacing={1}>\n <Grid item>No</Grid>\n <Grid item>\n <Switch\n checked={consent}\n disabled={saving}\n onChange={e => setConsent(e.target.checked)}\n />\n </Grid>\n <Grid item>Yes</Grid>\n </Grid>\n </Typography>\n </DialogContent>\n <DialogActions className={classes.dialogActions}>\n <Button\n color=\"primary\"\n data-testid=\"feedback-response-dialog-submit-button\"\n disabled={saving}\n onClick={saveResponse}\n >\n Submit\n </Button>\n <Button color=\"primary\" disabled={saving} onClick={onClose}>\n Close\n </Button>\n </DialogActions>\n </Dialog>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAM,wBAAqD,GAAA;AAAA,EACzD,EAAE,EAAA,EAAI,WAAa,EAAA,KAAA,EAAO,gBAAiB,EAAA;AAAA,EAC3C,EAAE,EAAA,EAAI,SAAW,EAAA,KAAA,EAAO,cAAe,EAAA;AAAA,EACvC,EAAE,EAAA,EAAI,OAAS,EAAA,KAAA,EAAO,OAAQ,EAAA;AAChC,CAAA,CAAA;AAaA,MAAM,SAAY,GAAA,UAAA;AAAA,EAChB,CAAU,KAAA,MAAA;AAAA,IACR,cAAgB,EAAA;AAAA,MACd,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA;AAAA,KAC9B;AAAA,IACA,YAAc,EAAA;AAAA,MACZ,YAAA,EAAc,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA;AAAA,KACjC;AAAA,IACA,YAAc,EAAA;AAAA,MACZ,YAAA,EAAc,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA;AA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SAAA,EAAU,QAAU,EAAA,MAAA,EAAQ,OAAS,EAAA,OAAA,EAAA,EAAS,OAE5D,CACF,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -4,6 +4,7 @@ import { EntityRefLink } from '@backstage/plugin-catalog-react';
|
|
|
4
4
|
import Chip from '@material-ui/core/Chip';
|
|
5
5
|
import { makeStyles } from '@material-ui/core/styles';
|
|
6
6
|
import CheckIcon from '@material-ui/icons/Check';
|
|
7
|
+
import Typography from '@material-ui/core/Typography';
|
|
7
8
|
import React from 'react';
|
|
8
9
|
import useAsync from 'react-use/esm/useAsync';
|
|
9
10
|
import '@backstage/errors';
|
|
@@ -12,6 +13,13 @@ import { entityFeedbackApiRef } from '../../api/EntityFeedbackApi.esm.js';
|
|
|
12
13
|
const useStyles = makeStyles((theme) => ({
|
|
13
14
|
consentCheck: {
|
|
14
15
|
color: theme.palette.status.ok
|
|
16
|
+
},
|
|
17
|
+
listItem: {
|
|
18
|
+
padding: "0",
|
|
19
|
+
marginTop: theme.spacing(1)
|
|
20
|
+
},
|
|
21
|
+
list: {
|
|
22
|
+
paddingLeft: "0"
|
|
15
23
|
}
|
|
16
24
|
}));
|
|
17
25
|
const FeedbackResponseTable = (props) => {
|
|
@@ -47,7 +55,23 @@ const FeedbackResponseTable = (props) => {
|
|
|
47
55
|
width: "35%",
|
|
48
56
|
render: (response) => /* @__PURE__ */ React.createElement(React.Fragment, null, (response.response || "").split(",").map((v) => v.trim()).filter(Boolean).map((res) => /* @__PURE__ */ React.createElement(Chip, { key: res, size: "small", label: res })))
|
|
49
57
|
},
|
|
50
|
-
{
|
|
58
|
+
{
|
|
59
|
+
title: "Comments",
|
|
60
|
+
field: "comments",
|
|
61
|
+
width: "40%",
|
|
62
|
+
render: (response) => {
|
|
63
|
+
var _a;
|
|
64
|
+
let parsedComment;
|
|
65
|
+
try {
|
|
66
|
+
parsedComment = (response == null ? void 0 : response.comments) && JSON.parse(response.comments);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
parsedComment = response.comments;
|
|
69
|
+
}
|
|
70
|
+
return /* @__PURE__ */ React.createElement("div", null, typeof parsedComment === "object" ? /* @__PURE__ */ React.createElement("ul", { className: classes.list }, (_a = Object.entries(parsedComment.responseComments)) == null ? void 0 : _a.map(
|
|
71
|
+
([key, value]) => /* @__PURE__ */ React.createElement("li", { key, className: classes.listItem }, /* @__PURE__ */ React.createElement("strong", null, key, ":"), " ", value)
|
|
72
|
+
), parsedComment.additionalComments && /* @__PURE__ */ React.createElement("li", { className: classes.listItem }, /* @__PURE__ */ React.createElement("strong", null, "additional:"), " ", parsedComment.additionalComments)) : /* @__PURE__ */ React.createElement(Typography, null, parsedComment));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
51
75
|
];
|
|
52
76
|
if (error) {
|
|
53
77
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedbackResponseTable.esm.js","sources":["../../../src/components/FeedbackResponseTable/FeedbackResponseTable.tsx"],"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 { ErrorPanel, Table } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { EntityRefLink } from '@backstage/plugin-catalog-react';\nimport { FeedbackResponse } from '@backstage-community/plugin-entity-feedback-common';\nimport Chip from '@material-ui/core/Chip';\nimport { makeStyles } from '@material-ui/core/styles';\nimport CheckIcon from '@material-ui/icons/Check';\nimport React from 'react';\nimport useAsync from 'react-use/esm/useAsync';\n\nimport { entityFeedbackApiRef } from '../../api';\n\ntype ResponseRow = Omit<FeedbackResponse, 'entityRef'>;\n\nconst useStyles = makeStyles(theme => ({\n consentCheck: {\n color: theme.palette.status.ok,\n },\n}));\n\n/**\n * @public\n */\nexport interface FeedbackResponseTableProps {\n entityRef: string;\n title?: string;\n}\n\nexport const FeedbackResponseTable = (props: FeedbackResponseTableProps) => {\n const { entityRef, title = 'Entity Responses' } = props;\n const classes = useStyles();\n const feedbackApi = useApi(entityFeedbackApiRef);\n\n const {\n error,\n loading,\n value: responses,\n } = useAsync(async () => {\n if (!entityRef) {\n return [];\n }\n\n return feedbackApi.getResponses(entityRef);\n }, [entityRef, feedbackApi]);\n\n const columns = [\n {\n title: 'User',\n field: 'userRef',\n width: '15%',\n render: (response: ResponseRow) => (\n <EntityRefLink entityRef={response.userRef} defaultKind=\"user\" />\n ),\n },\n {\n title: 'OK to contact?',\n field: 'consent',\n width: '10%',\n render: (response: ResponseRow) =>\n response.consent ? <CheckIcon className={classes.consentCheck} /> : '',\n },\n {\n title: 'Responses',\n field: 'response',\n width: '35%',\n render: (response: ResponseRow) => (\n <>\n {(response.response || '')\n .split(',')\n .map(v => v.trim()) // removes whitespace\n .filter(Boolean) // removes accidental empty entries\n .map(res => (\n <Chip key={res} size=\"small\" label={res} />\n ))}\n </>\n ),\n },\n {
|
|
1
|
+
{"version":3,"file":"FeedbackResponseTable.esm.js","sources":["../../../src/components/FeedbackResponseTable/FeedbackResponseTable.tsx"],"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 { ErrorPanel, Table } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { EntityRefLink } from '@backstage/plugin-catalog-react';\nimport { FeedbackResponse } from '@backstage-community/plugin-entity-feedback-common';\nimport Chip from '@material-ui/core/Chip';\nimport { makeStyles } from '@material-ui/core/styles';\nimport CheckIcon from '@material-ui/icons/Check';\nimport Typography from '@material-ui/core/Typography';\nimport React from 'react';\nimport useAsync from 'react-use/esm/useAsync';\n\nimport { entityFeedbackApiRef } from '../../api';\nimport { Comments } from '../FeedbackResponseDialog';\n\ntype ResponseRow = Omit<FeedbackResponse, 'entityRef'>;\n\nconst useStyles = makeStyles(theme => ({\n consentCheck: {\n color: theme.palette.status.ok,\n },\n listItem: {\n padding: '0',\n marginTop: theme.spacing(1),\n },\n list: {\n paddingLeft: '0',\n },\n}));\n\n/**\n * @public\n */\nexport interface FeedbackResponseTableProps {\n entityRef: string;\n title?: string;\n}\n\nexport const FeedbackResponseTable = (props: FeedbackResponseTableProps) => {\n const { entityRef, title = 'Entity Responses' } = props;\n const classes = useStyles();\n const feedbackApi = useApi(entityFeedbackApiRef);\n\n const {\n error,\n loading,\n value: responses,\n } = useAsync(async () => {\n if (!entityRef) {\n return [];\n }\n\n return feedbackApi.getResponses(entityRef);\n }, [entityRef, feedbackApi]);\n\n const columns = [\n {\n title: 'User',\n field: 'userRef',\n width: '15%',\n render: (response: ResponseRow) => (\n <EntityRefLink entityRef={response.userRef} defaultKind=\"user\" />\n ),\n },\n {\n title: 'OK to contact?',\n field: 'consent',\n width: '10%',\n render: (response: ResponseRow) =>\n response.consent ? <CheckIcon className={classes.consentCheck} /> : '',\n },\n {\n title: 'Responses',\n field: 'response',\n width: '35%',\n render: (response: ResponseRow) => (\n <>\n {(response.response || '')\n .split(',')\n .map((v: string) => v.trim()) // removes whitespace\n .filter(Boolean) // removes accidental empty entries\n .map((res: string) => (\n <Chip key={res} size=\"small\" label={res} />\n ))}\n </>\n ),\n },\n {\n title: 'Comments',\n field: 'comments',\n width: '40%',\n render: (response: ResponseRow) => {\n // Check if comment is a stringified object\n let parsedComment;\n try {\n parsedComment =\n response?.comments && (JSON.parse(response.comments) as Comments);\n } catch (e) {\n // If parsing fails, assume it's a regular string\n parsedComment = response.comments;\n }\n return (\n <div>\n {typeof parsedComment === 'object' ? (\n <ul className={classes.list}>\n {Object.entries<string>(parsedComment.responseComments)?.map(\n ([key, value]) => (\n <li key={key} className={classes.listItem}>\n <strong>{key}:</strong> {value}\n </li>\n ),\n )}\n {parsedComment.additionalComments && (\n <li className={classes.listItem}>\n <strong>additional:</strong>{' '}\n {parsedComment.additionalComments}\n </li>\n )}\n </ul>\n ) : (\n <Typography>{parsedComment}</Typography>\n )}\n </div>\n );\n },\n },\n ];\n\n if (error) {\n return (\n <ErrorPanel\n defaultExpanded\n title=\"Failed to load feedback responses\"\n error={error}\n />\n );\n }\n\n return (\n <Table<ResponseRow>\n columns={columns}\n data={(responses ?? []) as ResponseRow[]}\n isLoading={loading}\n options={{\n emptyRowsWhenPaging: false,\n loadingType: 'linear',\n pageSize: 20,\n pageSizeOptions: [20, 50, 100],\n paging: true,\n showEmptyDataSourceMessage: !loading,\n }}\n title={title}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAgCA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,YAAc,EAAA;AAAA,IACZ,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,MAAO,CAAA,EAAA;AAAA,GAC9B;AAAA,EACA,QAAU,EAAA;AAAA,IACR,OAAS,EAAA,GAAA;AAAA,IACT,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,GAC5B;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,WAAa,EAAA,GAAA;AAAA,GACf;AACF,CAAE,CAAA,CAAA,CAAA;AAUW,MAAA,qBAAA,GAAwB,CAAC,KAAsC,KAAA;AAC1E,EAAA,MAAM,EAAE,SAAA,EAAW,KAAQ,GAAA,kBAAA,EAAuB,GAAA,KAAA,CAAA;AAClD,E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AW,EAAA,OAAA,CAAQ,4BACpB,KAAA,CAAA,aAAA,CAAA,QAAA,EAAA,IAAA,EAAO,aAAW,CAAU,EAAA,GAAA,EAC5B,cAAc,kBACjB,CAEJ,oBAEC,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,IAAA,EAAY,aAAc,CAE/B,CAAA,CAAA;AAAA,OAEJ;AAAA,KACF;AAAA,GACF,CAAA;AAEA,EAAA,IAAI,KAAO,EAAA;AACT,IACE,uBAAA,KAAA,CAAA,aAAA;AAAA,MAAC,UAAA;AAAA,MAAA;AAAA,QACC,eAAe,EAAA,IAAA;AAAA,QACf,KAAM,EAAA,mCAAA;AAAA,QACN,KAAA;AAAA,OAAA;AAAA,KACF,CAAA;AAAA,GAEJ;AAEA,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,OAAA;AAAA,MACA,IAAA,EAAO,gCAAa,EAAC;AAAA,MACrB,SAAW,EAAA,OAAA;AAAA,MACX,OAAS,EAAA;AAAA,QACP,mBAAqB,EAAA,KAAA;AAAA,QACrB,WAAa,EAAA,QAAA;AAAA,QACb,QAAU,EAAA,EAAA;AAAA,QACV,eAAiB,EAAA,CAAC,EAAI,EAAA,EAAA,EAAI,GAAG,CAAA;AAAA,QAC7B,MAAQ,EAAA,IAAA;AAAA,QACR,4BAA4B,CAAC,OAAA;AAAA,OAC/B;AAAA,MACA,KAAA;AAAA,KAAA;AAAA,GACF,CAAA;AAEJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage-community/plugin-entity-feedback",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "frontend-plugin"
|
|
6
6
|
},
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@backstage/cli": "^0.26.5",
|
|
48
|
+
"@backstage/dev-utils": "^1.0.32",
|
|
49
|
+
"@backstage/plugin-catalog": "^1.20.0",
|
|
48
50
|
"@backstage/test-utils": "^1.5.5",
|
|
49
51
|
"@testing-library/dom": "^10.0.0",
|
|
50
52
|
"@testing-library/jest-dom": "^6.0.0",
|