import React, { useState } from 'react'; import { Box, Title, Tabs, Stack, ActionIcon, Group, Select } from '@mantine/core'; import { IconFunction, IconPlayerPlay, IconStar, IconStarFilled } from '@tabler/icons-react'; import { FunctionList } from './components/FunctionList'; import { FunctionForm } from './components/FunctionForm'; import { ExecutionModal } from './components/ExecutionModal'; import ExecutionList from './components/ExecutionList'; import { FunctionDefinition } from './types'; const App: React.FC = () => { // Determine current route based on pathname const getCurrentRoute = () => { const path = window.location.pathname; if (path.includes('/functions')) return 'functions'; if (path.includes('/executions')) return 'executions'; return 'functions'; }; const [currentRoute, setCurrentRoute] = useState(getCurrentRoute()); const [isFavorited, setIsFavorited] = useState(false); const [selectedColor, setSelectedColor] = useState(''); const [functionFormOpened, setFunctionFormOpened] = useState(false); const [executionModalOpened, setExecutionModalOpened] = useState(false); const [editingFunction, setEditingFunction] = useState(null); const [executingFunction, setExecutingFunction] = useState(null); const [refreshKey, setRefreshKey] = useState(0); // Listen for URL changes (for when the shell navigates) React.useEffect(() => { const handlePopState = () => { setCurrentRoute(getCurrentRoute()); }; window.addEventListener('popstate', handlePopState); return () => window.removeEventListener('popstate', handlePopState); }, []); const handleTabChange = (value: string | null) => { if (value) { // Use history.pushState to update URL and notify shell router const basePath = '/app/faas'; const newPath = `${basePath}/${value}`; // Update the URL and internal state window.history.pushState(null, '', newPath); setCurrentRoute(value); // Dispatch a custom event so shell can respond if needed window.dispatchEvent(new PopStateEvent('popstate', { state: null })); } }; const handleCreateFunction = () => { setEditingFunction(null); setFunctionFormOpened(true); }; const handleEditFunction = (func: FunctionDefinition) => { setEditingFunction(func); setFunctionFormOpened(true); }; const handleExecuteFunction = (func: FunctionDefinition) => { setExecutingFunction(func); setExecutionModalOpened(true); }; const handleFormSuccess = () => { setRefreshKey(prev => prev + 1); }; const handleFormClose = () => { setFunctionFormOpened(false); setEditingFunction(null); }; const handleExecutionClose = () => { setExecutionModalOpened(false); setExecutingFunction(null); }; const toggleFavorite = () => { setIsFavorited(prev => !prev); }; const colorOptions = [ { value: 'red', label: 'Red' }, { value: 'blue', label: 'Blue' }, { value: 'green', label: 'Green' }, { value: 'purple', label: 'Purple' }, { value: 'orange', label: 'Orange' }, { value: 'pink', label: 'Pink' }, { value: 'teal', label: 'Teal' }, ]; const renderContent = () => { switch (currentRoute) { case 'functions': return ( ); case 'executions': return ; default: return ( ); } }; return (
Function as a Service {isFavorited ? ( ) : ( )}
{/* Right-side controls */}