-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui-editor): enable component poc and feedback form (#14210)
Co-authored-by: Gørild Døhl <[email protected]>
- Loading branch information
Showing
19 changed files
with
251 additions
and
19 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
frontend/app-development/features/overview/components/News/NewsContent/news.nb.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
frontend/libs/studio-feedback-form/src/FeedbackForm/Question/TextQuestion.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import React, { type ChangeEvent } from 'react'; | ||
import type { QuestionsProps } from '../../types/QuestionsProps'; | ||
import { StudioTextfield } from '@studio/components'; | ||
import { StudioTextarea } from '@studio/components'; | ||
import { useDebounce } from '@studio/hooks'; | ||
|
||
export function TextQuestion({ id, label, value, onChange }: QuestionsProps): React.ReactElement { | ||
const { debounce } = useDebounce({ debounceTimeInMs: 500 }); | ||
const debouncedOnChange = (newValue: string) => debounce(() => onChange(id, newValue)); | ||
return ( | ||
<StudioTextfield | ||
<StudioTextarea | ||
size='sm' | ||
id={id} | ||
label={label} | ||
value={value} | ||
onChange={(e: ChangeEvent<HTMLInputElement>) => debouncedOnChange(e.target.value)} | ||
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => debouncedOnChange(e.target.value)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
frontend/packages/ux-editor/src/containers/DesignView/AddItem/AddItemModal.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.componentButtonInline { | ||
height: 80px; | ||
width: 140px; | ||
margin: 8px; | ||
height: 60px; | ||
width: 120px; | ||
margin: 4px; | ||
padding: 6px; | ||
} |
10 changes: 5 additions & 5 deletions
10
frontend/packages/ux-editor/src/containers/DesignView/AddItem/ComponentButton.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
.componentButton { | ||
margin: 4px; | ||
width: 140px; | ||
height: 100px; | ||
width: 130px; | ||
height: 80px; | ||
padding: 2px; | ||
overflow: wrap; | ||
} | ||
|
||
.componentButtonInline { | ||
height: 80px; | ||
width: 140px; | ||
margin: 8px; | ||
height: 60px; | ||
width: 120px; | ||
margin: 4px; | ||
padding: 2px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
frontend/packages/ux-editor/src/containers/DesignView/AddItem/FeedbackForm.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { FeedbackForm } from './FeedbackForm'; | ||
import axios from 'axios'; | ||
|
||
jest.mock('axios'); | ||
var mockedAxios = axios as jest.Mocked<typeof axios>; | ||
|
||
describe('FeedbackForm', () => { | ||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render feedback form', () => { | ||
renderFeedbackForm(); | ||
expect(screen.getByRole('button', { name: 'Gi tilbakemelding' })).toBeInTheDocument(); | ||
}); | ||
|
||
it('should open the feedback form when clicking trigger', async () => { | ||
const user = userEvent.setup(); | ||
renderFeedbackForm(); | ||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
await user.click(screen.getByRole('button', { name: 'Gi tilbakemelding' })); | ||
expect(await screen.findByRole('dialog')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should close the feedback form when clicking send', async () => { | ||
const user = userEvent.setup(); | ||
mockedAxios.post.mockResolvedValueOnce({}); | ||
renderFeedbackForm(); | ||
await user.click(screen.getByRole('button', { name: 'Gi tilbakemelding' })); | ||
expect(await screen.findByRole('dialog')).toBeInTheDocument(); | ||
await user.click(screen.getByRole('button', { name: 'Send' })); | ||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
const renderFeedbackForm = () => { | ||
return render(<FeedbackForm />); | ||
}; |
63 changes: 63 additions & 0 deletions
63
frontend/packages/ux-editor/src/containers/DesignView/AddItem/FeedbackForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { ReactElement } from 'react'; | ||
import { submitFeedbackPath } from 'app-shared/api/paths'; | ||
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; | ||
import { post } from 'app-shared/utils/networking'; | ||
import { FeedbackFormImpl } from '@studio/feedback-form'; | ||
import { toast } from 'react-toastify'; | ||
|
||
/** | ||
* This is a feedback form to gather feedback on the new design for adding components. | ||
* It uses the FeedbackForm component from the @studio/feedback-form package. | ||
* The form is temporary, and will be removed once the new design is fully tested, or we decide to go in a different direction. | ||
* As such, all texts are hardcoded in Norwegian, to avoid adding unnecessary translations. | ||
* @returns The FeedbackForm component. | ||
*/ | ||
export function FeedbackForm(): ReactElement { | ||
const { org, app } = useStudioEnvironmentParams(); | ||
|
||
const submitFeedback = async (answers: Record<string, string>) => { | ||
try { | ||
// Using regular axios post rather than a mutation hook, since we are not storing | ||
// the feedback in the cache, nor are we updating any state. | ||
await post(submitFeedbackPath(org, app), { answers: { ...answers } }); | ||
toast.success('Takk for tilbakemeldingen!'); | ||
} catch (error) { | ||
console.error('Failed to submit feedback', error); | ||
toast.error('Noe gikk galt. Prøv igjen senere.'); | ||
} | ||
}; | ||
|
||
const feedbackForm = new FeedbackFormImpl({ | ||
id: 'add-component-poc-feedback', | ||
onSubmit: submitFeedback, | ||
buttonTexts: { | ||
submit: 'Send', | ||
trigger: 'Gi tilbakemelding', | ||
close: 'Lukk', | ||
}, | ||
heading: 'Gi tilbakemelding', | ||
description: | ||
'Hei! Så bra at du har testet det nye designet for å legge til komponenter! Vi vil gjerne høre hva du synes.', | ||
disclaimer: | ||
'Merk at KI-verktøy kan bli brukt til å analysere svarene. Påse at du ikke inkluderer personopplysninger i dine svar.', | ||
position: 'fixed', | ||
questions: [ | ||
{ | ||
id: 'bedreJaNei', | ||
type: 'yesNo', | ||
questionText: 'Likte du dette designet bedre?', | ||
buttonLabels: { | ||
yes: 'Ja', | ||
no: 'Nei', | ||
}, | ||
}, | ||
{ | ||
id: 'kommentar', | ||
type: 'text', | ||
questionText: 'Har du kommentarer eller forslag til forbedringer?', | ||
}, | ||
], | ||
}); | ||
|
||
return feedbackForm.getFeedbackForm(); | ||
} |
5 changes: 5 additions & 0 deletions
5
...end/packages/ux-editor/src/containers/DesignView/AddItem/ToggleAddComponentPoc.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.switchWrapper { | ||
display: flex; | ||
flex-direction: row; | ||
gap: var(--fds-spacing-2); | ||
} |
10 changes: 10 additions & 0 deletions
10
frontend/packages/ux-editor/src/containers/DesignView/AddItem/ToggleAddComponentPoc.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { ToggleAddComponentPoc } from './ToggleAddComponentPoc'; | ||
|
||
describe('ToggleAddComponentPoc', () => { | ||
it('should render the component', () => { | ||
render(<ToggleAddComponentPoc />); | ||
expect(screen.getByText('Prøv nytt design')).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.