Skip to content

Commit

Permalink
fix(frontend): Replace white spaces in branch name proposition and al…
Browse files Browse the repository at this point in the history
…low 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 <alice.juan@student-cs.fr>
  • Loading branch information
Piv94165 and alice.juan authored Apr 10, 2024
1 parent 192df9e commit 7170d84
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions taxonomy-editor-frontend/src/pages/startproject/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ import { createBaseURL, toSnakeCase } from "@/utils";

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

function formatDate(date) {
const map = {
mm: ("0" + (date.getMonth() + 1)).slice(-2),
dd: ("0" + date.getDate()).slice(-2),
yy: ("0" + date.getFullYear()).slice(-2),
HH: ("0" + date.getHours()).slice(-2),
MinMin: ("0" + date.getMinutes()).slice(-2),
};

return `${map.mm}${map.dd}${map.yy}_${map.HH}_${map.MinMin}`;
}

export const StartProject = () => {
const [ownerName, setOwnerName] = useState("");
const [taxonomyName, setTaxonomyName] = useState("");
Expand All @@ -32,9 +44,9 @@ export const StartProject = () => {

const findDefaultBranchName = useCallback(() => {
if (taxonomyName === "" || ownerName === "") return "";
return `${toSnakeCase(taxonomyName.toLowerCase())}_${ownerName
.replace(" ", "")
.toLowerCase()}_${Math.floor(Date.now() / 1000)}`;
return `${formatDate(new Date())}_${taxonomyName}_${ownerName}`
.replace(/[\s-]+/g, "_")
.toLowerCase();
}, [ownerName, taxonomyName]);

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

const isOwnerNameInvalid = (name: string) => {
if (name === "") return false;
const pattern = /^[a-zA-Z0-9 _]+$/;
const pattern = /^[a-zA-Z0-9 _-]+$/;
if (!pattern.test(name)) {
return true;
}
Expand Down

0 comments on commit 7170d84

Please sign in to comment.