forked from ansible/awx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ansible#7929 from nixocio/ui_associate_instances
Associate instances to instance groups Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
- Loading branch information
Showing
20 changed files
with
950 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Base from '../Base'; | ||
|
||
class Instances extends Base { | ||
constructor(http) { | ||
super(http); | ||
this.baseUrl = '/api/v2/instances/'; | ||
} | ||
} | ||
|
||
export default Instances; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
awx/ui_next/src/components/InstanceToggle/InstanceToggle.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useState, useEffect, useCallback } from 'react'; | ||
import { withI18n } from '@lingui/react'; | ||
import { t } from '@lingui/macro'; | ||
import { Switch, Tooltip } from '@patternfly/react-core'; | ||
import AlertModal from '../AlertModal'; | ||
import ErrorDetail from '../ErrorDetail'; | ||
import useRequest from '../../util/useRequest'; | ||
import { InstancesAPI } from '../../api'; | ||
import { useConfig } from '../../contexts/Config'; | ||
|
||
function InstanceToggle({ | ||
className, | ||
fetchInstances, | ||
instance, | ||
onToggle, | ||
i18n, | ||
}) { | ||
const { me } = useConfig(); | ||
const [isEnabled, setIsEnabled] = useState(instance.enabled); | ||
const [showError, setShowError] = useState(false); | ||
|
||
const { result, isLoading, error, request: toggleInstance } = useRequest( | ||
useCallback(async () => { | ||
await InstancesAPI.update(instance.id, { enabled: !isEnabled }); | ||
await fetchInstances(); | ||
return !isEnabled; | ||
}, [instance, isEnabled, fetchInstances]), | ||
instance.enabled | ||
); | ||
|
||
useEffect(() => { | ||
if (result !== isEnabled) { | ||
setIsEnabled(result); | ||
if (onToggle) { | ||
onToggle(result); | ||
} | ||
} | ||
}, [result, isEnabled, onToggle]); | ||
|
||
useEffect(() => { | ||
if (error) { | ||
setShowError(true); | ||
} | ||
}, [error]); | ||
|
||
return ( | ||
<> | ||
<Tooltip | ||
content={i18n._( | ||
t`Set the instance online or offline. If offline, jobs will not be assigned to this instance.` | ||
)} | ||
position="top" | ||
> | ||
<Switch | ||
className={className} | ||
css="display: inline-flex;" | ||
id={`host-${instance.id}-toggle`} | ||
label={i18n._(t`On`)} | ||
labelOff={i18n._(t`Off`)} | ||
isChecked={isEnabled} | ||
isDisabled={isLoading || !me.is_superuser} | ||
onChange={toggleInstance} | ||
aria-label={i18n._(t`Toggle instance`)} | ||
/> | ||
</Tooltip> | ||
{showError && error && !isLoading && ( | ||
<AlertModal | ||
variant="error" | ||
title={i18n._(t`Error!`)} | ||
isOpen={error && !isLoading} | ||
onClose={() => setShowError(false)} | ||
> | ||
{i18n._(t`Failed to toggle instance.`)} | ||
<ErrorDetail error={error} /> | ||
</AlertModal> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default withI18n()(InstanceToggle); |
Oops, something went wrong.