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

v4/ Add Config tools for AttachmentList #12250

Merged
merged 110 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
040182d
remove includePdf property
lassopicasso Jan 29, 2024
d80dde5
init attachmentList + display all datatypes in combobox (minus dataTy…
lassopicasso Jan 29, 2024
b9250be
filter added
lassopicasso Jan 30, 2024
832b06e
Add some texts and cover some scenarios
lassopicasso Jan 30, 2024
d486dc8
include all attachments, all attach (exl. pdf), and sort them + descr…
lassopicasso Jan 30, 2024
512bba6
added behaviour when special variants is used + more
lassopicasso Feb 2, 2024
878d321
attachmentList functions as desired now
lassopicasso Feb 2, 2024
77e0b5e
Refactor attachmentList + Content, and add pending spinner
lassopicasso Feb 5, 2024
866706c
remove unused file
lassopicasso Feb 5, 2024
34725dd
update type
lassopicasso Feb 5, 2024
0b9d36a
init tests for attachmentListComponent
lassopicasso Feb 5, 2024
f017dd5
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 6, 2024
a3a9228
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 6, 2024
b7b8789
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 7, 2024
eb4d724
added unit tests, but need to add some more and clean up the code
lassopicasso Feb 8, 2024
3285a25
unit tests completed!
lassopicasso Feb 9, 2024
38ff871
unit test - completed v2
lassopicasso Feb 9, 2024
a7a98b2
Add spinner on higher lvl
lassopicasso Feb 9, 2024
a24cc7e
update code after ux feedback
lassopicasso Feb 12, 2024
3ff0122
update tests
lassopicasso Feb 12, 2024
3c5a5ec
other updates
lassopicasso Feb 12, 2024
2be67b4
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 12, 2024
356f257
cover some tests
lassopicasso Feb 12, 2024
2da6249
naming
lassopicasso Feb 12, 2024
902f51f
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 12, 2024
d644400
cover more lines
lassopicasso Feb 12, 2024
04d528b
Merge branch 'update-attachmentList-config-v4' of https://github.com/…
lassopicasso Feb 12, 2024
3b4f6bf
naming v2
lassopicasso Feb 12, 2024
bda2bd8
cover the uncovered partial lines
lassopicasso Feb 13, 2024
03adb64
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 13, 2024
eb790ff
one last adjustment + remove comments
lassopicasso Feb 13, 2024
f44f738
Merge branch 'update-attachmentList-config-v4' of https://github.com/…
lassopicasso Feb 13, 2024
30ef5ee
move function removeItemByValue to lib
lassopicasso Feb 14, 2024
0ab4656
change text
lassopicasso Feb 14, 2024
ce8f753
changes after feedback - next step implement indeterminate
lassopicasso Feb 15, 2024
b824c51
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 20, 2024
0bc2ba4
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 20, 2024
4833985
small fix
lassopicasso Feb 20, 2024
e953f45
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Feb 21, 2024
704a447
remove console.log from App.tsx
lassopicasso Feb 27, 2024
9b07d67
implement indeterminate checkbox + change logic of incoming and outco…
lassopicasso Mar 2, 2024
b4d3edf
assign state on currentTask to avoid saving to backend when no attach…
lassopicasso Mar 2, 2024
1af68da
some cleanup
lassopicasso Mar 2, 2024
2dad9d6
refactor outgoing data logic
lassopicasso Mar 4, 2024
2a151c5
update component and content logic + refactor
lassopicasso Mar 4, 2024
78f6b79
update onChangeTask - need to use an updated list of attachments
lassopicasso Mar 5, 2024
f8432a8
add unit tests for external format
lassopicasso Mar 6, 2024
ca9f2a0
add tests when converting to internal and external format
lassopicasso Mar 7, 2024
3b7da18
update tests on converting internal external
lassopicasso Mar 7, 2024
d59ed90
Refactor highest level to only handle incoming and outgoing data
lassopicasso Mar 7, 2024
16243ca
second level -> attachmentListInternalFormat
lassopicasso Mar 7, 2024
246604d
Lvl 3 - internal format combobox
lassopicasso Mar 7, 2024
2907c5c
Updated attachmentListUtils
lassopicasso Mar 7, 2024
d2a2c2f
AttachmentListUtils - update naming + cleanup
lassopicasso Mar 7, 2024
f30f4ce
small change in naming
lassopicasso Mar 7, 2024
72f6e8c
Updated arrayUtils
lassopicasso Mar 8, 2024
7e0e3ea
fix validation function + add tests for validation
lassopicasso Mar 8, 2024
3071b9a
update ArrayUtils.intersection with tests and more use of it
lassopicasso Mar 8, 2024
297ee04
renaming and get rid of the last bug!
lassopicasso Mar 8, 2024
ad494b5
temperoray status on attachmentListComponent tests before removing th…
lassopicasso Mar 8, 2024
e4f9f2f
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Mar 8, 2024
69e0492
check test coverage
lassopicasso Mar 10, 2024
e93c100
try to check coverage
lassopicasso Mar 10, 2024
fe262cc
3th attempt
lassopicasso Mar 10, 2024
967684e
Update unit tests
lassopicasso Mar 11, 2024
0a6fd4c
update unit tests
lassopicasso Mar 11, 2024
726adf1
add spinner when data is fetching + tests
lassopicasso Mar 11, 2024
e795825
Some cleanup
lassopicasso Mar 11, 2024
9740e68
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Mar 11, 2024
4c36798
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Mar 13, 2024
073a659
renaming convert functions
lassopicasso Mar 13, 2024
4261d38
update unit tests to use it.each format instead
lassopicasso Mar 13, 2024
ce9b3c4
test driven dev - update external and internal convert functions to h…
lassopicasso Mar 13, 2024
75a6925
add fieldset wrapper
lassopicasso Mar 13, 2024
c5a68c7
Fix converting unit tests after feedback
lassopicasso Mar 13, 2024
607b157
Updated convert functions, validation function + small adjustments in…
lassopicasso Mar 15, 2024
be065df
Refactor react logic to handle the updated convert functions
lassopicasso Mar 15, 2024
e59fcaf
remove console.log
lassopicasso Mar 15, 2024
c5791f5
Fix: call OnChange when onChangeTask is called :D
lassopicasso Mar 15, 2024
d1a2f99
add types
lassopicasso Mar 15, 2024
15baef8
Update component unit tests
lassopicasso Mar 15, 2024
ada2119
move convert functions in separate files + own type file
lassopicasso Mar 15, 2024
248b365
small adjustments in unit tests
lassopicasso Mar 15, 2024
5065917
small changes
lassopicasso Mar 15, 2024
3a79990
convert functions - split to two files and their own tests files
lassopicasso Mar 18, 2024
9a66f7c
updated convertToInternalFunction
lassopicasso Mar 18, 2024
6f7b422
renaming validation function
lassopicasso Mar 18, 2024
f6f6d3b
refactor attachmentList: -Component, -Content, -InternalFormat files
lassopicasso Mar 18, 2024
19aa36f
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Mar 18, 2024
9ce9678
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Mar 18, 2024
1ec3c5e
simplify convertToExternalFormat function
lassopicasso Mar 18, 2024
427501d
rename file
lassopicasso Mar 18, 2024
81967d6
rename file back
lassopicasso Mar 18, 2024
028419f
rename files lowercase
lassopicasso Mar 18, 2024
7712ac7
reuse function extractCurrentAvailableAttachments
lassopicasso Mar 19, 2024
95c8f1b
solve a case when convert to internal format and only pdf is selected
lassopicasso Mar 19, 2024
795f1f8
small adjustment in unit test
lassopicasso Mar 19, 2024
fc65f4e
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Mar 20, 2024
d34e485
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Mar 26, 2024
4074f2b
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Mar 31, 2024
55e5dc4
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Apr 5, 2024
0a3d31b
fix breaking changes after merge with main
lassopicasso Apr 8, 2024
6d63eef
update naming mockStore after merge with main
lassopicasso Apr 8, 2024
0c422dc
fix - make sure that selected datatypes exists in available datatypes…
lassopicasso Apr 17, 2024
f4ab265
add useEffect
lassopicasso Apr 17, 2024
7781e2b
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Apr 17, 2024
41c4130
Make sure initial selected values in combobox is displayed correctly …
lassopicasso Apr 18, 2024
e8b8715
Merge branch 'main' into update-attachmentList-config-v4
lassopicasso Apr 18, 2024
bcf3a03
removal of key index
lassopicasso Apr 18, 2024
2395a3b
remove index*
lassopicasso Apr 18, 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
7 changes: 7 additions & 0 deletions frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@
"ux_editor.component_properties.compact": "Bruk kompakt visning",
"ux_editor.component_properties.componentRef": "ID på komponenten det gjelder (componentRef)",
"ux_editor.component_properties.config_is_expression_message": "Denne egenskapen er konfigurert som et uttrykk, og kan foreløpig ikke redigeres her.",
"ux_editor.component_properties.current_task": "Kun gjeldende oppgave",
"ux_editor.component_properties.dataListId": "Id på dataliste",
"ux_editor.component_properties.dataTypeIds": "Liste med ID på datatyper som skal vises",
"ux_editor.component_properties.dateSent": "Dato instansen ble sendt inn",
Expand All @@ -1572,6 +1573,7 @@
"ux_editor.component_properties.largeGroup": "Stor gruppevisning/gruppe i gruppe",
"ux_editor.component_properties.layers": "Kartlag",
"ux_editor.component_properties.layout": "Visning",
"ux_editor.component_properties.loading": "Laster inn",
"ux_editor.component_properties.mapping": "Mapping",
"ux_editor.component_properties.maxCount": "Maks antall repetisjoner",
"ux_editor.component_properties.maxDate": "Seneste dato",
Expand Down Expand Up @@ -1602,6 +1604,9 @@
"ux_editor.component_properties.sandbox": "Sandbox",
"ux_editor.component_properties.saveWhileTyping": "Overstyr tidsintervall for lagring når bruker skriver",
"ux_editor.component_properties.secure": "Bruk sikret versjon av API for å hente valg (secure)",
"ux_editor.component_properties.select_all_attachments": "Alle vedlegg",
"ux_editor.component_properties.select_attachments": "Velg vedlegg",
"ux_editor.component_properties.select_pdf": "Inkluder skjemagenerert pdf",
"ux_editor.component_properties.sender": "Hvem som har sendt inn skjema",
"ux_editor.component_properties.severity": "Alvorlighetsgrad",
"ux_editor.component_properties.showAsCard": "Vis som kort",
Expand Down Expand Up @@ -1641,6 +1646,8 @@
"ux_editor.component_title.AddressComponent": "Adresse",
"ux_editor.component_title.Alert": "Varsel",
"ux_editor.component_title.AttachmentList": "Liste over vedlegg",
"ux_editor.component_title.AttachmentList_error": "Du må velge minst ett vedlegg eller PDF",
"ux_editor.component_title.AttachmentList_legend": "Vedleggsliste",
"ux_editor.component_title.Button": "Knapp",
"ux_editor.component_title.ButtonGroup": "Knappegruppe",
"ux_editor.component_title.Checkboxes": "Avkrysningsbokser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ describe('ArrayUtils', () => {
});
});

describe('removeItemByValue', () => {
it('Deletes item from array by value', () => {
expect(ArrayUtils.removeItemByValue([1, 2, 3], 2)).toEqual([1, 3]);
expect(ArrayUtils.removeItemByValue(['a', 'b', 'c'], 'b')).toEqual(['a', 'c']);
expect(ArrayUtils.removeItemByValue(['a', 'b', 'c'], 'd')).toEqual(['a', 'b', 'c']);
expect(ArrayUtils.removeItemByValue([], 'a')).toEqual([]);
expect(ArrayUtils.removeItemByValue(['a', 'b', 'c', 'b', 'a'], 'b')).toEqual(['a', 'c', 'a']);
});
});

describe('last', () => {
it('Returns last item in array', () => {
expect(ArrayUtils.last([1, 2, 3])).toEqual(3);
Expand All @@ -47,6 +57,22 @@ describe('ArrayUtils', () => {
});
});

describe('ArrayUtils.intersection', () => {
it('Returns intersection of two arrays when included is true', () => {
expect(ArrayUtils.intersection([1, 2, 3], [3, '4', 5])).toStrictEqual([3]);
expect(ArrayUtils.intersection([1, 2, 3], [4, '4', 5])).toStrictEqual([]);
expect(ArrayUtils.intersection([1, 2, 3], [3, '4', 2])).toStrictEqual([2, 3]);
expect(ArrayUtils.intersection([1, 2, 3], [1, 2, 3])).toStrictEqual([1, 2, 3]);
});

it('Returns intersection of two arrays when included is false', () => {
expect(ArrayUtils.intersection([1, 2, 3], [3, '4', 5], false)).toStrictEqual([1, 2]);
expect(ArrayUtils.intersection([1, 2, 3], [4, '4', 5], false)).toStrictEqual([1, 2, 3]);
expect(ArrayUtils.intersection([1, 2, 3], [3, '4', 2], false)).toStrictEqual([1]);
expect(ArrayUtils.intersection([1, 2, 3], [1, 2, 3], false)).toStrictEqual([]);
});
});

describe('replaceByIndex', () => {
it('Replaces element in array with new value', () => {
const array1 = ['0', '1', '2'];
Expand Down
21 changes: 21 additions & 0 deletions frontend/libs/studio-pure-functions/src/ArrayUtils/ArrayUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,30 @@ export class ArrayUtils {
return givenIndex < 0 || givenIndex >= array.length ? array.length - 1 : givenIndex;
}

/**
* Removes item from array by value.
* @param array Array to delete item from.
* @param value Value to delete.
* @returns Array without the given value.
*/
public static removeItemByValue<T>(array: T[], value: T): T[] {
return array.filter((item) => item !== value);
}

/** Returns the last item of the given array */
public static last = <T>(array: T[]): T => array[array.length - 1];

/**
* Returns an array of which the element of arrA are either present or not present in arrB based on the include param.
* @param arrA The first array.
* @param arrB The second array.
* @param include Whether to include or exclude the elements of arrB from arrA. Defaults to true.
* @returns Array that contains the filtered elements based on the filtering condition.
*/
public static intersection = <T>(arrA: T[], arrB: T[], include: boolean = true): T[] => {
return arrA.filter((x) => (include ? arrB.includes(x) : !arrB.includes(x)));
};

/** Replaces an element in an array with a new value */
public static replaceByIndex = <T>(array: T[], index: number, newValue: T): T[] => {
if (index < 0 || index >= array.length) return array;
Expand Down
3 changes: 1 addition & 2 deletions frontend/packages/schema-model/src/lib/SchemaModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
generateUniqueStringWithNumber,
insertArrayElementAtPos,
moveArrayItem,
removeItemByValue,
replaceItemsByValue,
} from 'app-shared/utils/arrayUtils';
import { ROOT_POINTER } from './constants';
Expand Down Expand Up @@ -356,7 +355,7 @@ export class SchemaModel {

private removeNodeFromParent = (pointer: string): void => {
const parent = this.getParentNode(pointer);
parent.children = removeItemByValue(parent.children, pointer);
parent.children = ArrayUtils.removeItemByValue(parent.children, pointer);
};

public getParentNode(pointer: string): FieldNode | CombinationNode | undefined {
Expand Down
9 changes: 4 additions & 5 deletions frontend/packages/schema-model/src/lib/mappers/field-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
StrRestrictionKey,
} from '../../types';
import { getCombinationKind, getObjectKind, isField } from '../utils';
import { arrayIntersection } from 'app-shared/utils/arrayUtils';
import type { KeyValuePairs } from 'app-shared/types/KeyValuePairs';
import { ArrayUtils } from '@studio/pure-functions';

Expand All @@ -31,13 +30,13 @@ export const findUiFieldType = (schemaNode: KeyValuePairs) => {
} else if (isCompundFieldType(schemaNode.type)) {
// @see SeresNillable.json, we need to support types where stuff can be null.
return schemaNode.type.filter((t: FieldType) => t !== FieldType.Null).pop();
} else if (arrayIntersection(keys, Object.values(IntRestrictionKey)).length) {
} else if (ArrayUtils.intersection(keys, Object.values(IntRestrictionKey)).length) {
return FieldType.Number;
} else if (arrayIntersection(keys, Object.values(ArrRestrictionKey)).length) {
} else if (ArrayUtils.intersection(keys, Object.values(ArrRestrictionKey)).length) {
return FieldType.Boolean;
} else if (arrayIntersection(keys, Object.values(StrRestrictionKey)).length) {
} else if (ArrayUtils.intersection(keys, Object.values(StrRestrictionKey)).length) {
return FieldType.String;
} else if (arrayIntersection(keys, Object.values(ObjRestrictionKey)).length) {
} else if (ArrayUtils.intersection(keys, Object.values(ObjRestrictionKey)).length) {
return FieldType.Object;
} else if (Array.isArray(schemaNode.enum) && schemaNode.enum.length) {
return findEnumFieldType(schemaNode.enum);
Expand Down
5 changes: 3 additions & 2 deletions frontend/packages/schema-model/test/validateTestUiSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { UiSchemaNodes } from '../src';
import { FieldType, ObjectKind, ROOT_POINTER } from '../src';
import { getPointers } from '../src/lib/mappers/getPointers';
import { areItemsUnique, mapByKey, removeItemByValue } from 'app-shared/utils/arrayUtils';
import { areItemsUnique, mapByKey } from 'app-shared/utils/arrayUtils';
import {
isField,
isFieldOrCombination,
Expand All @@ -12,6 +12,7 @@ import {
isNotTheRootNode,
isTheRootNode,
} from '../src/lib/utils';
import { ArrayUtils } from '@studio/pure-functions';

/** Verifies that there is a root node */
export const hasRootNode = (uiSchema: UiSchemaNodes) =>
Expand All @@ -33,7 +34,7 @@ export const allPointersExist = (uiSchema: UiSchemaNodes) => {
/** Verifies that all nodes except the root node have a parent */
export const nodesHaveParent = (uiSchema: UiSchemaNodes) => {
const allChildPointers = mapByKey(uiSchema.filter(isFieldOrCombination), 'children').flat();
removeItemByValue(getPointers(uiSchema), ROOT_POINTER).forEach((pointer) => {
ArrayUtils.removeItemByValue(getPointers(uiSchema), ROOT_POINTER).forEach((pointer) => {
expect(allChildPointers).toContain(pointer);
});
};
Expand Down
21 changes: 0 additions & 21 deletions frontend/packages/shared/src/utils/arrayUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
areItemsUnique,
arrayIntersection,
generateUniqueStringWithNumber,
insertArrayElementAtPos,
mapByKey,
moveArrayItem,
prepend,
removeEmptyStrings,
removeItemByValue,
replaceByPredicate,
replaceItemsByValue,
swapArrayElements,
Expand All @@ -21,16 +19,6 @@ describe('arrayUtils', () => {
});
});

describe('removeItemByValue', () => {
it('Deletes item from array by value', () => {
expect(removeItemByValue([1, 2, 3], 2)).toEqual([1, 3]);
expect(removeItemByValue(['a', 'b', 'c'], 'b')).toEqual(['a', 'c']);
expect(removeItemByValue(['a', 'b', 'c'], 'd')).toEqual(['a', 'b', 'c']);
expect(removeItemByValue([], 'a')).toEqual([]);
expect(removeItemByValue(['a', 'b', 'c', 'b', 'a'], 'b')).toEqual(['a', 'c', 'a']);
});
});

describe('areItemsUnique', () => {
it('Returns true if all items are unique', () => {
expect(areItemsUnique([1, 2, 3])).toBe(true);
Expand Down Expand Up @@ -81,15 +69,6 @@ describe('arrayUtils', () => {
});
});

describe('arrayIntersection', () => {
it('Returns intersection of two arrays', () => {
expect(arrayIntersection([1, 2, 3], [3, '4', 5])).toStrictEqual([3]);
expect(arrayIntersection([1, 2, 3], [4, '4', 5])).toStrictEqual([]);
expect(arrayIntersection([1, 2, 3], [3, '4', 2])).toStrictEqual([2, 3]);
expect(arrayIntersection([1, 2, 3], [1, 2, 3])).toStrictEqual([1, 2, 3]);
});
});

describe('mapByKey', () => {
it('Returns an array of values mapped by the given key', () => {
const array = [
Expand Down
22 changes: 4 additions & 18 deletions frontend/packages/shared/src/utils/arrayUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ArrayUtils } from '@studio/pure-functions';

/**
* Adds an item to the beginning of an array..
* @param array The array of interest.
Expand All @@ -17,15 +19,6 @@ export const replaceLastItem = <T>(array: T[], replaceWith: T): T[] => {
return array;
};

/**
* Removes item from array by value.
* @param array Array to delete item from.
* @param value Value to delete.
* @returns Array without the given value.
*/
export const removeItemByValue = <T>(array: T[], value: T): T[] =>
array.filter((item) => item !== value);

/**
* Checks if all items in the given array are unique.
* @param array The array of interest.
Expand Down Expand Up @@ -63,14 +56,6 @@ export const insertArrayElementAtPos = <T>(array: T[], item: T, targetPos: numbe
return out;
};

/**
* Returns an array of which the elements are present in both given arrays.
* @param arrA First array.
* @param arrB Second array.
* @returns Array of which the elements are present in both given arrays.
*/
export const arrayIntersection = <T>(arrA: T[], arrB: T[]) => arrA.filter((x) => arrB.includes(x));

/**
* Maps an array of objects by a given key.
* @param array The array of objects.
Expand Down Expand Up @@ -132,4 +117,5 @@ export const generateUniqueStringWithNumber = (array: string[], prefix: string =
};

/** Removes empty strings from a string array */
export const removeEmptyStrings = (array: string[]): string[] => removeItemByValue(array, '');
export const removeEmptyStrings = (array: string[]): string[] =>
ArrayUtils.removeItemByValue(array, '');
6 changes: 3 additions & 3 deletions frontend/packages/text-editor/src/RightMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { LangSelector } from './LangSelector';
import { getLangName, langOptions } from './utils';
import { Checkbox, Fieldset, Heading } from '@digdir/design-system-react';
import { defaultLangCode } from './constants';
import { removeItemByValue } from 'app-shared/utils/arrayUtils';
import { useTranslation } from 'react-i18next';
import { AltinnConfirmDialog } from 'app-shared/components';
import * as testids from '../../../testing/testids';
import { StudioButton } from '@studio/components';
import { ArrayUtils } from '@studio/pure-functions';

export interface RightMenuProps {
addLanguage: (langCode: LangCode) => void;
Expand All @@ -34,11 +34,11 @@ export const RightMenu = ({
const handleSelectChange = async ({ target }: React.ChangeEvent<HTMLInputElement>) => {
target.checked
? setSelectedLanguages([...selectedLanguages, target.name])
: setSelectedLanguages(removeItemByValue(selectedLanguages, target.name));
: setSelectedLanguages(ArrayUtils.removeItemByValue(selectedLanguages, target.name));
};

const handleDeleteLanguage = (langCode: LangCode) => {
setSelectedLanguages(removeItemByValue(selectedLanguages, langCode));
setSelectedLanguages(ArrayUtils.removeItemByValue(selectedLanguages, langCode));
deleteLanguage(langCode);
};

Expand Down
14 changes: 10 additions & 4 deletions frontend/packages/ux-editor-v3/src/utils/formLayoutUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type {
IToolbarElement,
} from '../types/global';
import { BASE_CONTAINER_ID, MAX_NESTED_GROUP_LEVEL } from 'app-shared/constants';
import { ObjectUtils } from '@studio/pure-functions';
import { insertArrayElementAtPos, removeItemByValue } from 'app-shared/utils/arrayUtils';
import { insertArrayElementAtPos } from 'app-shared/utils/arrayUtils';
import { ArrayUtils, ObjectUtils } from '@studio/pure-functions';
import { ComponentTypeV3 } from 'app-shared/types/ComponentTypeV3';
import type { FormComponent } from '../types/FormComponent';
import { generateFormItem } from './component';
Expand Down Expand Up @@ -202,7 +202,10 @@ export const removeComponent = (layout: IInternalLayout, componentId: string): I
const newLayout = ObjectUtils.deepCopy(layout);
const containerId = findParentId(layout, componentId);
if (containerId) {
newLayout.order[containerId] = removeItemByValue(newLayout.order[containerId], componentId);
newLayout.order[containerId] = ArrayUtils.removeItemByValue(
newLayout.order[containerId],
componentId,
);
delete newLayout.components[componentId];
}
return newLayout;
Expand Down Expand Up @@ -294,7 +297,10 @@ export const moveLayoutItem = (
const item = findItem(newLayout, id);
item.pageIndex = calculateNewPageIndex(newLayout, newContainerId, newPosition);
if (oldContainerId) {
newLayout.order[oldContainerId] = removeItemByValue(newLayout.order[oldContainerId], id);
newLayout.order[oldContainerId] = ArrayUtils.removeItemByValue(
newLayout.order[oldContainerId],
id,
);
newLayout.order[newContainerId] = insertArrayElementAtPos(
newLayout.order[newContainerId],
id,
Expand Down
Loading
Loading