You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by li...@apache.org on 2023/02/28 08:03:41 UTC

[incubator-devlake] branch main updated: fix(config-ui): limit the type of project name (#4540)

This is an automated email from the ASF dual-hosted git repository.

likyh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 6dd8715ef fix(config-ui): limit the type of project name (#4540)
6dd8715ef is described below

commit 6dd8715ef51dc4efd4be646d238dc6a9b82138e2
Author: 青湛 <0x...@gmail.com>
AuthorDate: Tue Feb 28 16:03:37 2023 +0800

    fix(config-ui): limit the type of project name (#4540)
---
 config-ui/src/pages/project/detail/panel/settings.tsx | 2 +-
 config-ui/src/pages/project/detail/use-project.ts     | 6 ++++++
 config-ui/src/pages/project/home/use-project.ts       | 6 ++++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/config-ui/src/pages/project/detail/panel/settings.tsx b/config-ui/src/pages/project/detail/panel/settings.tsx
index daad295d0..f22045507 100644
--- a/config-ui/src/pages/project/detail/panel/settings.tsx
+++ b/config-ui/src/pages/project/detail/panel/settings.tsx
@@ -59,7 +59,7 @@ export const SettingsPanel = ({ project, onUpdate }: Props) => {
           <p>DORA metrics are four widely-adopted metrics for measuring software delivery performance.</p>
         </div>
         <ButtonGroup>
-          <Button text="Save" intent={Intent.PRIMARY} onClick={handleSave} />
+          <Button text="Save" disabled={!name} intent={Intent.PRIMARY} onClick={handleSave} />
         </ButtonGroup>
       </S.Settings>
     </Card>
diff --git a/config-ui/src/pages/project/detail/use-project.ts b/config-ui/src/pages/project/detail/use-project.ts
index 7e396c662..c8e7014fa 100644
--- a/config-ui/src/pages/project/detail/use-project.ts
+++ b/config-ui/src/pages/project/detail/use-project.ts
@@ -19,6 +19,7 @@
 import { useState, useEffect, useMemo } from 'react';
 import { useHistory } from 'react-router-dom';
 
+import { toast } from '@/components';
 import type { WebhookItemType } from '@/plugins/register/webook';
 import { operator } from '@/utils';
 
@@ -54,6 +55,11 @@ export const useProject = (name: string) => {
   }, []);
 
   const handleUpdate = async (newName: string, enableDora: boolean) => {
+    if (!/^\w+$/.test(newName)) {
+      toast.error('Please enter alphanumeric or underscore');
+      return;
+    }
+
     const payload = {
       name: newName,
       description: '',
diff --git a/config-ui/src/pages/project/home/use-project.ts b/config-ui/src/pages/project/home/use-project.ts
index f54f15095..17245fa0d 100644
--- a/config-ui/src/pages/project/home/use-project.ts
+++ b/config-ui/src/pages/project/home/use-project.ts
@@ -18,6 +18,7 @@
 
 import { useState, useEffect, useMemo } from 'react';
 
+import { toast } from '@/components';
 import { operator } from '@/utils';
 
 import * as API from './api';
@@ -52,6 +53,11 @@ export const useProject = <T>({ name, enableDora, onHideDialog }: Props) => {
   }, []);
 
   const handleSave = async () => {
+    if (!/^\w+$/.test(name)) {
+      toast.error('Please enter alphanumeric or underscore');
+      return;
+    }
+
     const payload = {
       name,
       description: '',