Skip to content

Commit

Permalink
fix: handle no profiles in config
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak committed Nov 12, 2024
1 parent 55dc59d commit 0c96bae
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
43 changes: 27 additions & 16 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function App() {
const fitAddon = useRef(new FitAddon())
const { instance, ref } = useXTerm()
const [isTerminalHidden, setIsTerminalHidden] = useState(true)
const [startingServer, setStartingServer] = useState(false)
const client = useDockerClient()

useEffect(() => {
Expand All @@ -44,6 +45,7 @@ export function App() {

const onStartServer = async () => {
setIsTerminalHidden(false)
setStartingServer(true)
try {
await new Promise<void>((resolve, reject) => {
const result = client?.extension.host?.cli.exec(
Expand Down Expand Up @@ -85,7 +87,7 @@ export function App() {
<RouterProvider router={router} />
) : (
<>
{workspaceApiClient ? (
{workspaceApiClient || daytonaConfig?.activeProfile === '' ? (
<Box
display="flex"
flexDirection="column"
Expand All @@ -94,21 +96,30 @@ export function App() {
padding="48px 32px"
>
<Typography variant="h5">
Daytona server is not running
{startingServer
? 'Starting the Daytona Server...'
: 'Daytona Server is not running'}
</Typography>
{daytonaConfig?.activeProfile === 'default' && (
<Button
variant="contained"
onClick={onStartServer}
size="large"
>
Start Server
</Button>
)}
<Typography variant="h6" mt={4}>
You can switch to a different profile
</Typography>
<SwitchProfile />
{(daytonaConfig?.activeProfile === 'default' ||
!daytonaConfig?.activeProfile) &&
isTerminalHidden && (
<Button
variant="contained"
onClick={onStartServer}
size="large"
>
Start Server
</Button>
)}
{daytonaConfig?.profiles &&
daytonaConfig?.profiles.length > 1 && (
<>
<Typography variant="h6" mt={4}>
You can switch to a different profile
</Typography>
<SwitchProfile />
</>
)}
</Box>
) : (
<Grid
Expand All @@ -134,7 +145,7 @@ export function App() {
<Box
ref={ref}
width={'100%'}
hidden={isServerRuning || !workspaceApiClient || isTerminalHidden}
hidden={isServerRuning || isTerminalHidden}
/>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/shared/SwitchProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SwitchProfile = ({ disabled }: { disabled?: boolean }) => {
}

const profiles = useMemo(() => {
return daytonaConfig?.profiles.filter(
return daytonaConfig?.profiles?.filter(
(profile) => profile.name !== daytonaConfig?.activeProfile,
)
}, [daytonaConfig])
Expand Down
2 changes: 1 addition & 1 deletion client/src/providers/ApiClientProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ApiClientProvider = ({ children }: { children: ReactNode }) => {

const activeProfileConfig = useMemo(() => {
if (daytonaConfig) {
return daytonaConfig.profiles.find(
return daytonaConfig.profiles?.find(
(p) => p.name === daytonaConfig.activeProfile,
)
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/providers/DaytonaConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface IDaytonaConfig {
id: string
activeProfile: string
defaultIde: string
profiles: IDaytonaConfigProfile[]
profiles?: IDaytonaConfigProfile[]
}

const DaytonaConfigContext = createContext<{
Expand Down

0 comments on commit 0c96bae

Please sign in to comment.