-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add data service endpointDescriptions to endpoint section
- Loading branch information
1 parent
97074f3
commit e79230b
Showing
10 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
28 changes: 0 additions & 28 deletions
28
...ce-catalog/components/data-service-form/components/data-service-form-endpoint-section.tsx
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
apps/data-service-catalog/components/data-service-form/components/endpoint-section.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,71 @@ | ||
import { DataService } from '@catalog-frontend/types'; | ||
import { AddButton, LabelWithHelpTextAndTag } from '@catalog-frontend/ui'; | ||
import { localization } from '@catalog-frontend/utils'; | ||
import { Textfield } from '@digdir/designsystemet-react'; | ||
import { FastField, FieldArray, useFormikContext } from 'formik'; | ||
import FieldsetWithDelete from '../../fieldset-with-delete'; | ||
import styles from './endpoint.module.css'; | ||
|
||
export const EndpointSection = () => { | ||
const errors = useFormikContext<DataService>()?.errors; | ||
return ( | ||
<> | ||
<FastField | ||
name='endpointUrl' | ||
as={Textfield} | ||
size='sm' | ||
label={ | ||
<LabelWithHelpTextAndTag | ||
tagTitle={localization.tag.required} | ||
helpText={localization.dataServiceForm.helptext.endpoint} | ||
helpAriaLabel={localization.dataServiceForm.fieldLabel.endpoint} | ||
> | ||
{localization.dataServiceForm.fieldLabel.endpoint} | ||
</LabelWithHelpTextAndTag> | ||
} | ||
error={errors?.endpointUrl} | ||
/> | ||
|
||
<div> | ||
<FieldArray name='endpointDescriptions'> | ||
{(arrayHelpers) => ( | ||
<> | ||
{arrayHelpers.form.values.endpointDescriptions && | ||
arrayHelpers.form.values.endpointDescriptions.map((_, index: number) => ( | ||
<div | ||
key={`endpointDescriptions-${index}`} | ||
className={styles.padding} | ||
> | ||
<FieldsetWithDelete onDelete={() => arrayHelpers.remove(index)}> | ||
<FastField | ||
name={`endpointDescriptions[${index}]`} | ||
label={ | ||
index < 1 ? ( | ||
<LabelWithHelpTextAndTag | ||
helpAriaLabel={localization.dataServiceForm.fieldLabel.endpointDescriptions} | ||
helpText={localization.dataServiceForm.helptext.endpointDescriptions} | ||
> | ||
{localization.dataServiceForm.fieldLabel.endpointDescriptions} | ||
</LabelWithHelpTextAndTag> | ||
) : ( | ||
'' | ||
) | ||
} | ||
as={Textfield} | ||
size='sm' | ||
error={errors?.endpointDescriptions?.[index]} | ||
/> | ||
</FieldsetWithDelete> | ||
</div> | ||
))} | ||
|
||
<AddButton onClick={() => arrayHelpers.push('')}> | ||
{`${localization.dataServiceForm.fieldLabel.endpointDescriptions}`} | ||
</AddButton> | ||
</> | ||
)} | ||
</FieldArray> | ||
</div> | ||
</> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
apps/data-service-catalog/components/data-service-form/components/endpoint.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,3 @@ | ||
.padding { | ||
padding-bottom: 0.5rem; | ||
} |
File renamed without changes.
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
20 changes: 20 additions & 0 deletions
20
apps/data-service-catalog/components/fieldset-with-delete/fieldset-with-delete.module.scss
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,20 @@ | ||
.content { | ||
display: flex; | ||
align-items: flex-end; | ||
} | ||
|
||
.singleChild { | ||
width: 100%; | ||
} | ||
|
||
.twoChildren { | ||
display: grid; | ||
grid-template-columns: 49% 49%; | ||
gap: 2%; | ||
width: 100%; | ||
} | ||
|
||
.deleteButton { | ||
height: fit-content; | ||
width: fit-content; | ||
} |
23 changes: 23 additions & 0 deletions
23
apps/data-service-catalog/components/fieldset-with-delete/index.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,23 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
import { DeleteButton } from '@catalog-frontend/ui'; | ||
import styles from './fieldset-with-delete.module.scss'; | ||
|
||
type Props = { | ||
onDelete: () => void; | ||
} & PropsWithChildren; | ||
|
||
export const FieldsetWithDelete = ({ children, onDelete }: Props) => { | ||
const childArray = React.Children.toArray(children).filter(Boolean); | ||
|
||
return ( | ||
<div className={styles.content}> | ||
<div className={childArray.length === 1 ? styles.singleChild : styles.twoChildren}>{children}</div> | ||
<DeleteButton | ||
className={styles.deleteButton} | ||
onClick={onDelete} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FieldsetWithDelete; |
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