// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
// with the License. A copy of the License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
// OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
// limitations under the License.
import {Region} from '../../types/base'
import {ClusterName, ComputeFleetStatus} from '../../types/clusters'
import {InstanceState, Instance, NodeType} from '../../types/instances'
import React from 'react'
import {useNavigate} from 'react-router-dom'
import {useTranslation} from 'react-i18next'
import {GetClusterInstances, Ec2Action} from '../../model'
import {
setState,
clearState,
useState,
getState,
consoleDomain,
} from '../../store'
// UI Elements
import {
Button,
Header,
Link,
Pagination,
SpaceBetween,
Table,
TextFilter,
} from '@cloudscape-design/components'
import {useCollection} from '@cloudscape-design/collection-hooks'
// Components
import {InstanceStatusIndicator} from '../../components/Status'
import EmptyState from '../../components/EmptyState'
import DateView from '../../components/date/DateView'
function InstanceActions({
fleetStatus,
instance,
}: {
fleetStatus: ComputeFleetStatus
instance: Instance
}) {
const pending = useState(['app', 'clusters', 'action', 'pending'])
const clusterName = useState(['app', 'clusters', 'selected'])
const navigate = useNavigate()
const logHref = `/clusters/${clusterName}/logs?instance=${instance.instanceId}`
const {t} = useTranslation()
const refresh = () => {
const clusterName = getState(['app', 'clusters', 'selected'])
clusterName &&
GetClusterInstances(clusterName, () =>
clearState(['app', 'clusters', 'action', 'pending']),
)
}
const stopInstance = (instance: Instance) => {
setState(['app', 'clusters', 'action', 'pending'], true)
Ec2Action([instance.instanceId], 'stop_instances', refresh)
}
const startInstance = (instance: Instance) => {
setState(['app', 'clusters', 'action', 'pending'], true)
Ec2Action([instance.instanceId], 'start_instances', refresh)
}
return (
{fleetStatus === ComputeFleetStatus.Stopped && (