Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipelines modal use up top date data connections #1322

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as React from 'react';
import { Alert, Button, Form, Modal, Stack, StackItem } from '@patternfly/react-core';
import { DataConnection } from '~/pages/projects/types';
import { EMPTY_AWS_SECRET_DATA } from '~/pages/projects/dataConnections/const';
import './ConfigurePipelinesServerModal.scss';
import { convertAWSSecretData } from '~/pages/projects/screens/detail/data-connections/utils';
import { usePipelinesAPI } from '~/concepts/pipelines/context';
import useDataConnections from '~/pages/projects/screens/detail/data-connections/useDataConnections';
import { useContextResourceData } from '~/utilities/useContextResourceData';
import { isAWSValid } from '~/pages/projects/screens/spawner/spawnerUtils';
import { createPipelinesCR, deleteSecret } from '~/api';
import { ProjectDetailsContext } from '~/pages/projects/ProjectDetailsContext';
import { PipelinesDatabaseSection } from './PipelinesDatabaseSection';
import { ObjectStorageSection } from './ObjectStorageSection';
import {
Expand All @@ -35,7 +33,9 @@ export const ConfigurePipelinesServerModal: React.FC<ConfigurePipelinesServerMod
open,
}) => {
const { project, namespace } = usePipelinesAPI();
const dataConnections = useContextResourceData<DataConnection>(useDataConnections(namespace));
const {
dataConnections: { data: dataConnections },
} = React.useContext(ProjectDetailsContext);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks being able to add it with an existing connection on the global pages...

const [fetching, setFetching] = React.useState(false);
const [error, setError] = React.useState<Error | null>(null);
const [config, setConfig] = React.useState<PipelineServerConfigType>(FORM_DEFAULTS);
Expand Down Expand Up @@ -69,9 +69,7 @@ export const ConfigurePipelinesServerModal: React.FC<ConfigurePipelinesServerMod
let objectStorage: PipelineServerConfigType['objectStorage'];
if (config.objectStorage.useExisting) {
const existingName = config.objectStorage.existingName;
const existingValue = dataConnections.data?.find(
(dc) => dc.data.metadata.name === existingName,
);
const existingValue = dataConnections?.find((dc) => dc.data.metadata.name === existingName);
if (existingValue) {
objectStorage = {
existingValue: convertAWSSecretData(existingValue),
Expand Down Expand Up @@ -144,7 +142,11 @@ export const ConfigurePipelinesServerModal: React.FC<ConfigurePipelinesServerMod
submit();
}}
>
<ObjectStorageSection setConfig={setConfig} config={config} />
<ObjectStorageSection
setConfig={setConfig}
config={config}
dataConnections={dataConnections}
/>
<PipelinesDatabaseSection setConfig={setConfig} config={config} />
</Form>
</StackItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import {
} from '@patternfly/react-core';
import React from 'react';
import AWSField from '~/pages/projects/dataConnections/AWSField';
import useDataConnections from '~/pages/projects/screens/detail/data-connections/useDataConnections';
import { getDataConnectionDisplayName } from '~/pages/projects/screens/detail/data-connections/utils';
import { DataConnection } from '~/pages/projects/types';
import { useContextResourceData } from '~/utilities/useContextResourceData';
import { usePipelinesAPI } from '~/concepts/pipelines/context';
import { EMPTY_AWS_SECRET_DATA } from '~/pages/projects/dataConnections/const';
import { PipelineServerConfigType } from './types';
import './ConfigurePipelinesServerModal.scss';
Expand All @@ -33,11 +30,14 @@ const DISABLED_FOLDER_PATH = (
type ObjectStorageSectionProps = {
setConfig: (config: PipelineServerConfigType) => void;
config: PipelineServerConfigType;
dataConnections: DataConnection[];
};

export const ObjectStorageSection = ({ setConfig, config }: ObjectStorageSectionProps) => {
const { namespace } = usePipelinesAPI();
const dataConnections = useContextResourceData<DataConnection>(useDataConnections(namespace));
export const ObjectStorageSection = ({
setConfig,
config,
dataConnections,
}: ObjectStorageSectionProps) => {
const [existingDataConnectionOpen, setExistingDataConnectionOpen] = React.useState(false);
return (
<FormSection
Expand Down Expand Up @@ -76,11 +76,11 @@ export const ObjectStorageSection = ({ setConfig, config }: ObjectStorageSection
id="pipelines-data-connection"
isOpen={existingDataConnectionOpen}
placeholderText={
dataConnections.data.length === 0
dataConnections.length === 0
? 'No data connections available to select'
: 'Select...'
}
isDisabled={dataConnections.data.length === 0}
isDisabled={dataConnections.length === 0}
onToggle={(open) => setExistingDataConnectionOpen(open)}
onSelect={(_, option) => {
if (typeof option === 'string') {
Expand All @@ -98,7 +98,7 @@ export const ObjectStorageSection = ({ setConfig, config }: ObjectStorageSection
selections={config.objectStorage.existingName}
menuAppendTo="parent"
>
{dataConnections.data.map((connection) => (
{dataConnections.map((connection) => (
<SelectOption
key={connection.data.metadata.name}
value={connection.data.metadata.name}
Expand Down