Skip to content

Commit

Permalink
feat: create data connector in project (#3525)
Browse files Browse the repository at this point in the history
Co-authored-by: Lorenzo Cavazzi <[email protected]>
  • Loading branch information
olevski and lorenzo-cavazzi authored Feb 19, 2025
1 parent d82fdd4 commit f600423
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ import dataConnectorFormSlice from "../../state/dataConnectors.slice";

import DataConnectorModalResult from "./DataConnectorModalResult";
import DataConnectorSaveCredentialsInfo from "./DataConnectorSaveCredentialsInfo";
import type { Project } from "../../../projectsV2/api/projectV2.api";

interface AddOrEditDataConnectorProps {
storageSecrets: DataConnectorSecret[];
project?: Project;
}

type DataConnectorModalBodyProps = AddOrEditDataConnectorProps;

export default function DataConnectorModalBody({
storageSecrets,
project,
}: DataConnectorModalBodyProps) {
const { flatDataConnector, schemata, success } = useAppSelector(
(state) => state.dataConnectorFormSlice
Expand All @@ -76,13 +79,17 @@ export default function DataConnectorModalBody({
Or, connect to cloud storage to read and write custom data.
</p>
)}
<AddOrEditDataConnector storageSecrets={storageSecrets} />
<AddOrEditDataConnector
storageSecrets={storageSecrets}
project={project}
/>
</>
);
}

function AddOrEditDataConnector({
storageSecrets,
project,
}: AddOrEditDataConnectorProps) {
const { cloudStorageState, flatDataConnector, schemata, validationResult } =
useAppSelector((state) => state.dataConnectorFormSlice);
Expand Down Expand Up @@ -150,7 +157,10 @@ function AddOrEditDataConnector({
setState={setState}
/>
</div>
<DataConnectorContentByStep storageSecrets={storageSecrets} />
<DataConnectorContentByStep
storageSecrets={storageSecrets}
project={project}
/>
</>
);
return <p>Error - not implemented yet</p>;
Expand All @@ -173,7 +183,7 @@ type DataConnectorMountFormFields =
| "mountPoint"
| "readOnly"
| "saveCredentials";
export function DataConnectorMount() {
export function DataConnectorMount({ project }: AddOrEditDataConnectorProps) {
const dispatch = useAppDispatch();
const { cloudStorageState, flatDataConnector, schemata } = useAppSelector(
(state) => state.dataConnectorFormSlice
Expand Down Expand Up @@ -315,6 +325,7 @@ export function DataConnectorMount() {
field.onChange(e);
onFieldValueChange("namespace", e?.slug ?? "");
}}
project={project}
/>
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function DataConnectorModalBodyAndFooter({
if (dataConnector == null) {
flattened = {
...flattened,
namespace,
namespace: project ? `${project.namespace}/${project.slug}` : namespace,
visibility: project?.visibility ?? "private",
};
}
Expand All @@ -91,7 +91,7 @@ export function DataConnectorModalBodyAndFooter({
schemata: schemata ?? [],
})
);
}, [dataConnector, dispatch, namespace, project?.visibility, schemata]);
}, [dataConnector, dispatch, namespace, project, schemata]);

// Visual elements
return (
Expand All @@ -102,7 +102,10 @@ export function DataConnectorModalBodyAndFooter({
) : schemaQueryResult.error ? (
<RtkOrNotebooksError error={schemaQueryResult.error} />
) : (
<DataConnectorModalBody storageSecrets={connectorSecrets ?? []} />
<DataConnectorModalBody
storageSecrets={connectorSecrets ?? []}
project={project}
/>
)}
</ModalBody>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Pagination from "../../../components/Pagination";
import { RtkOrNotebooksError } from "../../../components/errors/RtkErrorAlert";
import useGroupPermissions from "../../groupsV2/utils/useGroupPermissions.hook";
import PermissionsGuard from "../../permissionsV2/PermissionsGuard";
import type { NamespaceKind } from "../../projectsV2/api/namespace.api";
import type { NamespaceKind } from "../../projectsV2/api/namespace.enhanced-api";
import { useGetUserQuery } from "../../usersV2/api/users.api";
import {
useGetDataConnectorsQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface AddOrEditCloudStorageProps {
state: AddCloudStorageState;
storage: CloudStorageDetails;
storageSecrets: CloudStorageSecretGet[];
projectId?: string;
}

export default function AddOrEditCloudStorage({
Expand All @@ -88,6 +89,7 @@ export default function AddOrEditCloudStorage({
setState,
state,
storage,
projectId,
}: AddOrEditCloudStorageProps) {
const ContentByStep =
state.step >= 0 && state.step <= CLOUD_STORAGE_TOTAL_STEPS
Expand All @@ -107,6 +109,7 @@ export default function AddOrEditCloudStorage({
setStorage={setStorage}
storageSecrets={[]}
validationSucceeded={false}
projectId={projectId}
/>
</>
);
Expand Down Expand Up @@ -171,6 +174,7 @@ export interface AddStorageStepProps {
storageSecrets: CloudStorageSecretGet[];
isV2?: boolean;
validationSucceeded: boolean;
projectId?: string;
}

const mapStepToElement: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export default function CloudStorageModal({
storageId={storageId}
success={success}
validationSucceeded={validationSucceeded}
projectId={projectId}
/>
</ModalBody>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface AddCloudStorageBodyContentProps
storageDetails: CloudStorageDetails;
success: boolean;
validationSucceeded: boolean;
projectId?: string;
}
export function AddCloudStorageBodyContent({
addResultStorageName,
Expand All @@ -121,6 +122,7 @@ export function AddCloudStorageBodyContent({
storageDetails,
storageId,
success,
projectId,
}: AddCloudStorageBodyContentProps) {
if (redraw) return <Loader />;
if (success) {
Expand All @@ -140,6 +142,7 @@ export function AddCloudStorageBodyContent({
state={state}
storage={storageDetails}
storageSecrets={[]}
projectId={projectId}
/>
);
}
Expand Down
12 changes: 12 additions & 0 deletions client/src/features/projectsV2/api/namespace.enhanced-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
NamespaceKind as NamespaceKindOrig,
NamespaceResponse as NamespaceResponseOrig,
} from "./namespace.api.ts";

export type NamespaceKind = NamespaceKindOrig | "project";
export interface NamespaceResponse
extends Omit<NamespaceResponseOrig, "namespace_kind"> {
namespace_kind: NamespaceKind;
}
export type NamespaceResponseList = NamespaceResponse[];
export type GetNamespacesApiResponse = NamespaceResponseList;
6 changes: 4 additions & 2 deletions client/src/features/projectsV2/api/projectV2.enhanced-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import type {
GetGroupsApiArg,
GetGroupsApiResponse as GetGroupsApiResponseOrig,
GetNamespacesApiArg,
GetNamespacesApiResponse as GetNamespacesApiResponseOrig,
GroupResponseList,
NamespaceResponseList,
} from "./namespace.api";
import type {
GetNamespacesApiResponse as GetNamespacesApiResponseOrig,
NamespaceResponseList,
} from "./namespace.enhanced-api";

export interface GetGroupsApiResponse extends AbstractKgPaginatedResponse {
groups: GetGroupsApiResponseOrig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { ErrorAlert } from "../../../components/Alert";
import { Loader } from "../../../components/Loader";
import type { PaginatedState } from "../../session/components/options/fetchMore.types";
import type { GetNamespacesApiResponse } from "../api/projectV2.enhanced-api";
import type { Project } from "../api/projectV2.api";
import type { NamespaceResponse } from "../api/namespace.enhanced-api";
import {
useGetNamespacesByNamespaceSlugQuery,
useGetNamespacesQuery,
Expand Down Expand Up @@ -273,6 +275,7 @@ interface ProjectNamespaceControlProps {
inputId: string;
onChange: (newValue: SingleValue<ResponseNamespace>) => void;
value?: string;
project?: Project;
}

export function ProjectNamespaceControl({
Expand All @@ -283,6 +286,7 @@ export function ProjectNamespaceControl({
onChange,
value,
"data-cy": dataCy,
project,
}: ProjectNamespaceControlProps) {
const {
data: namespacesFirstPage,
Expand Down Expand Up @@ -392,6 +396,23 @@ export function ProjectNamespaceControl({
});
}, [allNamespaces, specificNamespace, specificNamespaceRequestId]);

const allNamespacesWithProject = useMemo(() => {
if (!project) {
return allNamespaces || [];
}
return [
{
id: project.id,
slug: `${project.namespace}/${project.slug}`,
creation_date: project.creation_date,
created_by: project.created_by,
namespace_kind: "project",
name: `${project.namespace}/${project.slug}`,
} as NamespaceResponse,
...(allNamespaces || []),
];
}, [allNamespaces, project]);

if (isFetching) {
return (
<div className={cx(className, "form-control")} id={id}>
Expand All @@ -418,7 +439,7 @@ export function ProjectNamespaceControl({
hasMore={hasMore}
inputId={inputId}
isFetchingMore={namespacesPageResult.isFetching}
namespaces={allNamespaces}
namespaces={allNamespacesWithProject}
onChange={onChange}
onFetchMore={onFetchMore}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { RtkOrNotebooksError } from "../../../components/errors/RtkErrorAlert";
import useGroupPermissions from "../../groupsV2/utils/useGroupPermissions.hook";
import PermissionsGuard from "../../permissionsV2/PermissionsGuard";
import { useGetUserQuery } from "../../usersV2/api/users.api";
import { NamespaceKind } from "../api/namespace.api";
import { NamespaceKind } from "../api/namespace.enhanced-api";
import { useGetProjectsQuery } from "../api/projectV2.enhanced-api";
import ProjectShortHandDisplay from "../show/ProjectShortHandDisplay";

Expand Down
14 changes: 10 additions & 4 deletions tests/cypress/e2e/projectV2DataConnectorCredentials.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ describe("Set up data connectors with credentials", () => {
it("set up data connector with failed connection test", () => {
fixtures
.testCloudStorage({ success: false })
.postDataConnector({ namespace: "user1-uuid", visibility: "public" })
.postDataConnector({
namespace: "user1-uuid/test-2-v2-project",
visibility: "public",
})
.postDataConnectorProjectLink({
dataConnectorId: "ULID-5",
})
Expand Down Expand Up @@ -85,7 +88,7 @@ describe("Set up data connectors with credentials", () => {
cy.wait("@postDataConnector");
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
"The data connector user1-uuid/example-storage-without-credentials has been successfully added"
"The data connector user1-uuid/test-2-v2-project/example-storage-without-credentials has been successfully added"
);
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
Expand All @@ -109,7 +112,10 @@ describe("Set up data connectors with credentials", () => {
it("set up data connector with credentials", () => {
fixtures
.testCloudStorage({ success: true })
.postDataConnector({ namespace: "user1-uuid", visibility: "public" })
.postDataConnector({
namespace: "user1-uuid/test-2-v2-project",
visibility: "public",
})
.postDataConnectorProjectLink({ dataConnectorId: "ULID-5" })
.patchDataConnectorSecrets({
dataConnectorId: "ULID-5",
Expand Down Expand Up @@ -161,7 +167,7 @@ describe("Set up data connectors with credentials", () => {
cy.wait("@patchDataConnectorSecrets");
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
"The data connector user1-uuid/example-storage-with-credentials has been successfully added"
"The data connector user1-uuid/test-2-v2-project/example-storage-with-credentials has been successfully added"
);
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
Expand Down
14 changes: 10 additions & 4 deletions tests/cypress/e2e/projectV2setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ describe("Set up data connectors", () => {
.getDataConnector()
.getStorageSchema({ fixture: "cloudStorage/storage-schema-s3.json" })
.testCloudStorage({ success: false })
.postDataConnector({ namespace: "user1-uuid", visibility: "public" })
.postDataConnector({
namespace: "user1-uuid/test-2-v2-project",
visibility: "public",
})
.postDataConnectorProjectLink({ dataConnectorId: "ULID-5" });
cy.visit("/v2/projects/user1-uuid/test-2-v2-project");
cy.wait("@readProjectV2");
Expand Down Expand Up @@ -239,7 +242,7 @@ describe("Set up data connectors", () => {
cy.wait("@postDataConnector");
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
"The data connector user1-uuid/example-storage-without-credentials has been successfully added"
"The data connector user1-uuid/test-2-v2-project/example-storage-without-credentials has been successfully added"
);
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
Expand Down Expand Up @@ -342,7 +345,10 @@ describe("Set up data connectors", () => {
.getDataConnector()
.getStorageSchema({ fixture: "cloudStorage/storage-schema-s3.json" })
.testCloudStorage({ success: false })
.postDataConnector({ namespace: "user1-uuid", visibility: "public" })
.postDataConnector({
namespace: "user1-uuid/test-2-v2-project",
visibility: "public",
})
.postDataConnectorProjectLink({ dataConnectorId: "ULID-5" });
cy.visit("/v2/projects/user1-uuid/test-2-v2-project");
cy.wait("@readProjectV2");
Expand Down Expand Up @@ -375,7 +381,7 @@ describe("Set up data connectors", () => {
cy.wait("@postDataConnector");
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
"The data connector user1-uuid/example-storage-without-credentials has been successfully added"
"The data connector user1-uuid/test-2-v2-project/example-storage-without-credentials has been successfully added"
);
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
Expand Down

0 comments on commit f600423

Please sign in to comment.