Răsfoiți Sursa

Merge branch 'gitlab-integration' of github.com:porter-dev/porter into dev

jnfrati 4 ani în urmă
părinte
comite
fd18bc5fa8

+ 4 - 1
dashboard/src/components/repo-selector/BranchList.tsx

@@ -24,8 +24,11 @@ const BranchList: React.FC<Props> = ({ setBranch, actionConfig }) => {
 
 
   useEffect(() => {
   useEffect(() => {
     // Get branches
     // Get branches
+    if (!actionConfig) {
+      return () => {};
+    }
 
 
-    if (actionConfig.git_repo_id !== 0) {
+    if (actionConfig?.kind === "github") {
       api
       api
         .getBranches(
         .getBranches(
           "<token>",
           "<token>",

+ 54 - 89
dashboard/src/components/repo-selector/RepoList.tsx

@@ -8,16 +8,7 @@ import { Context } from "shared/Context";
 
 
 import Loading from "../Loading";
 import Loading from "../Loading";
 import SearchBar from "../SearchBar";
 import SearchBar from "../SearchBar";
-import OptionsDropdown from "components/OptionsDropdown";
-import { SelectField } from "material-ui";
-import SelectRow from "components/form-components/SelectRow";
-import SearchSelector from "components/SearchSelector";
-
-interface GithubAppAccessData {
-  has_access: boolean;
-  username?: string;
-  accounts?: string[];
-}
+import DynamicLink from "components/DynamicLink";
 
 
 type Props = {
 type Props = {
   actionConfig: ActionConfigType | null;
   actionConfig: ActionConfigType | null;
@@ -41,72 +32,8 @@ const RepoList: React.FC<Props> = ({
   const [selectedRepo, setSelectedRepo] = useState(null);
   const [selectedRepo, setSelectedRepo] = useState(null);
   const [repoError, setRepoError] = useState(false);
   const [repoError, setRepoError] = useState(false);
   const [searchFilter, setSearchFilter] = useState(null);
   const [searchFilter, setSearchFilter] = useState(null);
-  const { currentProject } = useContext(Context);
-
-  // const loadData = async () => {
-  //   try {
-  //     const { data } = await api.getGithubAccounts("<token>", {}, {});
-
-  //     setAccessData(data);
-  //     setAccessLoading(false);
-  //   } catch (error) {
-  //     setAccessError(true);
-  //     setAccessLoading(false);
-  //   }
-
-  //   let ids: number[] = [];
-
-  //   if (!userId && userId !== 0) {
-  //     ids = await api
-  //       .getGitRepos("token", {}, { project_id: currentProject.id })
-  //       .then((res) => res.data);
-  //   } else {
-  //     setRepoLoading(false);
-  //     setRepoError(true);
-  //     return;
-  //   }
-
-  //   const repoListPromises = ids.map((id) =>
-  //     api.getGitRepoList(
-  //       "<token>",
-  //       {},
-  //       { project_id: currentProject.id, git_repo_id: id }
-  //     )
-  //   );
-
-  //   try {
-  //     const resolvedRepoList = await Promise.allSettled(repoListPromises);
-
-  //     const repos: RepoType[][] = resolvedRepoList.map((repo) =>
-  //       repo.status === "fulfilled" ? repo.value.data : []
-  //     );
-
-  //     const names = new Set();
-  //     // note: would be better to use .flat() here but you need es2019 for
-  //     setRepos(
-  //       repos
-  //         .map((arr, idx) =>
-  //           arr.map((el) => {
-  //             el.GHRepoID = ids[idx];
-  //             return el;
-  //           })
-  //         )
-  //         .reduce((acc, val) => acc.concat(val), [])
-  //         .reduce((acc, val) => {
-  //           if (!names.has(val.FullName)) {
-  //             names.add(val.FullName);
-  //             return acc.concat(val);
-  //           } else {
-  //             return acc;
-  //           }
-  //         }, [])
-  //     );
-  //     setRepoLoading(false);
-  //   } catch (err) {
-  //     setRepoLoading(false);
-  //     setRepoError(true);
-  //   }
-  // };
+  const [hasProviders, setHasProviders] = useState(true);
+  const { currentProject, setCurrentError } = useContext(Context);
 
 
   useEffect(() => {
   useEffect(() => {
     let isSubscribed = true;
     let isSubscribed = true;
@@ -114,11 +41,21 @@ const RepoList: React.FC<Props> = ({
       .getGitProviders("<token>", {}, { project_id: currentProject.id })
       .getGitProviders("<token>", {}, { project_id: currentProject.id })
       .then((res) => {
       .then((res) => {
         const data = res.data;
         const data = res.data;
-        if (isSubscribed) {
-          setProviders(data);
+        if (!isSubscribed) {
+          return;
+        }
 
 
-          setCurrentProvider(data[0]);
+        if (!Array.isArray(data)) {
+          setHasProviders(false);
+          return;
         }
         }
+
+        setProviders(data);
+        setCurrentProvider(data[0]);
+      })
+      .catch((err) => {
+        setHasProviders(false);
+        setCurrentError(err);
       });
       });
 
 
     return () => {
     return () => {
@@ -186,11 +123,6 @@ const RepoList: React.FC<Props> = ({
       });
       });
   }, [currentProvider]);
   }, [currentProvider]);
 
 
-  // TODO: Try to unhook before unmount
-  // useEffect(() => {
-  //   loadData();
-  // }, []);
-
   // clear out actionConfig and SelectedRepository if new search is performed
   // clear out actionConfig and SelectedRepository if new search is performed
   useEffect(() => {
   useEffect(() => {
     setActionConfig({
     setActionConfig({
@@ -243,8 +175,7 @@ const RepoList: React.FC<Props> = ({
           <LoadingWrapper>
           <LoadingWrapper>
             We couldn't reach gitlab to get your repos. You can
             We couldn't reach gitlab to get your repos. You can
             <A
             <A
-              style={{ marginRight: "5px" }}
-              href={`/api/projects/${currentProject.id}/oauth/gitlab?integration_id=${currentProvider.integration_id}`}
+              to={`/api/projects/${currentProject.id}/oauth/gitlab?integration_id=${currentProvider.integration_id}`}
             >
             >
               Connect your gitlab account to porter
               Connect your gitlab account to porter
             </A>
             </A>
@@ -255,10 +186,10 @@ const RepoList: React.FC<Props> = ({
         return (
         return (
           <LoadingWrapper>
           <LoadingWrapper>
             No connected Github repos found. You can
             No connected Github repos found. You can
-            <A href={"/api/integrations/github-app/install"}>
+            <A to={"/api/integrations/github-app/install"}>
               Install Porter in more repositories
               Install Porter in more repositories
             </A>
             </A>
-            .
+            or select another git provider.
           </LoadingWrapper>
           </LoadingWrapper>
         );
         );
       }
       }
@@ -330,6 +261,39 @@ const RepoList: React.FC<Props> = ({
     }
     }
   };
   };
 
 
+  if (!hasProviders) {
+    return (
+      <>
+        <RepoListWrapper>
+          <ExpandedWrapper>
+            <LoadingWrapper>
+              <div
+                style={{
+                  display: "flex",
+                  flexDirection: "column",
+                  alignItems: "center",
+                  justifyContent: "center",
+                }}
+              >
+                <div>We couldn't find any git provider to connect with.</div>
+                <div>
+                  You can
+                  <A to={"/api/integrations/github-app/install"}>
+                    Add Github repositories
+                  </A>
+                  or
+                  <A to={"/integrations"}>
+                    Add a Gitlab instance to your project
+                  </A>
+                </div>
+              </div>
+            </LoadingWrapper>
+          </ExpandedWrapper>
+        </RepoListWrapper>
+      </>
+    );
+  }
+
   return <>{renderExpanded()}</>;
   return <>{renderExpanded()}</>;
 };
 };
 
 
@@ -499,10 +463,11 @@ const ExpandedWrapperAlt = styled(ExpandedWrapper)`
   overflow-y: auto;
   overflow-y: auto;
 `;
 `;
 
 
-const A = styled.a`
+const A = styled(DynamicLink)`
   color: #8590ff;
   color: #8590ff;
   text-decoration: underline;
   text-decoration: underline;
   margin-left: 5px;
   margin-left: 5px;
+  margin-right: 5px;
 
 
   cursor: pointer;
   cursor: pointer;
 `;
 `;

+ 0 - 44
dashboard/src/main/home/integrations/GitlabIntegrationList.tsx

@@ -11,46 +11,11 @@ interface Props {
 }
 }
 
 
 const GitlabIntegrationList: React.FC<Props> = (props) => {
 const GitlabIntegrationList: React.FC<Props> = (props) => {
-  const [isDelete, setIsDelete] = useState(false);
-  const [deleteIndex, setDeleteIndex] = useState(-1); // guaranteed to be set when used
-  const { currentProject, setCurrentError } = useContext(Context);
-  const deleted = useRef(new Set());
-
-  const handleDelete = () => {
-    alert("NOT IMPLEMENTED");
-    // api
-    //   .deleteSlackIntegration(
-    //     "<token>",
-    //     {},
-    //     {
-    //       project_id: currentProject.id,
-    //       slack_integration_id: props.gitlabData[deleteIndex].id,
-    //     }
-    //   )
-    //   .then(() => {
-    //     deleted.current.add(deleteIndex);
-    //     setIsDelete(false);
-    //   })
-    //   .catch((err) => {
-    //     setCurrentError(err);
-    //   });
-  };
-
   return (
   return (
     <>
     <>
-      <ConfirmOverlay
-        show={isDelete}
-        message={
-          deleteIndex != -1 &&
-          `Are you sure you want to delete the gitlab instance ${props.gitlabData[deleteIndex].instance_url}?`
-        }
-        onYes={handleDelete}
-        onNo={() => setIsDelete(false)}
-      />
       <StyledIntegrationList>
       <StyledIntegrationList>
         {props.gitlabData?.length > 0 ? (
         {props.gitlabData?.length > 0 ? (
           props.gitlabData.map((inst, idx) => {
           props.gitlabData.map((inst, idx) => {
-            if (deleted.current.has(idx)) return null;
             return (
             return (
               <Integration
               <Integration
                 onClick={() => {}}
                 onClick={() => {}}
@@ -63,15 +28,6 @@ const GitlabIntegrationList: React.FC<Props> = (props) => {
                     <Label>{inst.instance_url}</Label>
                     <Label>{inst.instance_url}</Label>
                   </Flex>
                   </Flex>
                   <MaterialIconTray disabled={false}>
                   <MaterialIconTray disabled={false}>
-                    <i
-                      className="material-icons"
-                      onClick={() => {
-                        setDeleteIndex(idx);
-                        setIsDelete(true);
-                      }}
-                    >
-                      delete
-                    </i>
                     <i
                     <i
                       className="material-icons"
                       className="material-icons"
                       onClick={() => {
                       onClick={() => {