/******************************************************************************** * Copyright (c) 2020 TypeFox and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { FunctionComponent, createContext, useState } from 'react'; import { useLocation } from 'react-router-dom'; import { Box, Button, Link, Paper, Grid, Typography } from '@mui/material'; import { styled, Theme } from '@mui/material/styles'; import WarningIcon from '@mui/icons-material/Warning'; import { UserNamespaceExtensionListContainer } from './user-namespace-extension-list'; import { AdminDashboardRoutes } from '../admin-dashboard/admin-dashboard-routes'; import { Namespace, UserData } from '../../extension-registry-types'; import { NamespaceChangeDialog } from '../admin-dashboard/namespace-change-dialog'; import { NamespaceDeleteDialog } from '../admin-dashboard/namespace-delete-dialog'; import { UserNamespaceMemberList } from './user-namespace-member-list'; import { UserNamespaceDetails } from './user-namespace-details'; export interface NamespaceDetailConfig { defaultMemberRole?: 'contributor' | 'owner'; } // eslint-disable-next-line react-refresh/only-export-components export const NamespaceDetailConfigContext = createContext({}); const NamespaceDetailContainer = styled(Grid)(({ theme }: { theme: Theme }) => ({ flex: 5, padding: theme.spacing(0, 1), [theme.breakpoints.only('md')]: { width: '80%' }, [theme.breakpoints.down('sm')]: { width: '100%' } })); const WarningPaper = styled(Paper)(({ theme }: { theme: Theme }) => ({ maxWidth: '800px', margin: `0 ${theme.spacing(6)} ${theme.spacing(4)} ${theme.spacing(6)}`, padding: theme.spacing(2), display: 'flex', [theme.breakpoints.down('sm')]: { margin: `0 0 ${theme.spacing(2)} 0`, } })); const NamespaceHeader = styled(Box)(({ theme }: { theme: Theme }) => ({ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: theme.spacing(1), [theme.breakpoints.down('sm')]: { flexDirection: 'column', alignItems: 'center' } })); export const NamespaceDetail: FunctionComponent = props => { const [changeDialogIsOpen, setChangeDialogIsOpen] = useState(false); const [deleteDialogIsOpen, setDeleteDialogIsOpen] = useState(false); const { pathname } = useLocation(); const handleCloseChangeDialog = async () => { setChangeDialogIsOpen(false); }; const handleOpenChangeDialog = () => { setChangeDialogIsOpen(true); }; const handleCloseDeleteDialog = async () => { setDeleteDialogIsOpen(false); }; const handleDeletedNamespace = async () => { setDeleteDialogIsOpen(false); if (props.onDelete !== undefined) { props.onDelete(); } }; const handleOpenDeleteDialog = () => { setDeleteDialogIsOpen(true); }; const warningColor = props.theme === 'dark' ? '#fff' : '#151515'; return <> { !props.namespace.verified && props.namespaceAccessUrl ? This namespace is not verified. See the documentation to learn about claiming namespaces. : null } {props.namespace.name} { pathname.startsWith(AdminDashboardRoutes.NAMESPACE_ADMIN) ? { Object.keys(props.namespace.extensions).length === 0 && } : null } { props.namespace.membersUrl ? : null } { props.namespace.detailsUrl ? : null } ; }; export interface NamespaceDetailProps { namespace: Namespace; filterUsers: (user: UserData) => boolean; fixSelf: boolean; setLoadingState: (loading: boolean) => void; namespaceAccessUrl?: string; theme?: string; onDelete?: () => void; }