Skip to content

Commit 7b41eac

Browse files
committed
refactor: move render to views for initializing, not running, and running states in App component
1 parent bcb860e commit 7b41eac

File tree

4 files changed

+338
-195
lines changed

4 files changed

+338
-195
lines changed

client/src/App.tsx

Lines changed: 16 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ import {
6363
POSTMAN_CONTAINER
6464
} from './utils/constants';
6565
import { useDockerDesktopClient } from './utils/ddclient';
66+
import InitializingView from './components/views/InitializingView';
67+
import NotRunningView from './components/views/NotRunningView';
68+
import RunningView from './components/views/RunningView';
6669

6770
const isWindows = () => {
6871
const platform = useDockerDesktopClient().host.platform;
@@ -763,203 +766,21 @@ const App = () => {
763766
return (
764767
<Container>
765768
{status === 'INITIALIZING' ? (
766-
<Stack
767-
sx={{
768-
display: 'flex',
769-
flexGrow: 1,
770-
height: '90vh',
771-
alignItems: 'center',
772-
justifyContent: 'center',
773-
}}
774-
spacing={5}
775-
>
776-
<CircularProgress color="primary" />
777-
</Stack>
769+
<InitializingView />
778770
) : status == 'NOT_RUNNING' ? (
779-
<>
780-
<Stack
781-
sx={{
782-
display: 'flex',
783-
flexGrow: 1,
784-
height: '90vh',
785-
alignItems: 'center',
786-
justifyContent: 'center',
787-
}}
788-
>
789-
<Box
790-
m={4}
791-
sx={{
792-
width: 450,
793-
maxWidth: { xs: 450, md: 350 },
794-
}}
795-
component="img"
796-
src={
797-
uiMode === 'light'
798-
? 'assets/images/microcks-logo-blue-baseline-tweet.png'
799-
: 'assets/images/microcks-logo-white-baseline-tweet.png'
800-
}
801-
alt="Microcks Logo"
802-
/>
803-
<Paper
804-
elevation={3}
805-
sx={{
806-
margin: 4,
807-
padding: 2,
808-
width: '100%',
809-
display: 'flex',
810-
flexDirection: 'row',
811-
}}
812-
>
813-
{!appStatus.isRunning && (
814-
<Chip variant="outlined" color="error" label="STOPPED" />
815-
)}
816-
<Box
817-
alignContent="center"
818-
display="flex"
819-
alignItems="center"
820-
mx={1}
821-
>
822-
<RocketLaunchIcon />
823-
</Box>
824-
<Box
825-
flexGrow={1}
826-
alignContent="center"
827-
display="flex"
828-
alignItems="center"
829-
>
830-
<Typography variant="subtitle1">
831-
Microcks is not running. First launch can take some time while
832-
we're pulling the container images.
833-
</Typography>
834-
</Box>
835-
<Box
836-
flexGrow={1}
837-
alignContent="center"
838-
display="flex"
839-
alignItems="center"
840-
></Box>
841-
</Paper>
842-
<Stack m={2} spacing={2} direction="row">
843-
<Button
844-
variant="outlined"
845-
size="large"
846-
startIcon={<SettingsIcon />}
847-
onClick={handleOpenSettings}
848-
>
849-
Settings
850-
</Button>
851-
<Button variant="contained" size="large" onClick={launchMicrocks}>
852-
Launch Microcks
853-
</Button>
854-
</Stack>
855-
</Stack>
856-
<Footer>
857-
{appStatus.exists && (
858-
<Link onClick={deleteMicrocksDialog} component="button">
859-
Delete Microcks
860-
</Link>
861-
)}
862-
</Footer>
863-
</>
771+
<NotRunningView
772+
uiMode={uiMode}
773+
appStatus={appStatus}
774+
onLaunchMicrocks={launchMicrocks}
775+
onOpenSettings={handleOpenSettings}
776+
onDeleteMicrocks={deleteMicrocksDialog}
777+
/>
864778
) : (
865-
<Box
866-
display="flex"
867-
flexDirection="column"
868-
justifyContent="flex-start"
869-
height="95vh"
870-
>
871-
<Box
872-
sx={{ display: 'flex', width: '100%', alignItems: 'center' }}
873-
my={1}
874-
>
875-
<Box alignContent="flex-start" textAlign="left" flexGrow={1}>
876-
<Typography sx={{ fontWeight: 'bolder' }} variant="h5">
877-
Microcks
878-
</Typography>
879-
<Typography variant="subtitle1" color="InactiveCaptionText">
880-
API Mocking and Testing for REST, GraphQL, gRPC and AsyncAPI
881-
</Typography>
882-
</Box>
883-
<Box>
884-
<Tooltip title="Settings">
885-
<IconButton onClick={handleOpenSettings}>
886-
<SettingsIcon />
887-
</IconButton>
888-
</Tooltip>
889-
</Box>
890-
<Box m={2}>
891-
<Button variant="contained" color="error" onClick={stopMicrocks}>
892-
Stop Microcks
893-
</Button>
894-
</Box>
895-
</Box>
896-
<Paper
897-
elevation={3}
898-
sx={{
899-
marginTop: 4,
900-
padding: 2,
901-
width: '100%',
902-
display: 'flex',
903-
flexDirection: 'row',
904-
}}
905-
>
906-
<Chip variant="filled" color="success" label="RUNNING" />
907-
<Box
908-
alignContent="center"
909-
display="flex"
910-
alignItems="center"
911-
mx={1}
912-
>
913-
<DoneOutlinedIcon />
914-
</Box>
915-
<Box
916-
flexGrow={1}
917-
alignContent="center"
918-
display="flex"
919-
alignItems="center"
920-
>
921-
<Typography variant="subtitle1" component="span">
922-
Microcks is running. To access the UI navigate to:{' '}
923-
<Link
924-
onClick={() =>
925-
ddClient.host.openExternal(
926-
`http://localhost:${8080 + config.portOffset}/#/`,
927-
)
928-
}
929-
variant="subtitle1"
930-
component="span"
931-
>
932-
http://localhost:{8080 + config.portOffset}
933-
</Link>
934-
<IconButton
935-
onClick={() =>
936-
ddClient.host.openExternal(
937-
`http://localhost:${8080 + config.portOffset}/#/`,
938-
)
939-
}
940-
component="span"
941-
size="small"
942-
>
943-
<OpenInNewIcon
944-
fontSize="small"
945-
/>
946-
</IconButton>
947-
<ClipboardCopy
948-
copyText={`http://localhost:${8080 + config.portOffset}/#/`}
949-
size="small"
950-
/>
951-
</Typography>
952-
</Box>
953-
</Paper>
954-
<Services config={config} />
955-
<Footer>
956-
{appStatus.exists && (
957-
<Link onClick={deleteMicrocksDialog} component="button">
958-
Delete Microcks
959-
</Link>
960-
)}
961-
</Footer>
962-
</Box>
779+
<RunningView
780+
appStatus={appStatus}
781+
onOpenSettings={handleOpenSettings}
782+
onDeleteMicrocks={deleteMicrocksDialog} config={config} onStopMicrocks={stopMicrocks}
783+
/>
963784
)}
964785
<SettingsDialog
965786
config={config}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright The Microcks Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import React from 'react';
17+
import {
18+
Stack,
19+
CircularProgress,
20+
} from '@mui/material';
21+
22+
const InitializingView: React.FC = () => {
23+
return (
24+
<Stack
25+
sx={{
26+
display: 'flex',
27+
flexGrow: 1,
28+
height: '90vh',
29+
alignItems: 'center',
30+
justifyContent: 'center',
31+
}}
32+
spacing={5}
33+
>
34+
<CircularProgress color="primary" />
35+
</Stack>
36+
);
37+
};
38+
39+
export default InitializingView;

0 commit comments

Comments
 (0)