-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: support for data connectors on user and group namespaces (#3315) * feat: set/edit secrets for data connectors (#3330) * feat: data connectors on the project page (#3334) * feat: support launching sessions with data connectors (#3346) BREAKING CHANGE: Requires renku-data-services version >= 0.xx.0 BREAKING CHANGE: Requires renku-notebooks version >= 0.xx.0 build: update to latest project api spec
- Loading branch information
Showing
75 changed files
with
7,630 additions
and
4,192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*! | ||
* Copyright 2024 - Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
interface RenkuIconProps { | ||
className?: string; | ||
id?: string; | ||
} | ||
|
||
export default function CrosshairIcon({ className, id }: RenkuIconProps) { | ||
return ( | ||
<svg | ||
aria-hidden | ||
className={className} | ||
id={id} | ||
role="img" | ||
width="16" | ||
height="16" | ||
fill="currentColor" | ||
viewBox="0 0 16 16" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
{/* eslint-disable spellcheck/spell-checker */} | ||
<path d="M8.5.5a.5.5 0 0 0-1 0v.518A7 7 0 0 0 1.018 7.5H.5a.5.5 0 0 0 0 1h.518A7 7 0 0 0 7.5 14.982v.518a.5.5 0 0 0 1 0v-.518A7 7 0 0 0 14.982 8.5h.518a.5.5 0 0 0 0-1h-.518A7 7 0 0 0 8.5 1.018zm-6.48 7A6 6 0 0 1 7.5 2.02v.48a.5.5 0 0 0 1 0v-.48a6 6 0 0 1 5.48 5.48h-.48a.5.5 0 0 0 0 1h.48a6 6 0 0 1-5.48 5.48v-.48a.5.5 0 0 0-1 0v.48A6 6 0 0 1 2.02 8.5h.48a.5.5 0 0 0 0-1zM8 10a2 2 0 1 0 0-4 2 2 0 0 0 0 4" /> | ||
{/* eslint-enable spellcheck/spell-checker */} | ||
</svg> | ||
); | ||
} |
302 changes: 302 additions & 0 deletions
302
...res/ProjectPageV2/ProjectPageContent/DataConnectors/ProjectConnectDataConnectorsModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,302 @@ | ||
/*! | ||
* Copyright 2024 - Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License | ||
*/ | ||
|
||
import cx from "classnames"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { Database, NodePlus, PlusLg, XLg } from "react-bootstrap-icons"; | ||
import { Controller, useForm } from "react-hook-form"; | ||
import { | ||
Button, | ||
ButtonGroup, | ||
Form, | ||
Input, | ||
Label, | ||
Modal, | ||
ModalBody, | ||
ModalHeader, | ||
ModalFooter, | ||
} from "reactstrap"; | ||
|
||
import { RtkOrNotebooksError } from "../../../../components/errors/RtkErrorAlert"; | ||
import { Loader } from "../../../../components/Loader"; | ||
import useAppDispatch from "../../../../utils/customHooks/useAppDispatch.hook"; | ||
|
||
import { | ||
dataConnectorsApi, | ||
usePostDataConnectorsByDataConnectorIdProjectLinksMutation, | ||
} from "../../../dataConnectorsV2/api/data-connectors.enhanced-api"; | ||
import DataConnectorModal, { | ||
DataConnectorModalBodyAndFooter, | ||
} from "../../../dataConnectorsV2/components/DataConnectorModal/index"; | ||
import styles from "../../../dataConnectorsV2/components/DataConnectorModal/DataConnectorModal.module.scss"; | ||
|
||
import type { Project } from "../../../projectsV2/api/projectV2.api"; | ||
import { projectV2Api } from "../../../projectsV2/api/projectV2.enhanced-api"; | ||
|
||
interface ProjectConnectDataConnectorsModalProps | ||
extends Omit< | ||
Parameters<typeof DataConnectorModal>[0], | ||
"dataConnector" | "projectId" | ||
> { | ||
project: Project; | ||
} | ||
|
||
type ProjectConnectDataConnectorMode = "create" | "link"; | ||
|
||
export default function ProjectConnectDataConnectorsModal({ | ||
isOpen, | ||
namespace, | ||
project, | ||
toggle, | ||
}: ProjectConnectDataConnectorsModalProps) { | ||
const [mode, setMode] = useState<ProjectConnectDataConnectorMode>("link"); | ||
return ( | ||
<Modal | ||
backdrop="static" | ||
centered | ||
className={styles.modal} | ||
data-cy="project-data-connector-connect-modal" | ||
fullscreen="lg" | ||
id={"connect-project-data-connector"} | ||
isOpen={isOpen} | ||
scrollable | ||
size="lg" | ||
unmountOnClose={false} | ||
toggle={toggle} | ||
> | ||
<ModalHeader | ||
toggle={toggle} | ||
data-cy="project-data-connector-connect-header" | ||
> | ||
<ProjectConnectDataConnectorModalHeader mode={mode} setMode={setMode} /> | ||
</ModalHeader> | ||
{mode === "create" ? ( | ||
<ProjectCreateDataConnectorBodyAndFooter | ||
{...{ | ||
isOpen, | ||
namespace, | ||
project, | ||
toggle, | ||
}} | ||
/> | ||
) : ( | ||
<ProjectLinkDataConnectorBodyAndFooter | ||
{...{ | ||
isOpen, | ||
namespace, | ||
project, | ||
toggle, | ||
}} | ||
/> | ||
)} | ||
</Modal> | ||
); | ||
} | ||
|
||
function ProjectConnectDataConnectorModalHeader({ | ||
mode, | ||
setMode, | ||
}: { | ||
mode: ProjectConnectDataConnectorMode; | ||
setMode: (mode: ProjectConnectDataConnectorMode) => void; | ||
}) { | ||
return ( | ||
<> | ||
<div> | ||
<Database className={cx("bi", "me-1")} /> Link or create data connector | ||
</div> | ||
<div className="mt-3"> | ||
<ButtonGroup> | ||
<Input | ||
type="radio" | ||
className="btn-check" | ||
id="project-data-controller-mode-link" | ||
value="link" | ||
checked={mode === "link"} | ||
onChange={() => { | ||
setMode("link"); | ||
}} | ||
/> | ||
<Label | ||
data-cy="project-data-controller-mode-link" | ||
for="project-data-controller-mode-link" | ||
className={cx("btn", "btn-outline-primary")} | ||
> | ||
<NodePlus className={cx("bi", "me-1")} /> | ||
Link a data connector | ||
</Label> | ||
<Input | ||
type="radio" | ||
className="btn-check" | ||
id="project-data-controller-mode-create" | ||
value="create" | ||
checked={mode === "create"} | ||
onChange={() => { | ||
setMode("create"); | ||
}} | ||
/> | ||
<Label | ||
data-cy="project-data-controller-mode-create" | ||
for="project-data-controller-mode-create" | ||
className={cx("btn", "btn-outline-primary")} | ||
> | ||
<PlusLg className={cx("bi", "me-1")} /> | ||
Create a data connector | ||
</Label> | ||
</ButtonGroup> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
function ProjectCreateDataConnectorBodyAndFooter({ | ||
isOpen, | ||
namespace, | ||
project, | ||
toggle, | ||
}: ProjectConnectDataConnectorsModalProps) { | ||
return ( | ||
<DataConnectorModalBodyAndFooter | ||
dataConnector={null} | ||
{...{ | ||
isOpen, | ||
namespace, | ||
project, | ||
toggle, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
interface DataConnectorLinkFormFields { | ||
dataConnectorIdentifier: string; | ||
} | ||
|
||
function ProjectLinkDataConnectorBodyAndFooter({ | ||
project, | ||
toggle, | ||
}: ProjectConnectDataConnectorsModalProps) { | ||
const dispatch = useAppDispatch(); | ||
const [ | ||
linkDataConnector, | ||
{ error: linkDataConnectorError, isLoading, isSuccess }, | ||
] = usePostDataConnectorsByDataConnectorIdProjectLinksMutation(); | ||
const { | ||
control, | ||
formState: { errors }, | ||
handleSubmit, | ||
setError, | ||
} = useForm<DataConnectorLinkFormFields>({ | ||
defaultValues: { | ||
dataConnectorIdentifier: "", | ||
}, | ||
}); | ||
|
||
const onSubmit = useCallback( | ||
async (values: DataConnectorLinkFormFields) => { | ||
const [namespace, slug] = values.dataConnectorIdentifier.split("/"); | ||
const dataConnectorPromise = dispatch( | ||
dataConnectorsApi.endpoints.getNamespacesByNamespaceDataConnectorsAndSlug.initiate( | ||
{ namespace, slug } | ||
) | ||
); | ||
const { data: dataConnector, isSuccess } = await dataConnectorPromise; | ||
dataConnectorPromise.unsubscribe(); | ||
if (!isSuccess || dataConnector == null) { | ||
setError("dataConnectorIdentifier", { | ||
type: "manual", | ||
message: "Data connector not found", | ||
}); | ||
return false; | ||
} | ||
linkDataConnector({ | ||
dataConnectorId: dataConnector.id, | ||
dataConnectorToProjectLinkPost: { | ||
project_id: project.id, | ||
}, | ||
}); | ||
}, | ||
[dispatch, linkDataConnector, project.id, setError] | ||
); | ||
|
||
useEffect(() => { | ||
if (isSuccess) { | ||
dispatch(projectV2Api.util.invalidateTags(["DataConnectors"])); | ||
toggle(); | ||
} | ||
}, [dispatch, isSuccess, toggle]); | ||
|
||
return ( | ||
<Form noValidate onSubmit={handleSubmit(onSubmit)}> | ||
<ModalBody data-cy="data-connector-edit-body"> | ||
<div className="mb-3"> | ||
<Label className="form-label" for="data-connector-identifier"> | ||
Data connector identifier | ||
</Label> | ||
<Controller | ||
control={control} | ||
name="dataConnectorIdentifier" | ||
render={({ field }) => ( | ||
<Input | ||
className={cx( | ||
"form-control", | ||
errors.dataConnectorIdentifier && "is-invalid" | ||
)} | ||
id="data-connector-identifier" | ||
placeholder="namespace/slug" | ||
type="text" | ||
{...field} | ||
/> | ||
)} | ||
rules={{ | ||
required: true, | ||
pattern: /^(.+)\/(.+)$/, | ||
}} | ||
/> | ||
<div className="invalid-feedback"> | ||
Please provide an identifier (namespace/group) for the data | ||
connector | ||
</div> | ||
</div> | ||
{isSuccess != null && !isSuccess && ( | ||
<RtkOrNotebooksError error={linkDataConnectorError} /> | ||
)} | ||
</ModalBody> | ||
|
||
<ModalFooter className="border-top" data-cy="data-connector-edit-footer"> | ||
<Button color="outline-danger" onClick={toggle}> | ||
<XLg className={cx("bi", "me-1")} /> | ||
Cancel | ||
</Button> | ||
<Button | ||
color="primary" | ||
data-cy="link-data-connector-button" | ||
disabled={isLoading} | ||
type="submit" | ||
> | ||
{isLoading ? ( | ||
<Loader className="me-1" inline size={16} /> | ||
) : ( | ||
<NodePlus className={cx("bi", "me-1")} /> | ||
)} | ||
Link data | ||
</Button> | ||
</ModalFooter> | ||
</Form> | ||
); | ||
} |
Oops, something went wrong.