From 4f8f3df8fd39705919436b8570b9ee8d6b90c3df Mon Sep 17 00:00:00 2001 From: nikolar Date: Wed, 21 Feb 2024 10:50:28 -0800 Subject: [PATCH] remove dialog box changes Signed-off-by: nikolar --- .changeset/perfect-shoes-arrive.md | 16 +----- plugins/entity-feedback/README.md | 18 ------ plugins/entity-feedback/api-report.md | 2 - .../FeedbackResponseDialog.test.tsx | 18 ------ .../FeedbackResponseDialog.tsx | 56 +------------------ .../FeedbackResponseTable.tsx | 10 ++-- 6 files changed, 8 insertions(+), 112 deletions(-) diff --git a/.changeset/perfect-shoes-arrive.md b/.changeset/perfect-shoes-arrive.md index 5ba02e2184..fbd4d0fec1 100644 --- a/.changeset/perfect-shoes-arrive.md +++ b/.changeset/perfect-shoes-arrive.md @@ -5,21 +5,7 @@ -Add in logic to link the feedback comment box to specific feedback responses -const requireComments = ( - -... - - ... - - ); +Remove empty Chip in `FeedbackResponseTable.tsx` when there is no response diff --git a/plugins/entity-feedback/README.md b/plugins/entity-feedback/README.md index b66cf6f567..c405bd4083 100644 --- a/plugins/entity-feedback/README.md +++ b/plugins/entity-feedback/README.md @@ -90,24 +90,6 @@ const overviewContent = ( ); -// Link the feedback comment box to specific feedback responses -const overviewContent = ( - - ... -+ -+ -+ -+ -+ - ... - -); ... // Add to each applicable kind/type of entity as desired diff --git a/plugins/entity-feedback/api-report.md b/plugins/entity-feedback/api-report.md index d5c03685cd..27e56e5282 100644 --- a/plugins/entity-feedback/api-report.md +++ b/plugins/entity-feedback/api-report.md @@ -79,8 +79,6 @@ export interface EntityFeedbackResponse { id: string; // (undocumented) label: string; - // (undocumented) - mustComment?: boolean; } // @public (undocumented) diff --git a/plugins/entity-feedback/src/components/FeedbackResponseDialog/FeedbackResponseDialog.test.tsx b/plugins/entity-feedback/src/components/FeedbackResponseDialog/FeedbackResponseDialog.test.tsx index 620548d1e1..631738d6f9 100644 --- a/plugins/entity-feedback/src/components/FeedbackResponseDialog/FeedbackResponseDialog.test.tsx +++ b/plugins/entity-feedback/src/components/FeedbackResponseDialog/FeedbackResponseDialog.test.tsx @@ -115,22 +115,4 @@ describe('FeedbackResponseDialog', () => { ); }); }); - - it('will not submit "other" without comments', async () => { - const rendered = await render(); - - await userEvent.click( - rendered.getByRole('checkbox', { name: 'Incorrect info' }), - ); - await userEvent.click( - rendered.getByRole('checkbox', { name: 'Other (please specify below)' }), - ); - await userEvent.click( - rendered.getByTestId('feedback-response-dialog-submit-button'), - ); - - await waitFor(() => { - expect(feedbackApi.recordResponse).toHaveBeenCalledTimes(0); - }); - }); }); diff --git a/plugins/entity-feedback/src/components/FeedbackResponseDialog/FeedbackResponseDialog.tsx b/plugins/entity-feedback/src/components/FeedbackResponseDialog/FeedbackResponseDialog.tsx index 1acf58003a..6bd4510d3e 100644 --- a/plugins/entity-feedback/src/components/FeedbackResponseDialog/FeedbackResponseDialog.tsx +++ b/plugins/entity-feedback/src/components/FeedbackResponseDialog/FeedbackResponseDialog.tsx @@ -16,12 +16,7 @@ import { Entity, stringifyEntityRef } from '@backstage/catalog-model'; import { Progress } from '@backstage/core-components'; -import { - ErrorApiError, - errorApiRef, - useApi, - alertApiRef, -} from '@backstage/core-plugin-api'; +import { ErrorApiError, errorApiRef, useApi } from '@backstage/core-plugin-api'; import { Button, Checkbox, @@ -50,13 +45,12 @@ import { entityFeedbackApiRef } from '../../api'; export interface EntityFeedbackResponse { id: string; label: string; - mustComment?: boolean; } const defaultFeedbackResponses: EntityFeedbackResponse[] = [ { id: 'incorrect', label: 'Incorrect info' }, { id: 'missing', label: 'Missing info' }, - { id: 'other', label: 'Other (please specify below)', mustComment: true }, + { id: 'other', label: 'Other (please specify below)' }, ]; /** @@ -87,41 +81,13 @@ export const FeedbackResponseDialog = (props: FeedbackResponseDialogProps) => { const classes = useStyles(); const errorApi = useApi(errorApiRef); const feedbackApi = useApi(entityFeedbackApiRef); - const alertApi = useApi(alertApiRef); const [responseSelections, setResponseSelections] = useState( Object.fromEntries(feedbackDialogResponses.map(r => [r.id, false])), ); const [comments, setComments] = useState(''); const [consent, setConsent] = useState(true); - const requireComments = feedbackDialogResponses - .filter(r => r.mustComment) - .map(r => r.id); - - const isLinkedBoxChecked = () => { - const checkedBoxes = Object.keys(responseSelections).filter( - id => responseSelections[id], - ); - return checkedBoxes.some(id => requireComments.includes(id)); - }; const [{ loading: saving }, saveResponse] = useAsyncFn(async () => { - if (requireComments.length > 0) { - if (comments.length === 0 && isLinkedBoxChecked()) { - alertApi.post({ - message: - 'The selected option(s) require a comment. Please provide a comment.', - severity: 'info', - }); - return; - } - if (comments.length > 0 && !isLinkedBoxChecked()) { - alertApi.post({ - message: 'Please select the option(s) that require a comment.', - severity: 'info', - }); - return; - } - } try { await feedbackApi.recordResponse(stringifyEntityRef(entity), { comments, @@ -136,22 +102,6 @@ export const FeedbackResponseDialog = (props: FeedbackResponseDialogProps) => { } }, [comments, consent, entity, feedbackApi, onClose, responseSelections]); - const selectLinkedBox = (res: boolean) => { - const newResponseSelections = { ...responseSelections }; - requireComments.forEach(id => newResponseSelections[id] === res); - setResponseSelections(newResponseSelections); - }; - - const verifyComments = (e: any) => { - setComments(e.target.value); - if (requireComments.length > 0) { - selectLinkedBox(true); - if (e.target.value.length === 0) { - selectLinkedBox(false); - } - } - }; - return ( !saving && onClose()}> {saving && } @@ -188,7 +138,7 @@ export const FeedbackResponseDialog = (props: FeedbackResponseDialogProps) => { label="Additional comments" multiline minRows={2} - onChange={e => verifyComments(e)} + onChange={e => setComments(e.target.value)} variant="outlined" value={comments} /> diff --git a/plugins/entity-feedback/src/components/FeedbackResponseTable/FeedbackResponseTable.tsx b/plugins/entity-feedback/src/components/FeedbackResponseTable/FeedbackResponseTable.tsx index 22155f90ce..0c26d7a2ba 100644 --- a/plugins/entity-feedback/src/components/FeedbackResponseTable/FeedbackResponseTable.tsx +++ b/plugins/entity-feedback/src/components/FeedbackResponseTable/FeedbackResponseTable.tsx @@ -80,12 +80,10 @@ export const FeedbackResponseTable = (props: FeedbackResponseTableProps) => { width: '35%', render: (response: ResponseRow) => ( <> - {response.response?.length !== undefined && - response.response?.length > 0 - ? response.response - ?.split(',') - .map(res => ) - : ''} + {response.response?.length && + response.response + ?.split(',') + .map(res => )} ), },