mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-25 18:50:08 +03:00
69 lines
2.7 KiB
JavaScript
69 lines
2.7 KiB
JavaScript
/* ------------------------------------------------------------------------- *
|
|
* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems *
|
|
* *
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
|
|
* not use this file except in compliance with the License. You may obtain *
|
|
* a copy of the License at *
|
|
* *
|
|
* http://www.apache.org/licenses/LICENSE-2.0 *
|
|
* *
|
|
* Unless required by applicable law or agreed to in writing, software *
|
|
* distributed under the License is distributed on an "AS IS" BASIS, *
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
|
* See the License for the specific language governing permissions and *
|
|
* limitations under the License. *
|
|
* ------------------------------------------------------------------------- */
|
|
import { memo, useMemo } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import { Alert, LinearProgress } from '@mui/material'
|
|
|
|
import { useViews } from 'client/features/Auth'
|
|
import { useGetServiceTemplateQuery } from 'client/features/OneApi/serviceTemplate'
|
|
import { getAvailableInfoTabs } from 'client/models/Helper'
|
|
import { RESOURCE_NAMES } from 'client/constants'
|
|
|
|
import Tabs from 'client/components/Tabs'
|
|
import Info from 'client/components/Tabs/ServiceTemplate/Info'
|
|
import Roles from 'client/components/Tabs/ServiceTemplate/Roles'
|
|
import Template from 'client/components/Tabs/ServiceTemplate/Template'
|
|
|
|
const getTabComponent = (tabName) =>
|
|
({
|
|
info: Info,
|
|
roles: Roles,
|
|
template: Template,
|
|
}[tabName])
|
|
|
|
const ServiceTemplateTabs = memo(({ id }) => {
|
|
const { view, getResourceView } = useViews()
|
|
const { isError, error, status, data } = useGetServiceTemplateQuery({
|
|
id,
|
|
})
|
|
|
|
const tabsAvailable = useMemo(() => {
|
|
const resource = RESOURCE_NAMES.SERVICE_TEMPLATE
|
|
const infoTabs = getResourceView(resource)?.['info-tabs'] ?? {}
|
|
|
|
return getAvailableInfoTabs(infoTabs, getTabComponent, id)
|
|
}, [view, id])
|
|
|
|
if (isError) {
|
|
return (
|
|
<Alert severity="error" variant="outlined">
|
|
{error.data}
|
|
</Alert>
|
|
)
|
|
}
|
|
|
|
if (status === 'fulfilled' || id === data?.ID) {
|
|
return <Tabs addBorder tabs={tabsAvailable ?? []} />
|
|
}
|
|
|
|
return <LinearProgress color="secondary" sx={{ width: '100%' }} />
|
|
})
|
|
|
|
ServiceTemplateTabs.propTypes = { id: PropTypes.string.isRequired }
|
|
ServiceTemplateTabs.displayName = 'ServiceTemplateTabs'
|
|
|
|
export default ServiceTemplateTabs
|