@kinvolk/headlamp-plugin
Version:
The needed infrastructure for building Headlamp plugins.
52 lines (51 loc) • 3.9 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/*
* Copyright 2025 The Kubernetes Authors
*
* 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 { InlineIcon } from '@iconify/react';
import Button from '@mui/material/Button';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import CardHeader from '@mui/material/CardHeader';
import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { isElectron } from '../../../helpers/isElectron';
import { createRouteURL } from '../../../lib/router/createRouteURL';
import { useTypedSelector } from '../../../redux/hooks';
import { PageGrid } from '../../common/Resource';
import SectionBox from '../../common/SectionBox';
function AddClusterProvider({ title, icon, description, url }) {
const history = useHistory();
const { t } = useTranslation(['translation']);
const Icon = icon;
const avatar = _jsx(Icon, { width: 24, height: 24 });
return (_jsxs(Card, { variant: "outlined", children: [_jsx(CardHeader, { title: title, avatar: avatar }), _jsxs(CardContent, { children: [_jsx(Typography, { children: description }), _jsx(Button, { variant: "contained", onClick: () => history.push(url), sx: { mt: 2 }, children: t('translation|Add') })] })] }));
}
export default function AddCluster(props) {
const { open } = props;
const { t } = useTranslation(['translation']);
const history = useHistory();
const addClusterProviders = useTypedSelector(state => state.clusterProvider.clusterProviders);
const customSidebarEntries = useTypedSelector(state => state.sidebar.entries);
if (!open) {
return null;
}
const isPluginCatalogRegistered = Object.values(customSidebarEntries).some(entry => entry.url === '/plugin-catalog');
return (_jsx(PageGrid, { children: _jsx(SectionBox, { backLink: true, title: t('translation|Add Cluster'), py: 2, mt: [4, 0, 0], children: _jsxs(Grid, { container: true, justifyContent: "flex-start", alignItems: "stretch", spacing: 4, children: [_jsx(Grid, { item: true, xs: 12, children: _jsx(Typography, { children: t('Proceed to select your preferred method for cluster creation and addition') }) }), _jsx(Grid, { item: true, xs: 12, children: _jsx(Card, { variant: "outlined", children: _jsx(CardContent, { children: _jsx(Button, { onClick: () => history.push(createRouteURL('loadKubeConfig')), startIcon: _jsx(InlineIcon, { icon: "mdi:plus-box-outline" }), children: t('translation|Load from KubeConfig') }) }) }) }), _jsx(Grid, { item: true, xs: 12, children: _jsx(Typography, { variant: "h4", children: t('translation|Providers') }) }), isElectron() && isPluginCatalogRegistered && addClusterProviders.length === 0 && (_jsx(Grid, { item: true, xs: 12, children: _jsx(Button, { onClick: () => {
window.location.href = '#/plugin-catalog/headlamp-plugins/headlamp_minikube';
}, startIcon: _jsx(InlineIcon, { icon: "mdi:plus-box-outline" }), children: t('translation|Add Local Cluster Provider') }) })), addClusterProviders.length > 0 && (_jsx(Grid, { item: true, xs: 12, children: addClusterProviders.map(addClusterProviderInfo => (_jsx(AddClusterProvider, { ...addClusterProviderInfo }))) }))] }) }) }));
}