Fix UI peers_from_control_nodes (#14858)

* Fix UI peers_from_control_nodes

Fixes bug where peers_from_control_node was
greyed out in UI.

Additional changes:
- Make edit instance button only show for instances
with managed = False
- Make remove instance button only show for instances
with managed = False
- InstanceList selectable only for instances with
managed = False

---------

Signed-off-by: Seth Foster <fosterbseth@gmail.com>
This commit is contained in:
Seth Foster 2024-02-08 14:13:11 -05:00 committed by GitHub
parent b79aa5b1ed
commit 40150a2be8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 40 deletions

View File

@ -209,33 +209,31 @@ function InstanceDetail({ setBreadcrumb, isK8s }) {
<Detail label={t`Node Type`} value={instance.node_type} />
<Detail label={t`Host`} value={instance.ip_address} />
<Detail label={t`Listener Port`} value={instance.listener_port} />
{(isExecutionNode || isHopNode || !isManaged) && (
<>
{instance.related?.install_bundle && (
<Detail
label={t`Install Bundle`}
value={
<Tooltip content={t`Click to download bundle`}>
<Button
component="a"
isSmall
href={`${instance.related?.install_bundle}`}
target="_blank"
variant="secondary"
dataCy="install-bundle-download-button"
rel="noopener noreferrer"
>
<DownloadIcon />
</Button>
</Tooltip>
}
/>
)}
<Detail
label={t`Peers from control nodes`}
value={instance.peers_from_control_nodes ? t`On` : t`Off`}
/>
</>
{!isManaged && instance.related?.install_bundle && (
<Detail
label={t`Install Bundle`}
value={
<Tooltip content={t`Click to download bundle`}>
<Button
component="a"
isSmall
href={`${instance.related?.install_bundle}`}
target="_blank"
variant="secondary"
dataCy="install-bundle-download-button"
rel="noopener noreferrer"
>
<DownloadIcon />
</Button>
</Tooltip>
}
/>
)}
{(isExecutionNode || isHopNode) && (
<Detail
label={t`Peers from control nodes`}
value={instance.peers_from_control_nodes ? t`On` : t`Off`}
/>
)}
{!isHopNode && (
<>
@ -341,9 +339,8 @@ function InstanceDetail({ setBreadcrumb, isK8s }) {
)}
</DetailList>
<CardActionsRow>
{config?.me?.is_superuser &&
isK8s &&
(isExecutionNode || isHopNode || !isManaged) && (
{config?.me?.is_superuser && isK8s && !isManaged && (
<>
<Button
ouiaId="instance-detail-edit-button"
aria-label={t`edit`}
@ -352,17 +349,14 @@ function InstanceDetail({ setBreadcrumb, isK8s }) {
>
{t`Edit`}
</Button>
)}
{config?.me?.is_superuser &&
isK8s &&
(isExecutionNode || isHopNode || !isManaged) && (
<RemoveInstanceButton
dataCy="remove-instance-button"
itemsToRemove={[instance]}
isK8s={isK8s}
onRemove={removeInstances}
/>
)}
</>
)}
{isExecutionNode && (
<Tooltip content={t`Run a health check on the instance`}>
<Button

View File

@ -114,7 +114,6 @@ function InstanceListItem({
);
const isHopNode = instance.node_type === 'hop';
const isExecutionNode = instance.node_type === 'execution';
const isManaged = instance.managed;
return (
@ -140,7 +139,7 @@ function InstanceListItem({
rowIndex,
isSelected,
onSelect,
disable: !(isExecutionNode || isHopNode || isManaged),
disable: isManaged,
}}
dataLabel={t`Selected`}
/>

View File

@ -16,7 +16,7 @@ const INSTANCE_TYPES = [
{ id: 'hop', name: t`Hop` },
];
function InstanceFormFields({ isEdit, instance }) {
function InstanceFormFields({ isEdit }) {
const [instanceTypeField, instanceTypeMeta, instanceTypeHelpers] = useField({
name: 'node_type',
validate: required(t`Set a value for this field`),
@ -98,7 +98,6 @@ function InstanceFormFields({ isEdit, instance }) {
name="peers_from_control_nodes"
label={t`Peers from control nodes`}
tooltip={t`If enabled, control nodes will peer to this instance automatically. If disabled, instance will be connected only to associated peers.`}
isDisabled={parseInt(instance.listener_port, 10) < 1024 || true}
/>
</FormGroup>
</>
@ -139,7 +138,7 @@ function InstanceForm({
{(formik) => (
<Form autoComplete="off" onSubmit={formik.handleSubmit}>
<FormColumnLayout>
<InstanceFormFields isEdit={isEdit} instance={instance} />
<InstanceFormFields isEdit={isEdit} />
<FormSubmitError error={submitError} />
<FormActionGroup
onCancel={handleCancel}