Skip to content

Commit ff5db9b

Browse files
committed
feat: branch name rules and router for names containing slash character
1 parent e34ae97 commit ff5db9b

File tree

6 files changed

+69
-29
lines changed

6 files changed

+69
-29
lines changed

ee/backend/app/src/main/kotlin/io/tolgee/ee/api/v2/hateoas/model/branching/CreateBranchModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package io.tolgee.ee.api.v2.hateoas.model.branching
22

33
import io.swagger.v3.oas.annotations.media.Schema
44
import jakarta.validation.constraints.Pattern
5+
import org.hibernate.validator.constraints.Length
56
import org.springframework.hateoas.RepresentationModel
67

78
@Suppress("unused")
89
open class CreateBranchModel(
910
@Schema(description = "Branch name, example = feature/new-feature")
10-
@field:Pattern(regexp = "^[a-z0-9]([a-z0-9-_]*[a-z0-9])?$", message = "invalid_pattern")
11+
@field:Pattern(regexp = "^[a-z0-9]([a-z0-9-_/]*[a-z0-9])?$", message = "invalid_pattern")
12+
@field:Length(min = 2, max = 100, message = "max_length")
1113
val name: String,
1214
@Schema(description = "Origin branch id")
1315
val originBranchId: Long,
14-
) : RepresentationModel<CreateBranchModel>()
16+
) : RepresentationModel<CreateBranchModel>()

webapp/src/constants/GlobalValidationSchema.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,10 @@ export class Validation {
526526
Yup.object().shape({
527527
name: Yup.string()
528528
.required()
529-
.min(3)
529+
.min(2)
530530
.max(100)
531531
.matches(
532-
/^[a-z0-9]([a-z0-9-_]*[a-z0-9])?$/i,
532+
/^[a-z0-9]([a-z0-9-_/]*[a-z0-9])?$/i,
533533
t('validation_invalid_branch_name')
534534
),
535535
});

webapp/src/constants/links.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ export class LINKS {
350350
static PROJECT_ADD = Link.ofParent(LINKS.PROJECTS, 'add');
351351

352352
static PROJECT_TRANSLATIONS = Link.ofParent(LINKS.PROJECT, 'translations');
353+
static PROJECT_TRANSLATIONS_BRANCHED_VIEW = Link.ofParent(
354+
LINKS.PROJECT_TRANSLATIONS,
355+
'tree/' + p(PARAMS.TRANSLATIONS_BRANCH) + '*'
356+
);
357+
353358
static PROJECT_TRANSLATIONS_BRANCHED = Link.ofParent(
354359
LINKS.PROJECT_TRANSLATIONS,
355360
'tree/' + p(PARAMS.TRANSLATIONS_BRANCH)

webapp/src/ee/branching/BranchMergeDetailView.tsx

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -401,29 +401,41 @@ export const BranchMergeDetailView: React.FC = () => {
401401
)}
402402
</Typography>
403403
<Box display="flex" alignItems="center">
404-
<SuccessChip
405-
icon={<CheckCircle width={18} height={18} />}
406-
label={<T keyName={'branch_merges_merged_button'} />}
407-
/>
408-
{merge && merge?.mergedAt == null && (
404+
{merge && merge.mergedAt && (
405+
<SuccessChip
406+
icon={<CheckCircle width={18} height={18} />}
407+
label={<T keyName={'branch_merges_merged_button'} />}
408+
/>
409+
)}
410+
{merge && (
409411
<>
410-
<IconButton
411-
onClick={handleOpen}
412-
data-cy="project-dashboard-language-menu"
413-
>
414-
<DotsVertical />
415-
</IconButton>
416-
<Menu
417-
anchorEl={anchorEl}
418-
open={Boolean(anchorEl)}
419-
onClose={closeWith()}
420-
>
421-
<MenuItem onClick={closeWith(handleCancel)}>
422-
<Typography color={(theme) => theme.palette.error.main}>
423-
<T keyName="branch_merge_delete_button" />
424-
</Typography>
425-
</MenuItem>
426-
</Menu>
412+
<>
413+
{merge.mergedAt && (
414+
<SuccessChip
415+
icon={<CheckCircle width={18} height={18} />}
416+
label={<T keyName={'branch_merges_merged_button'} />}
417+
/>
418+
)}
419+
</>
420+
<>
421+
<IconButton
422+
onClick={handleOpen}
423+
data-cy="project-dashboard-language-menu"
424+
>
425+
<DotsVertical />
426+
</IconButton>
427+
<Menu
428+
anchorEl={anchorEl}
429+
open={Boolean(anchorEl)}
430+
onClose={closeWith()}
431+
>
432+
<MenuItem onClick={closeWith(handleCancel)}>
433+
<Typography color={(theme) => theme.palette.error.main}>
434+
<T keyName="branch_merge_delete_button" />
435+
</Typography>
436+
</MenuItem>
437+
</Menu>
438+
</>
427439
</>
428440
)}
429441
</Box>

webapp/src/ee/branching/components/BranchForm.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { StandardForm } from 'tg.component/common/form/StandardForm';
22
import { components } from 'tg.service/apiSchema.generated';
33
import React, { FC } from 'react';
4-
import { Box } from '@mui/material';
4+
import { Box, styled } from '@mui/material';
55
import { TextField } from 'tg.component/common/form/fields/TextField';
66
import { FieldLabel } from 'tg.component/FormField';
77
import { T, useTranslate } from '@tolgee/react';
88
import { Validation } from 'tg.constants/GlobalValidationSchema';
99
import { BranchSelectField } from 'tg.component/branching/BranchSelectField';
10+
import { LabelHint } from 'tg.component/common/LabelHint';
1011

1112
type BranchModel = components['schemas']['BranchModel'];
1213

@@ -15,6 +16,13 @@ export type BranchFormValues = {
1516
originBranchId: number;
1617
};
1718

19+
const StyledHint = styled(Box)`
20+
ul {
21+
margin: 0;
22+
padding-left: 16px;
23+
}
24+
`;
25+
1826
export const BranchForm: FC<{
1927
branch?: BranchModel;
2028
defaultBranch?: BranchModel;
@@ -44,7 +52,20 @@ export const BranchForm: FC<{
4452
<Box display="flex" mb={2}>
4553
<Box display="grid" flexGrow={1}>
4654
<FieldLabel>
47-
<T keyName="project_branch_name" />
55+
<Box display="flex" alignItems="center" gap={1}>
56+
<LabelHint
57+
title={
58+
<StyledHint>
59+
<T
60+
keyName="branch_name_rules"
61+
params={{ ul: <ul />, li: <li /> }}
62+
/>
63+
</StyledHint>
64+
}
65+
>
66+
<T keyName="project_branch_name" />
67+
</LabelHint>
68+
</Box>
4869
</FieldLabel>
4970
<TextField size="small" name="name" required={true} />
5071
</Box>

webapp/src/views/projects/ProjectRouter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const ProjectRouter = () => {
4343
<TranslationsView />
4444
</Route>
4545

46-
<Route exact path={LINKS.PROJECT_TRANSLATIONS_BRANCHED.template}>
46+
<Route exact path={LINKS.PROJECT_TRANSLATIONS_BRANCHED_VIEW.template}>
4747
<TranslationsView />
4848
</Route>
4949

0 commit comments

Comments
 (0)