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

Edit for existing project connection instances #3250

Conversation

emilys314
Copy link
Contributor

@emilys314 emilys314 commented Sep 24, 2024

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

Description

Hooks up the edit kebab action to the manageConnectionModal. it will pass in the connection of that row, and pass isEdit. It will then prefill connection data.

The secret stores data in base64, so atob() is used to decode, this is done in the modal itself (which is similar to the data connections). This makes it easier to reference a corresponding connection type, to determine how to decode the value.

If a connection has env var names that do not match up to a connection type field, they will be appended to the bottom as short text fields.

The multi dropdown is stored as a JSON array, and decoded as such.

The "Save" button isn't enabled until the field values have been updated.

image

image

Additionally the k8sNameDesc is now intractable in the preview to mimic the actual form.

image

How Has This Been Tested?

Tested locally.
Just click the kebab menu on an existing connection row and click "Edit". You can update the values and click Save.

To test non matching values, you modify the env var for the field from the connection type, or edit it directly in openshift

Test Impact

A cypress test added to check the edit functionally
Jest tests to test the modal in edit form

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 24, 2024
Copy link
Contributor

openshift-ci bot commented Sep 24, 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

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 93.26923% with 7 lines in your changes missing coverage. Please review.

Project coverage is 84.90%. Comparing base (ca27d1d) to head (5959ccd).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rc/concepts/connectionTypes/ConnectionTypeForm.tsx 84.00% 4 Missing ⚠️
frontend/src/concepts/connectionTypes/utils.ts 89.65% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3250      +/-   ##
==========================================
+ Coverage   84.85%   84.90%   +0.04%     
==========================================
  Files        1299     1299              
  Lines       28919    29001      +82     
  Branches     7770     7807      +37     
==========================================
+ Hits        24539    24623      +84     
+ Misses       4380     4378       -2     
Files with missing lines Coverage Δ
...onnectionTypes/fields/ConnectionTypeFormFields.tsx 100.00% <100.00%> (ø)
...8sNameDescriptionField/K8sNameDescriptionField.tsx 100.00% <100.00%> (ø)
.../k8s/K8sNameDescriptionField/ResourceNameField.tsx 100.00% <100.00%> (ø)
...cts/screens/detail/connections/ConnectionsList.tsx 100.00% <100.00%> (ø)
...ts/screens/detail/connections/ConnectionsTable.tsx 100.00% <100.00%> (ø)
...eens/detail/connections/ManageConnectionsModal.tsx 93.47% <100.00%> (+4.08%) ⬆️
.../projects/screens/detail/data-connections/utils.ts 97.67% <100.00%> (+0.05%) ⬆️
frontend/src/concepts/connectionTypes/utils.ts 92.72% <89.65%> (-1.18%) ⬇️
...rc/concepts/connectionTypes/ConnectionTypeForm.tsx 88.23% <84.00%> (-0.66%) ⬇️

... and 5 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 ca27d1d...5959ccd. Read the comment docs.

@emilys314 emilys314 marked this pull request as ready for review September 24, 2024 20:32
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Sep 24, 2024
@@ -111,7 +113,7 @@ const ConnectionTypeForm: React.FC<Props> = ({
},
}
}
onDataChange={setConnectionNameDesc}
onDataChange={setConnectionNameDesc ?? (() => undefined)} // onDataChange needs to be truthy to show resource name
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a strange requirement from K8sNameDescriptionField. Can we update it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay it's been updated. I'm not 100% certain on all the use cases for the component, but i think if you want to old preview behavior, they can still pass in the k8sName.state.immutable = false

const matching = fields?.find((f) => isConnectionTypeDataField(f) && f.envVar === key);
if (!matching) {
unmatched.push({
type: ConnectionTypeFieldType.ShortText,
Copy link
Contributor

Choose a reason for hiding this comment

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

we could be smart. If it contains \n make it long text, or if it is true|false make it a boolean. But otherwise I think this works.

Comment on lines 188 to 190
response[key] = JSON.parse(decodedString);
} catch {
response[key] = decodedString;
Copy link
Contributor

@christianvogt christianvogt Sep 24, 2024

Choose a reason for hiding this comment

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

This is expected to be an array correct? If so, perhaps ensure it parsed correctly and fallback to [<decodedString>]?

@@ -74,6 +91,7 @@ const ConnectionTypeFormFields: React.FC<Props> = ({
<React.Fragment key={i}>{renderDataFields(fieldGroup.fields)}</React.Fragment>
),
)}
{unmatchedValues.length > 0 && renderDataFields(unmatchedValues)}
Copy link
Contributor

Choose a reason for hiding this comment

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

@simrandhaliw when editing a connection instance where the env var has no matching field in the connection type, should we section these off with a header and description which informs the user of their situation?

matchingField.properties.variant === 'multi'
) {
try {
response[key] = JSON.parse(decodedString);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this overkill what I'm suggesting to ensure that the parsed value conforms to an array of strings?

Suggested change
response[key] = JSON.parse(decodedString);
const parsed = JSON.parse(decodedString);
if (Array.isArray(parsed)) {
response[key] = parsed.map(v => String(v));
} else {
response[key] = [decodedString];
}

@emilys314 emilys314 force-pushed the edit-project-connections-modal branch 2 times, most recently from da72b1d to e763060 Compare September 25, 2024 17:55
@emilys314
Copy link
Contributor Author

updates to the connection type select
image

@christianvogt
Copy link
Contributor

/lgtm
/approve

Copy link
Contributor

openshift-ci bot commented Sep 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: christianvogt

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

The pull request process is described 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

@openshift-ci openshift-ci bot removed the lgtm label Sep 26, 2024
@emilys314
Copy link
Contributor Author

rebasing to run CI again

@christianvogt
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Sep 26, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 6ca046e into opendatahub-io:main Sep 26, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants