Skip to content

Commit 7170d84

Browse files
Piv94165alice.juan
and
alice.juan
authored
fix(frontend): Replace white spaces in branch name proposition and allow dashes in owner name (#466)
* fix(frontend): Replace white spaces in branch name proposition * fix(frontend): Allow dashes in owner names to support GitHub usernames * refactor(frontend): remove useless comments * fix checks tests * feat(frontend): readable date in branch name proposition * lint * feat(frontend): Implement constant date formatting * lint --------- Co-authored-by: alice.juan <[email protected]>
1 parent 192df9e commit 7170d84

File tree

1 file changed

+16
-4
lines changed
  • taxonomy-editor-frontend/src/pages/startproject

1 file changed

+16
-4
lines changed

taxonomy-editor-frontend/src/pages/startproject/index.tsx

+16-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ import { createBaseURL, toSnakeCase } from "@/utils";
2222

2323
const branchNameRegEx = /[^a-z0-9_]+/;
2424

25+
function formatDate(date) {
26+
const map = {
27+
mm: ("0" + (date.getMonth() + 1)).slice(-2),
28+
dd: ("0" + date.getDate()).slice(-2),
29+
yy: ("0" + date.getFullYear()).slice(-2),
30+
HH: ("0" + date.getHours()).slice(-2),
31+
MinMin: ("0" + date.getMinutes()).slice(-2),
32+
};
33+
34+
return `${map.mm}${map.dd}${map.yy}_${map.HH}_${map.MinMin}`;
35+
}
36+
2537
export const StartProject = () => {
2638
const [ownerName, setOwnerName] = useState("");
2739
const [taxonomyName, setTaxonomyName] = useState("");
@@ -32,9 +44,9 @@ export const StartProject = () => {
3244

3345
const findDefaultBranchName = useCallback(() => {
3446
if (taxonomyName === "" || ownerName === "") return "";
35-
return `${toSnakeCase(taxonomyName.toLowerCase())}_${ownerName
36-
.replace(" ", "")
37-
.toLowerCase()}_${Math.floor(Date.now() / 1000)}`;
47+
return `${formatDate(new Date())}_${taxonomyName}_${ownerName}`
48+
.replace(/[\s-]+/g, "_")
49+
.toLowerCase();
3850
}, [ownerName, taxonomyName]);
3951

4052
const [branchName, setBranchName] = useState(findDefaultBranchName());
@@ -78,7 +90,7 @@ export const StartProject = () => {
7890

7991
const isOwnerNameInvalid = (name: string) => {
8092
if (name === "") return false;
81-
const pattern = /^[a-zA-Z0-9 _]+$/;
93+
const pattern = /^[a-zA-Z0-9 _-]+$/;
8294
if (!pattern.test(name)) {
8395
return true;
8496
}

0 commit comments

Comments
 (0)