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

10767 fix form validation of version control #11871

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
gap: 1rem;
}

.createReleaseInvalidTagName {
background-color: #fbf6bd;
padding: 1.2rem;
padding: 1.2rem 0 1.2rem 0;
}

.releaseVersionInput {
width: 50%;
margin-bottom: 8px;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useState } from 'react';
import classes from './createAppReleaseComponent.module.css';
import type { ChangeEvent } from 'react';
import { LegacyTextField, Button, LegacyTextArea } from '@digdir/design-system-react';
import { Button, Textfield, Textarea } from '@digdir/design-system-react';
import { versionNameValid } from './utils';
import { useBranchStatusQuery, useAppReleasesQuery } from '../../../hooks/queries';
import { useCreateReleaseMutation } from '../../../hooks/mutations';
import { useTranslation } from 'react-i18next';
import { useStudioUrlParams } from 'app-shared/hooks/useStudioUrlParams';
import { FormField } from '../../../../packages/shared/src/components/FormField/FormField';

export function CreateReleaseComponent() {
const { org, app } = useStudioUrlParams();
Expand Down Expand Up @@ -37,27 +38,40 @@ export function CreateReleaseComponent() {

return (
<div className={classes.createReleaseForm}>
{!versionNameValid(releases, tagName) ? (
<div className={classes.createReleaseInvalidTagName}>
{t('app_create_release.release_versionnumber_validation')}
</div>
) : null}
<div className={classes.releaseVersionInput}>
<LegacyTextField
label={t('app_create_release.release_versionnumber')}
onChange={handleTagNameChange}
value={tagName}
isValid={versionNameValid(releases, tagName)}
/>
</div>
<div>
<LegacyTextArea
label={t('app_create_release.release_description')}
value={body}
onChange={handleBodyChange}
rows={4}
/>
</div>
<FormField
value={tagName}
customValidationRules={(value: string) => {
const trimmedValue = value.trim().toLowerCase();
if (releases.some((release) => release.tagName.toLowerCase() === trimmedValue)) {
return t('app_create_release.release_versionnumber_already_exists');
}
return versionNameValid(releases, trimmedValue)
? ''
: t('app_create_release.release_versionnumber_validation');
}}
customValidationMessages={(errorCode) => errorCode}
renderField={({ fieldProps }) => (
<div className={classes.releaseVersionInput}>
<Textfield
{...fieldProps}
label={t('app_create_release.release_versionnumber')}
onChange={handleTagNameChange}
/>
</div>
)}
/>
<FormField
value={body}
renderField={({ fieldProps }) => (
<Textarea
{...fieldProps}
label={t('app_create_release.release_description')}
value={body}
onChange={handleBodyChange}
rows={4}
/>
)}
/>
<div>
<Button
onClick={handleBuildVersionClick}
Expand Down
1 change: 1 addition & 0 deletions frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"app_create_release.release_creating": "Bygger en ny versjon av applikasjonen, startet av",
"app_create_release.release_description": "Beskriv innholdet i versjonen",
"app_create_release.release_versionnumber": "Versjonsnummer",
"app_create_release.release_versionnumber_already_exists": "Et versjonnummer med det navnet finnes allerede.",
"app_create_release.release_versionnumber_validation": "Må være en unik kombinasjon av tall, små bokstaver (a-z) og spesialtegnene \".\" og \"-\". Maks 128 tegn.",
"app_create_release.still_building_release": "Bygger fortsatt versjon {{version}}",
"app_create_release_errors.build_cannot_be_saved": "Huff da, vi opplever en teknisk feil som fører til at applikasjonen ikke blir bygget. Forsøk å laste siden på nytt (f5). Dersom problemet vedvarer, kontakt",
Expand Down
Loading