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

Add connection modal #3217

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

emilys314
Copy link
Contributor

@emilys314 emilys314 commented Sep 18, 2024

https://issues.redhat.com/browse/RHOAIENG-11555

Description

Creates a new connection in the form of a secret on the project.

SCREENSHOTS

image
image

image
result:
image

image

How Has This Been Tested?

If you have a connection type named s3, then you can view the results in data connections. otherwise check the secrets to verify the creation

Test Impact

cypress and jest tests added

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

@simrandhaliw

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress This PR is in WIP state label Sep 18, 2024
Copy link
Contributor

openshift-ci bot commented Sep 18, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Contributor

openshift-ci bot commented Sep 18, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign manosnoam for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 89.74359% with 16 lines in your changes missing coverage. Please review.

Project coverage is 85.64%. Comparing base (4cec257) to head (de17325).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...eens/detail/connections/ManageConnectionsModal.tsx 89.39% 7 Missing ⚠️
...onnectionTypes/ConnectionTypeDetailsHelperText.tsx 78.94% 4 Missing ⚠️
...rc/concepts/connectionTypes/ConnectionTypeForm.tsx 88.88% 4 Missing ⚠️
frontend/src/concepts/connectionTypes/utils.ts 93.33% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3217      +/-   ##
==========================================
+ Coverage   85.50%   85.64%   +0.13%     
==========================================
  Files        1280     1282       +2     
  Lines       28190    28365     +175     
  Branches     7535     7601      +66     
==========================================
+ Hits        24103    24292     +189     
+ Misses       4087     4073      -14     
Files with missing lines Coverage Δ
...ts/connectionTypes/ConnectionTypePreviewDrawer.tsx 100.00% <ø> (ø)
...onnectionTypes/fields/ConnectionTypeFormFields.tsx 100.00% <100.00%> (+4.34%) ⬆️
frontend/src/concepts/connectionTypes/types.ts 100.00% <ø> (ø)
...cts/screens/detail/connections/ConnectionsList.tsx 100.00% <100.00%> (ø)
frontend/src/concepts/connectionTypes/utils.ts 93.90% <93.33%> (-0.13%) ⬇️
...onnectionTypes/ConnectionTypeDetailsHelperText.tsx 78.94% <78.94%> (ø)
...rc/concepts/connectionTypes/ConnectionTypeForm.tsx 88.88% <88.88%> (ø)
...eens/detail/connections/ManageConnectionsModal.tsx 89.39% <89.39%> (ø)

... and 15 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4cec257...de17325. Read the comment docs.

@emilys314 emilys314 force-pushed the project-connection-add-modal branch 4 times, most recently from bc21fd9 to ac0bad6 Compare September 19, 2024 13:12
@emilys314 emilys314 marked this pull request as ready for review September 19, 2024 14:42
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Sep 19, 2024
Copy link
Contributor

@christianvogt christianvogt left a comment

Choose a reason for hiding this comment

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

Connection preview displays the resource name header with no content. I believe this should be omitted here.

image

/>
}
>
<ConnectionTypePreview
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be named ConnectionTypePreview anymore since it's being reused here and the preview.
Maybe ConnectionTypeForm

}>(connection?.data ?? {});

// if user changes connection types, don't discard previous entries in case of accident
const [previousEntries, setPreviousEntries] = React.useState<{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the previous entries could simply be a ref instead because we don't need to react to this state change.

Comment on lines 70 to 77
setNameDescData('name', '');
setNameDescData('description', '');
setConnectionValues({});
}
// load saved values?
if (type?.metadata.name && type.metadata.name in previousEntries) {
setNameDescData('name', previousEntries[type.metadata.name].nameDesc.name);
setNameDescData('description', previousEntries[type.metadata.name].nameDesc.description);
Copy link
Contributor

Choose a reason for hiding this comment

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

When switching connection types, the connection name and connection description are also wiped and restored. The name and description should remain when switching types.

Comment on lines 18 to 20
connection?: Connection;
connectionTypes?: ConnectionTypeConfigMapObj[];
project?: ProjectKind;
Copy link
Contributor

Choose a reason for hiding this comment

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

These should all be required fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think connection?: Connection can remain optional, since this is the scenario for a new connection. If it's edit, then connection will be a filled out value.

I can update the other 2 though for sure

connection?: Connection;
connectionTypes?: ConnectionTypeConfigMapObj[];
project?: ProjectKind;
onClose: (refresh?: boolean) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of naming the param refresh i think it would be better to describe what happened instead of what's expected of the caller to do. Other modals use submitted.

Comment on lines 125 to 127
const connectionValuesAsStrings = Object.fromEntries(
Object.entries(connectionValues).map(([key, value]) => [key, String(value)]),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to discuss how dropdown values should be serialized / deserialized. Especially for multi dropdown. A multi drop down item containing a comma will be serialized as a string in a way that loses the ability to parse back the value.

Comment on lines 128 to 145
const update: Connection = {
apiVersion: 'v1',
kind: 'Secret',
metadata: {
name: nameDescData.k8sName.value || translateDisplayNameForK8s(nameDescData.name),
namespace: project?.metadata.name ?? '',
labels: {
'opendatahub.io/dashboard': 'true',
'opendatahub.io/managed': 'true',
},
annotations: {
'opendatahub.io/connection-type': selectedConnectionType?.metadata.name ?? '',
'openshift.io/display-name': nameDescData.name,
'openshift.io/description': nameDescData.description,
},
},
stringData: connectionValuesAsStrings,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to our utils in concepts.

setConnectionNameDesc,
connectionValues,
setConnectionValues,
}) => {
const connectionTypeName = obj && obj.metadata.annotations?.['openshift.io/display-name'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if this is not a preview, we want to fall back to the metadata name therefore using the util getDisplayNameFromK8Resource

Comment on lines 24 to 25
const displayName =
connectionType && connectionType.metadata.annotations?.['openshift.io/display-name'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if this is not a preview, we want to fall back to the metadata name therefore using the util getDisplayNameFromK8Resource

import CategoryLabel from './CategoryLabel';

type Props = {
connectionType?: ConnectionTypeConfigMapObj;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a required prop.

))}
</LabelGroup>
) : (
<UnspecifiedValue />
Copy link
Contributor

Choose a reason for hiding this comment

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

A connection type should always have at least one category but good to have fall backs.
When not in preview we can omit the category altogether or render -. But UnspecifiedValue is for preview only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated with a isPreview ? <UnspecifiedValues /> : "-"

I don't really like the 2 ternaries being chained but yeah

Comment on lines 83 to 95
const isValid = React.useMemo(
() =>
!!selectedConnectionType &&
!!nameDescData.name &&
!selectedConnectionType.data?.fields?.find(
(field) =>
isConnectionTypeDataField(field) &&
field.required &&
!connectionValues[field.envVar] &&
field.type !== ConnectionTypeFieldType.Boolean,
),
[selectedConnectionType, nameDescData, connectionValues],
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Individual form fields have an onValidate callback. We need to hook into those such that errors are propagated to here.
You can test this with invalid URIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants