Skip to content

Commit

Permalink
feat: set the user namespace as the default when creating a new proje…
Browse files Browse the repository at this point in the history
…ct in Renku 2.0 (#3264)


fix #3285
  • Loading branch information
andre-code authored Aug 27, 2024
1 parent 91db782 commit 081a03c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
36 changes: 25 additions & 11 deletions client/src/features/projectsV2/fields/ProjectNamespaceFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,32 @@

import cx from "classnames";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Button, FormText, Label, UncontrolledTooltip } from "reactstrap";
import { ArrowRepeat, ChevronDown, ThreeDots } from "react-bootstrap-icons";
import type { FieldValues } from "react-hook-form";
import { Controller } from "react-hook-form";
import Select, {
ClassNamesConfig,
components,
GroupBase,
MenuListProps,
OptionProps,
SelectComponentsConfig,
SingleValue,
SingleValueProps,
components,
} from "react-select";

import { Button, FormText, Label, UncontrolledTooltip } from "reactstrap";
import { ErrorAlert } from "../../../components/Alert";
import { Loader } from "../../../components/Loader";
import useAppDispatch from "../../../utils/customHooks/useAppDispatch.hook";
import type { PaginatedState } from "../../session/components/options/fetchMore.types";
import type { GetNamespacesApiResponse } from "../api/projectV2.enhanced-api";
import {
projectV2Api,
useGetNamespacesQuery,
useLazyGetNamespacesQuery,
} from "../api/projectV2.enhanced-api";

import type { GenericFormFieldProps } from "./formField.types";
import styles from "./ProjectNamespaceFormField.module.scss";
import { useDispatch } from "react-redux";

type ResponseNamespaces = GetNamespacesApiResponse["namespaces"];
type ResponseNamespace = ResponseNamespaces[number];
Expand Down Expand Up @@ -206,7 +204,7 @@ export default function ProjectNamespaceFormField<T extends FieldValues>({
name,
}: GenericFormFieldProps<T>) {
// Handle forced refresh
const dispatch = useDispatch();
const dispatch = useAppDispatch();
const refetch = useCallback(() => {
dispatch(projectV2Api.util.invalidateTags(["Namespace"]));
}, [dispatch]);
Expand Down Expand Up @@ -292,6 +290,18 @@ function ProjectNamespaceControl(props: ProjectNamespaceControlProps) {
}));
}, [namespacesFirstPage?.perPage, fetchNamespacesPage, fetchedPages]);

useEffect(() => {
if (namespacesFirstPage == null) {
return;
}
const userNamespace = namespacesFirstPage.namespaces.find(
(namespace) => namespace.namespace_kind === "user"
);
if (userNamespace != null && !value) {
onChange(userNamespace);
}
}, [onChange, namespacesFirstPage, value]);

useEffect(() => {
if (namespacesFirstPage == null) {
return;
Expand All @@ -302,7 +312,6 @@ function ProjectNamespaceControl(props: ProjectNamespaceControlProps) {
hasMore: namespacesFirstPage.totalPages > namespacesFirstPage.page,
currentRequestId: "",
});
``;
}, [namespacesFirstPage, requestId]);

useEffect(() => {
Expand All @@ -313,12 +322,17 @@ function ProjectNamespaceControl(props: ProjectNamespaceControlProps) {
) {
return;
}
const hasMore =
namespacesPageResult.currentData.totalPages >
namespacesPageResult.currentData.page;
const namespacesAvailable = [
...allNamespaces,
...namespacesPageResult.currentData.namespaces,
];
setState({
data: [...allNamespaces, ...namespacesPageResult.currentData.namespaces],
data: namespacesAvailable,
fetchedPages: namespacesPageResult.currentData.page ?? 0,
hasMore:
namespacesPageResult.currentData.totalPages >
namespacesPageResult.currentData.page,
hasMore,
currentRequestId: "",
});
}, [
Expand Down
1 change: 0 additions & 1 deletion tests/cypress/e2e/projectV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ describe("Add new v2 project", () => {
cy.contains(
"Please provide a slug consisting of lowercase letters, numbers, and hyphens."
).should("be.visible");
cy.contains("A project must belong to a namespace.").should("be.visible");
cy.getDataCy("project-slug-input").clear().type(slug);
cy.wait("@listNamespaceV2");
cy.findReactSelectOptions("project-namespace-input", "namespace-select")
Expand Down

0 comments on commit 081a03c

Please sign in to comment.