-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ComponentSpecificContent in smaller parts
- Loading branch information
Showing
37 changed files
with
579 additions
and
504 deletions.
There are no files selected for viewing
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
5 changes: 5 additions & 0 deletions
5
...editor/src/components/config/componentSpecificContent/Address/AddressComponent.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 @@ | ||
.root > div { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--fieldset-gap); | ||
} |
29 changes: 29 additions & 0 deletions
29
...x-editor/src/components/config/componentSpecificContent/Address/AddressComponent.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,29 @@ | ||
import React from 'react'; | ||
import { IGenericEditComponent } from '../../componentConfig'; | ||
import { IFormAddressComponent } from '../../../../types/global'; | ||
import { renderWithMockStore } from '../../../../testing/mocks'; | ||
import { AddressComponent } from './AddressComponent'; | ||
|
||
// Test data: | ||
const component: IFormAddressComponent = { | ||
dataModelBindings: { | ||
test: 'test' | ||
}, | ||
id: '1', | ||
simplified: false, | ||
}; | ||
const handleComponentChange = jest.fn(); | ||
const defaultProps: IGenericEditComponent = { | ||
component, | ||
handleComponentChange, | ||
}; | ||
|
||
describe('AddressComponent', () => { | ||
it('Renders without errors', () => { | ||
render(); | ||
}); | ||
}); | ||
|
||
const render = (props?: Partial<IGenericEditComponent>) => | ||
renderWithMockStore()(<AddressComponent {...defaultProps} {...props} />); | ||
|
53 changes: 53 additions & 0 deletions
53
...ges/ux-editor/src/components/config/componentSpecificContent/Address/AddressComponent.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,53 @@ | ||
import React from 'react'; | ||
import { Checkbox, FieldSet } from '@altinn/altinn-design-system'; | ||
import classes from './AddressComponent.module.css'; | ||
import { useText } from '../../../../hooks'; | ||
import { IGenericEditComponent } from '../../componentConfig'; | ||
import { IFormAddressComponent } from '../../../../types/global'; | ||
import { AddressKeys, getTextResourceByAddressKey } from '../../../../utils/component'; | ||
import { EditDataModelBindings } from '../../editModal/EditDataModelBindings'; | ||
|
||
export const AddressComponent = ({ | ||
component, | ||
handleComponentChange, | ||
}: IGenericEditComponent) => { | ||
const t = useText(); | ||
|
||
const handleToggleAddressSimple = (isChecked: boolean) => { | ||
handleComponentChange({ | ||
...component, | ||
simplified: isChecked, | ||
}); | ||
}; | ||
|
||
return ( | ||
<FieldSet className={classes.root}> | ||
<div> | ||
<Checkbox | ||
checked={(component as IFormAddressComponent).simplified} | ||
label={t('ux_editor.modal_configure_address_component_simplified')} | ||
onChange={(e) => handleToggleAddressSimple(e.target.checked)} | ||
/> | ||
</div> | ||
{Object.keys(AddressKeys).map((value: AddressKeys, index) => { | ||
const simple: boolean = (component as IFormAddressComponent).simplified; | ||
if (simple && (value === AddressKeys.careOf || value === AddressKeys.houseNumber)) { | ||
return null; | ||
} | ||
return ( | ||
<EditDataModelBindings | ||
component={component} | ||
handleComponentChange={handleComponentChange} | ||
key={value} | ||
renderOptions={{ | ||
label: getTextResourceByAddressKey(value, t), | ||
returnValue: value, | ||
key: value, | ||
uniqueKey: index, | ||
}} | ||
/> | ||
); | ||
})} | ||
</FieldSet> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Address/index.ts
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 @@ | ||
export { AddressComponent } from './AddressComponent'; |
5 changes: 5 additions & 0 deletions
5
...x-editor/src/components/config/componentSpecificContent/Button/ButtonComponent.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 @@ | ||
.root > div { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--fieldset-gap); | ||
} |
28 changes: 28 additions & 0 deletions
28
.../ux-editor/src/components/config/componentSpecificContent/Button/ButtonComponent.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,28 @@ | ||
import React from 'react'; | ||
import { IGenericEditComponent } from '../../componentConfig'; | ||
import { IFormButtonComponent } from '../../../../types/global'; | ||
import { renderWithMockStore } from '../../../../testing/mocks'; | ||
import { ButtonComponent } from './ButtonComponent'; | ||
import { ComponentTypes } from '../../../'; | ||
|
||
// Test data: | ||
const component: IFormButtonComponent = { | ||
id: '1', | ||
onClickAction: jest.fn(), | ||
type: ComponentTypes.Button, | ||
}; | ||
const handleComponentChange = jest.fn(); | ||
const defaultProps: IGenericEditComponent = { | ||
component, | ||
handleComponentChange, | ||
}; | ||
|
||
describe('ButtonComponent', () => { | ||
it('Renders without errors', () => { | ||
render(); | ||
}); | ||
}); | ||
|
||
const render = (props?: Partial<IGenericEditComponent>) => | ||
renderWithMockStore()(<ButtonComponent {...defaultProps} {...props} />); | ||
|
68 changes: 68 additions & 0 deletions
68
...kages/ux-editor/src/components/config/componentSpecificContent/Button/ButtonComponent.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,68 @@ | ||
import React from 'react'; | ||
import { FieldSet, Select } from '@altinn/altinn-design-system'; | ||
import classes from '../../ButtonComponent.module.css'; | ||
import { EditTitle } from '../../editModal/EditTitle'; | ||
import { useText } from '../../../../hooks'; | ||
import { IGenericEditComponent } from '../../componentConfig'; | ||
import { ComponentTypes } from '../../../index'; | ||
|
||
export const ButtonComponent = ({ | ||
component, | ||
handleComponentChange, | ||
}: IGenericEditComponent) => { | ||
const t = useText(); | ||
|
||
const handleButtonTypeChange = (selected: any) => { | ||
const componentCopy = { ...component }; | ||
if (!componentCopy.textResourceBindings) { | ||
componentCopy.textResourceBindings = {}; | ||
} | ||
if (selected.value === 'NavigationButtons') { | ||
componentCopy.type = 'NavigationButtons'; | ||
componentCopy.textResourceBindings.title = undefined; | ||
(componentCopy as any).textResourceId = undefined; | ||
componentCopy.customType = undefined; | ||
(componentCopy as any).showBackButton = true; | ||
componentCopy.textResourceBindings.next = 'next'; | ||
componentCopy.textResourceBindings.back = 'back'; | ||
} else if (selected.value === 'Button') { | ||
componentCopy.type = 'Button'; | ||
componentCopy.textResourceBindings.next = undefined; | ||
componentCopy.textResourceBindings.back = undefined; | ||
(componentCopy as any).showPrev = undefined; | ||
(componentCopy as any).showBackButton = undefined; | ||
componentCopy.textResourceBindings.title = t('ux_editor.modal_properties_button_type_submit'); | ||
} | ||
handleComponentChange(componentCopy); | ||
}; | ||
|
||
const types = [ | ||
{ | ||
value: ComponentTypes.Button, | ||
label: t('ux_editor.modal_properties_button_type_submit'), | ||
}, | ||
{ | ||
value: ComponentTypes.NavigationButtons, | ||
label: t('ux_editor.modal_properties_button_type_navigation'), | ||
}, | ||
]; | ||
|
||
return ( | ||
<FieldSet className={classes.root}> | ||
<div> | ||
<Select | ||
label={t('ux_editor.modal_properties_button_type_helper')} | ||
options={types} | ||
value={types.find((element) => element.value === component.type).value} | ||
onChange={handleButtonTypeChange} | ||
/> | ||
</div> | ||
{component.type === ComponentTypes.Button && ( | ||
<EditTitle | ||
component={component} | ||
handleComponentChange={handleComponentChange} | ||
/> | ||
)} | ||
</FieldSet> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Button/index.ts
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 @@ | ||
export { ButtonComponent } from './ButtonComponent'; |
Oops, something went wrong.