Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge select and edit tabs in config #14137

Merged
merged 23 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
905b5e9
Merge option editor views into 1 tab.
Konrad-Simso Nov 20, 2024
703fa90
Revert removing old files to maintain the same functionality in prod …
Konrad-Simso Nov 21, 2024
2153800
Merge branch 'main' into feat/mergeSelectAndEditCodelistViews
Konrad-Simso Nov 22, 2024
c1c448c
Fixes after merge, and add required duplicate code until featureFlag …
Konrad-Simso Nov 22, 2024
3eee769
Add tests, missing file after moving files into new folder.
Konrad-Simso Nov 22, 2024
559682d
Update tests, remove unused imports, and add/update Todo comments.
Konrad-Simso Nov 22, 2024
7ecf962
Clean up unused, and not required files.
Konrad-Simso Nov 22, 2024
c6e24f4
Merge branch 'main' into feat/mergeSelectAndEditCodelistViews
Konrad-Simso Nov 22, 2024
73595cd
Fix imports
Konrad-Simso Nov 22, 2024
85fa21e
Fix imports and coverage.
Konrad-Simso Nov 22, 2024
9d20ef1
Updates from review
Konrad-Simso Nov 26, 2024
f29fa9d
Removed renderOptions prop from EditOptions.tsx
Konrad-Simso Nov 28, 2024
96879e1
Update tests
Konrad-Simso Nov 28, 2024
698c9c6
Fix bug when making an empty options-list
Konrad-Simso Nov 29, 2024
8c9f0c1
Fix tests
Konrad-Simso Dec 5, 2024
e9a0d13
Updates from review, refactoring and rename variables.
Konrad-Simso Dec 5, 2024
3284927
Correcting spelling mistake in variable name.
Konrad-Simso Dec 5, 2024
4641eb5
Refactoring.
Konrad-Simso Dec 5, 2024
e351ab7
Merge branch 'main' into feat/mergeSelectAndEditCodelistViews
Konrad-Simso Dec 6, 2024
e485126
Fixes after merge
Konrad-Simso Dec 6, 2024
91aa45e
Merge branch 'main' into feat/mergeSelectAndEditCodelistViews
Konrad-Simso Dec 6, 2024
5e8421e
Fix texts and remove unused/empty files
Konrad-Simso Dec 6, 2024
09f0614
Fix import statement
Konrad-Simso Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,10 @@
"ux_editor.modal_header_type_helper": "Velg titteltype",
"ux_editor.modal_new_option": "Legg til alternativ",
"ux_editor.modal_properties_add_radio_button_options": "Hvordan vil du legge til radioknapper?",
"ux_editor.modal_properties_code_list": "Velg fra biblioteket",
"ux_editor.modal_properties_code_list_alert_title": "Du er i ferd med å redigere en kodeliste i biblioteket.",
Konrad-Simso marked this conversation as resolved.
Show resolved Hide resolved
"ux_editor.modal_properties_code_list_button_title_library": "Kodeliste fra biblioteket",
"ux_editor.modal_properties_code_list_button_title_manual": "Kodeliste på komponenten",
"ux_editor.modal_properties_code_list_custom_list": "Egendefinert kodeliste",
"ux_editor.modal_properties_code_list_filename_error": "Filnavnet er ugyldig. Du kan bruke tall, understrek, punktum, bindestrek, og store/små bokstaver fra det norske alfabetet. Filnavnet må starte med en engelsk bokstav.",
"ux_editor.modal_properties_code_list_helper": "Velg kodeliste",
Expand All @@ -1534,7 +1538,6 @@
"ux_editor.modal_properties_code_list_read_more_dynamic": "<0 href=\"{{optionsDocs}}\" >Les mer om dynamiske kodelister</0>",
"ux_editor.modal_properties_code_list_read_more_static": "<0 href=\"{{optionsDocs}}\" >Les mer om statiske kodelister</0>",
"ux_editor.modal_properties_code_list_spinner_title": "Laster inn kodelister",
"ux_editor.modal_properties_code_list_upload": "Last opp din egen kodeliste",
"ux_editor.modal_properties_code_list_upload_duplicate_error": "Opplastning feilet. Du prøvde å laste opp en fil som finnes fra før.",
"ux_editor.modal_properties_code_list_upload_generic_error": "Opplastning feilet. Filen du lastet opp er ikke satt opp riktig.",
"ux_editor.modal_properties_code_list_upload_success": "Filen ble lastet opp.",
Expand Down Expand Up @@ -1681,11 +1684,14 @@
"ux_editor.options.code_list_referenceId.description": "Her kan du legge til en referanse-ID til en dynamisk kodeliste som er satt opp i koden.",
"ux_editor.options.code_list_referenceId.description_details": "Du bruker dynamiske kodelister for å tilpasse alternativer for brukerne. Det kan for eksempel være tilpasninger ut fra geografisk plassering, eller valg brukeren gjør tidligere i skjemaet.",
"ux_editor.options.multiple": "{{value}} alternativer",
"ux_editor.options.option_edit_text": "Rediger kodeliste",
"ux_editor.options.option_remove_text": "Fjern valgt kodeliste",
"ux_editor.options.section_heading": "Valg for kodelister",
"ux_editor.options.single": "{{value}} alternativ",
"ux_editor.options.tab_code_list": "Velg kodeliste",
"ux_editor.options.tab_manual": "Sett opp egne alternativer",
"ux_editor.options.tab_referenceId": "Angi referanse-ID",
"ux_editor.options.upload_title": "Last opp din egen",
Konrad-Simso marked this conversation as resolved.
Show resolved Hide resolved
"ux_editor.page": "Side",
"ux_editor.page_config_pdf_abort_converting_page_to_pdf": "Avbryt å gjøre om siden til PDF",
"ux_editor.page_config_pdf_card_heading": "Siden skal være en PDF",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ describe('StudioCodeListEditor', () => {
const labelInput = screen.getByRole('textbox', { name: texts.itemLabel(1) });
const newValue = 'new text';
await user.type(labelInput, newValue);
expect(onChange).toHaveBeenCalledTimes(newValue.length);
await user.tab();
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenLastCalledWith([
{ ...codeList[0], label: newValue },
codeList[1],
Expand All @@ -133,7 +134,8 @@ describe('StudioCodeListEditor', () => {
const valueInput = screen.getByRole('textbox', { name: texts.itemValue(1) });
const newValue = 'new text';
await user.type(valueInput, newValue);
expect(onChange).toHaveBeenCalledTimes(newValue.length);
await user.tab();
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenLastCalledWith([
{ ...codeList[0], value: newValue },
codeList[1],
Expand All @@ -147,7 +149,8 @@ describe('StudioCodeListEditor', () => {
const descriptionInput = screen.getByRole('textbox', { name: texts.itemDescription(1) });
const newValue = 'new text';
await user.type(descriptionInput, newValue);
expect(onChange).toHaveBeenCalledTimes(newValue.length);
await user.tab();
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenLastCalledWith([
{ ...codeList[0], description: newValue },
codeList[1],
Expand All @@ -161,7 +164,8 @@ describe('StudioCodeListEditor', () => {
const helpTextInput = screen.getByRole('textbox', { name: texts.itemHelpText(1) });
const newValue = 'new text';
await user.type(helpTextInput, newValue);
expect(onChange).toHaveBeenCalledTimes(newValue.length);
await user.tab();
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenLastCalledWith([
{ ...codeList[0], helpText: newValue },
codeList[1],
Expand Down Expand Up @@ -263,7 +267,8 @@ describe('StudioCodeListEditor', () => {
const validValueInput = screen.getByRole('textbox', { name: texts.itemValue(3) });
const newValue = 'new value';
await user.type(validValueInput, newValue);
expect(onInvalid).toHaveBeenCalledTimes(newValue.length);
await user.tab();
expect(onInvalid).toHaveBeenCalledTimes(1);
});

it('Does not trigger onInvalid if an invalid code list is changed to a valid state', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function CodeLists({
item={item}
key={index}
number={index + 1}
onChange={(newItem) => handleChange(index, newItem)}
onBlur={(newItem) => handleChange(index, newItem)}
onDeleteButtonClick={() => handleDeleteButtonClick(index)}
/>
))}
Expand Down
ErlingHauan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,49 @@ type StudioCodeListEditorRowProps = {
error: ValueError | null;
item: CodeListItem;
number: number;
onChange: (newItem: CodeListItem) => void;
onBlur: (newItem: CodeListItem) => void;
onDeleteButtonClick: () => void;
};

export function StudioCodeListEditorRow({
error,
item,
number,
onChange,
onBlur,
onDeleteButtonClick,
}: StudioCodeListEditorRowProps) {
const { texts } = useStudioCodeListEditorContext();

const handleLabelChange = useCallback(
(label: string) => {
const updatedItem = changeLabel(item, label);
onChange(updatedItem);
onBlur(updatedItem);
},
[item, onChange],
[item, onBlur],
);

const handleDescriptionChange = useCallback(
(description: string) => {
const updatedItem = changeDescription(item, description);
onChange(updatedItem);
onBlur(updatedItem);
},
[item, onChange],
[item, onBlur],
);

const handleValueChange = useCallback(
(value: string) => {
const updatedItem = changeValue(item, value);
onChange(updatedItem);
onBlur(updatedItem);
},
[item, onChange],
[item, onBlur],
);

const handleHelpTextChange = useCallback(
(helpText: string) => {
const updatedItem = changeHelpText(item, helpText);
onChange(updatedItem);
onBlur(updatedItem);
},
[item, onChange],
[item, onBlur],
);

return (
Expand All @@ -64,22 +64,22 @@ export function StudioCodeListEditorRow({
autoComplete='off'
error={error && texts.valueErrors[error]}
label={texts.itemValue(number)}
onChange={handleValueChange}
onBlur={handleValueChange}
value={item.value}
/>
<TextfieldCell
label={texts.itemLabel(number)}
onChange={handleLabelChange}
onBlur={handleLabelChange}
value={item.label}
/>
<TextfieldCell
label={texts.itemDescription(number)}
onChange={handleDescriptionChange}
onBlur={handleDescriptionChange}
value={item.description}
/>
<TextfieldCell
label={texts.itemHelpText(number)}
onChange={handleHelpTextChange}
onBlur={handleHelpTextChange}
value={item.helpText}
/>
<DeleteButtonCell onClick={onDeleteButtonClick} number={number} />
Expand All @@ -90,23 +90,23 @@ export function StudioCodeListEditorRow({
type TextfieldCellProps = {
error?: string;
label: string;
onChange: (newString: string) => void;
onBlur: (newString: string) => void;
value: CodeListItemValue;
autoComplete?: HTMLInputAutoCompleteAttribute;
};

function TextfieldCell({ error, label, value, onChange, autoComplete }: TextfieldCellProps) {
function TextfieldCell({ error, label, value, onBlur, autoComplete }: TextfieldCellProps) {
const ref = useRef<HTMLInputElement>(null);

useEffect((): void => {
ref.current?.setCustomValidity(error || '');
}, [error]);

const handleChange = useCallback(
const handleBlur = useCallback(
(event: React.ChangeEvent<HTMLInputElement>): void => {
onChange(event.target.value);
onBlur(event.target.value);
},
[onChange],
[onBlur],
);

const handleFocus = useCallback((event: FocusEvent<HTMLInputElement>): void => {
Expand All @@ -118,7 +118,7 @@ function TextfieldCell({ error, label, value, onChange, autoComplete }: Textfiel
aria-label={label}
autoComplete={autoComplete}
className={classes.textfieldCell}
onChange={handleChange}
onBlur={handleBlur}
onFocus={handleFocus}
ref={ref}
value={(value as string) ?? ''}
Expand Down
Loading