-
Notifications
You must be signed in to change notification settings - Fork 153
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
base: main
Are you sure you want to change the base?
Add connection modal #3217
Conversation
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
dfb9dd5
to
71d923a
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
... and 15 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
bc21fd9
to
ac0bad6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/> | ||
} | ||
> | ||
<ConnectionTypePreview |
There was a problem hiding this comment.
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<{ |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
connection?: Connection; | ||
connectionTypes?: ConnectionTypeConfigMapObj[]; | ||
project?: ProjectKind; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
const connectionValuesAsStrings = Object.fromEntries( | ||
Object.entries(connectionValues).map(([key, value]) => [key, String(value)]), | ||
); |
There was a problem hiding this comment.
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.
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, | ||
}; |
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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
const displayName = | ||
connectionType && connectionType.metadata.annotations?.['openshift.io/display-name']; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
5ca2473
to
66cb7f8
Compare
))} | ||
</LabelGroup> | ||
) : ( | ||
<UnspecifiedValue /> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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], | ||
); |
There was a problem hiding this comment.
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.
https://issues.redhat.com/browse/RHOAIENG-11555
Description
Creates a new connection in the form of a secret on the project.
SCREENSHOTS
result:
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):
If you have UI changes:
@simrandhaliw
After the PR is posted & before it merges:
main