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(ui-fields): update table repeater #14962

Merged
merged 14 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
4 changes: 4 additions & 0 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}
}

export function buildCheckboxField(

Check warning on line 78 in libs/application/core/src/lib/fieldBuilders.ts

View workflow job for this annotation

GitHub Actions / linting (application-api-core,application-api-files,application-api-history,application-api-payme...

Expected a function expression
data: Omit<CheckboxField, 'type' | 'component' | 'children'>,
): CheckboxField {
const {
Expand All @@ -98,7 +98,7 @@
}
}

export function buildDateField(

Check warning on line 101 in libs/application/core/src/lib/fieldBuilders.ts

View workflow job for this annotation

GitHub Actions / linting (application-api-core,application-api-files,application-api-history,application-api-payme...

Expected a function expression
data: Omit<DateField, 'type' | 'component' | 'children'>,
): DateField {
const {
Expand All @@ -125,7 +125,7 @@
}
}

export function buildDescriptionField(

Check warning on line 128 in libs/application/core/src/lib/fieldBuilders.ts

View workflow job for this annotation

GitHub Actions / linting (application-api-core,application-api-files,application-api-history,application-api-payme...

Expected a function expression
data: Omit<DescriptionField, 'type' | 'component' | 'children'>,
): DescriptionField {
const {
Expand Down Expand Up @@ -153,7 +153,7 @@
}
}

export function buildRadioField(

Check warning on line 156 in libs/application/core/src/lib/fieldBuilders.ts

View workflow job for this annotation

GitHub Actions / linting (application-api-core,application-api-files,application-api-history,application-api-payme...

Expected a function expression
data: Omit<RadioField, 'type' | 'component' | 'children'>,
): RadioField {
const {
Expand Down Expand Up @@ -742,6 +742,8 @@
addItemButtonText,
saveItemButtonText,
removeButtonTooltipText,
editButtonTooltipText,
editField,
getStaticTableData,
} = data

Expand All @@ -759,6 +761,8 @@
addItemButtonText,
saveItemButtonText,
removeButtonTooltipText,
editButtonTooltipText,
editField,
getStaticTableData,
}
}
Expand Down
5 changes: 5 additions & 0 deletions libs/application/core/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ export const coreMessages = defineMessages({
defaultMessage: 'Eyða færslu',
description: 'Delete field text',
},
editFieldText: {
id: 'application.system:core.edit.field.text',
defaultMessage: 'Breyta færslu',
description: 'Edit field text',
},
deleteApplicationDialogTitle: {
id: 'application.system:delete.application.dialog.title',
defaultMessage: 'Eyða umsókn',
Expand Down
2 changes: 2 additions & 0 deletions libs/application/types/src/lib/Fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
suffix?: string
rows?: number
required?: boolean
onChange?: (...event: any[]) => void

Check warning on line 320 in libs/application/types/src/lib/Fields.ts

View workflow job for this annotation

GitHub Actions / linting (application-templates-university,application-testing,application-types,application-ui-co...

Unexpected any. Specify a different type
}

export interface PhoneField extends BaseField {
Expand All @@ -331,7 +331,7 @@
allowedCountryCodes?: string[]
disableDropdown?: boolean
required?: boolean
onChange?: (...event: any[]) => void

Check warning on line 334 in libs/application/types/src/lib/Fields.ts

View workflow job for this annotation

GitHub Actions / linting (application-templates-university,application-testing,application-types,application-ui-co...

Unexpected any. Specify a different type
}

export interface FileUploadField extends BaseField {
Expand Down Expand Up @@ -500,6 +500,8 @@
saveItemButtonText?: StaticText
getStaticTableData?: (application: Application) => Record<string, string>[]
removeButtonTooltipText?: StaticText
editButtonTooltipText?: StaticText
editField?: boolean
marginTop?: ResponsiveProp<Space>
marginBottom?: ResponsiveProp<Space>
titleVariant?: TitleVariants
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { coreMessages, formatText } from '@island.is/application/core'
import {
FieldBaseProps,
StaticText,
TableRepeaterField,
} from '@island.is/application/types'
import {
Expand Down Expand Up @@ -59,6 +58,8 @@ export const TableRepeaterFormField: FC<Props> = ({
addItemButtonText = coreMessages.buttonAdd,
saveItemButtonText = coreMessages.reviewButtonSubmit,
removeButtonTooltipText = coreMessages.deleteFieldText,
editButtonTooltipText = coreMessages.editFieldText,
editField = false,
} = data

const items = Object.keys(rawItems).map((key) => ({
Expand Down Expand Up @@ -104,6 +105,10 @@ export const TableRepeaterFormField: FC<Props> = ({
remove(index)
}

const handleEditItem = (index: number) => {
setActiveIndex(index)
}

const getFieldError = (id: string) => {
/**
* Errors that occur in a field-array have incorrect typing
Expand Down Expand Up @@ -183,6 +188,28 @@ export const TableRepeaterFormField: FC<Props> = ({
/>
</button>
</Tooltip>
{editField && (
<Tooltip
placement="left"
text={formatText(
editButtonTooltipText,
application,
formatMessage,
)}
>
<button
type="button"
onClick={() => handleEditItem(index)}
>
<Icon
icon="pencil"
color="dark200"
type="outline"
size="small"
/>
</button>
</Tooltip>
)}
karenbjorg marked this conversation as resolved.
Show resolved Hide resolved
</Box>
</T.Data>
{tableRows.map((item, idx) => (
Expand Down
Loading