Skip to content

Commit

Permalink
replace VIEWER_IMPORTING with conversionStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Dec 12, 2023
1 parent 09652c1 commit 8e08476
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
18 changes: 7 additions & 11 deletions src/components/LoadFileMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import TRAJECTORIES from "../../constants/networked-trajectories";
import { URL_PARAM_KEY_FILE_NAME } from "../../constants";
import {
ClearSimFileDataAction,
ConvertFileAction,
ConversionStatus,
RequestLocalFileAction,
RequestNetworkFileAction,
} from "../../state/trajectory/types";
Expand All @@ -18,11 +18,10 @@ import { DownArrow } from "../Icons";
import {
SetErrorAction,
SetViewerStatusAction,
ViewerStatus,
} from "../../state/viewer/types";

import styles from "./style.css";
import { VIEWER_IMPORTING } from "../../state/viewer/constants";
import { CONVERSION_INACTIVE } from "../../state/trajectory/constants";

interface LoadFileMenuProps {
isBuffering: boolean;
Expand All @@ -31,8 +30,7 @@ interface LoadFileMenuProps {
loadLocalFile: ActionCreator<RequestLocalFileAction>;
setViewerStatus: ActionCreator<SetViewerStatusAction>;
setError: ActionCreator<SetErrorAction>;
initializeFileConversionUI: ActionCreator<ConvertFileAction>;
viewerStatus: ViewerStatus;
conversionStatus: ConversionStatus;
}

const LoadFileMenu = ({
Expand All @@ -42,8 +40,7 @@ const LoadFileMenu = ({
selectFile,
setViewerStatus,
setError,
viewerStatus,
initializeFileConversionUI: initializeFileConversionUI,
conversionStatus,
}: LoadFileMenuProps): JSX.Element => {
const [isModalVisible, setIsModalVisible] = useState(false);
const location = useLocation();
Expand Down Expand Up @@ -102,9 +99,6 @@ const LoadFileMenu = ({
to={{
pathname: IMPORT_PATHNAME,
}}
onClick={() => {
initializeFileConversionUI();
}}
>
Import other file type
</Link>
Expand All @@ -117,7 +111,9 @@ const LoadFileMenu = ({
<Dropdown
menu={{ items, theme: "dark", className: styles.menu }}
placement="bottomRight"
disabled={isBuffering || viewerStatus === VIEWER_IMPORTING}
disabled={
isBuffering || conversionStatus !== CONVERSION_INACTIVE
}
>
<Button
className="ant-dropdown-link"
Expand Down
16 changes: 6 additions & 10 deletions src/containers/AppHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { connect } from "react-redux";

import {
ClearSimFileDataAction,
ConvertFileAction,
ConversionStatus,
isLocalFileInterface,
isNetworkSimFileInterface,
LocalSimFile,
Expand All @@ -23,7 +23,6 @@ import viewerStateBranch from "../../state/viewer";
import {
SetViewerStatusAction,
SetErrorAction,
ViewerStatus,
} from "../../state/viewer/types";

import styles from "./style.css";
Expand All @@ -37,8 +36,7 @@ interface AppHeaderProps {
changeToNetworkedFile: ActionCreator<RequestNetworkFileAction>;
setViewerStatus: ActionCreator<SetViewerStatusAction>;
setError: ActionCreator<SetErrorAction>;
convertFile: ActionCreator<ConvertFileAction>;
viewerStatus: ViewerStatus;
conversionStatus: ConversionStatus;
}

class AppHeader extends React.Component<AppHeaderProps> {
Expand All @@ -48,11 +46,10 @@ class AppHeader extends React.Component<AppHeaderProps> {
isBuffering,
changeToLocalSimulariumFile: loadLocalFile,
changeToNetworkedFile: loadNetworkFile,
convertFile,
setViewerStatus,
clearSimulariumFile,
setError,
viewerStatus,
conversionStatus,
} = this.props;
let lastModified = 0;
let displayName = "";
Expand Down Expand Up @@ -86,8 +83,7 @@ class AppHeader extends React.Component<AppHeaderProps> {
setViewerStatus={setViewerStatus}
isBuffering={isBuffering}
setError={setError}
initializeFileConversionUI={convertFile}
viewerStatus={viewerStatus}
conversionStatus={conversionStatus}
/>
<HelpMenu key="help" />
<div className={styles.pipe}>|</div>
Expand All @@ -106,7 +102,8 @@ function mapStateToProps(state: State) {
simulariumFile:
trajectoryStateBranch.selectors.getSimulariumFile(state),
isBuffering: viewerStateBranch.selectors.getIsBuffering(state),
viewerStatus: viewerStateBranch.selectors.getStatus(state),
conversionStatus:
trajectoryStateBranch.selectors.getConversionStatus(state),
};
}

Expand All @@ -117,7 +114,6 @@ const dispatchToPropsMap = {
clearSimulariumFile: trajectoryStateBranch.actions.clearSimulariumFile,
setViewerStatus: viewerStateBranch.actions.setStatus,
setError: viewerStateBranch.actions.setError,
convertFile: trajectoryStateBranch.actions.convertFile,
};

export default connect(mapStateToProps, dispatchToPropsMap)(AppHeader);
8 changes: 5 additions & 3 deletions src/containers/ConversionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import trajectoryStateBranch from "../../state/trajectory";
import viewerStateBranch from "../../state/viewer";
import {
ConversionStatus,
InitializeConversionAction,
ReceiveFileToConvertAction,
SetConversionEngineAction,
} from "../../state/trajectory/types";
Expand Down Expand Up @@ -39,6 +40,7 @@ interface ConversionProps {
};
receiveFileToConvert: ActionCreator<ReceiveFileToConvertAction>;
setError: ActionCreator<SetErrorAction>;
initializeConversion: ActionCreator<InitializeConversionAction>;
conversionStatus: ConversionStatus;
}

Expand All @@ -65,6 +67,7 @@ const ConversionForm = ({
conversionProcessingData,
setError,
receiveFileToConvert,
initializeConversion,
conversionStatus,
}: ConversionProps): JSX.Element => {
const [fileToConvert, setFileToConvert] = useState<UploadFile>();
Expand All @@ -74,10 +77,8 @@ const ConversionForm = ({
const [isProcessing, setIsProcessing] = useState<boolean>(false);
const [fileTypeErrorModalOpen, setFileTypeErrorModalOpen] = useState(false);

// On load, configure controller and check if server is healthy
useEffect(() => {
// calling this with null payload configures the controller and checks server health
receiveFileToConvert(null);
initializeConversion();
}, []);

// TODO delete after development, useEffect to log a change in server health
Expand Down Expand Up @@ -236,6 +237,7 @@ const dispatchToPropsMap = {
receiveFileToConvert: trajectoryStateBranch.actions.receiveFileToConvert,
setError: viewerStateBranch.actions.setError,
setConversionEngine: trajectoryStateBranch.actions.setConversionEngine,
initializeConversion: trajectoryStateBranch.actions.initializeConversion,
};

export default connect(mapStateToProps, dispatchToPropsMap)(ConversionForm);
2 changes: 0 additions & 2 deletions src/containers/ModelPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import {
VIEWER_EMPTY,
VIEWER_ERROR,
VIEWER_IMPORTING,
VIEWER_LOADING,
VIEWER_SUCCESS,
} from "../../state/viewer/constants";
Expand Down Expand Up @@ -96,7 +95,6 @@ class ModelPanel extends React.Component<ModelPanelProps> {
[VIEWER_SUCCESS]: checkboxTree,
[VIEWER_EMPTY]: <NoTrajectoriesText selectFile={loadNetworkFile} />,
[VIEWER_LOADING]: <div />,
[VIEWER_IMPORTING]: <div />,
[VIEWER_ERROR]: isNetworkedFile ? (
<NetworkFileFailedText />
) : (
Expand Down
10 changes: 7 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ const { Header } = Layout;

import "./style.css";
import { setIsPlaying, setStatus } from "./state/viewer/actions";
import { clearSimulariumFile } from "./state/trajectory/actions";
import { VIEWER_EMPTY, VIEWER_IMPORTING } from "./state/viewer/constants";
import {
clearSimulariumFile,
setConversionStatus,
} from "./state/trajectory/actions";
import { VIEWER_EMPTY } from "./state/viewer/constants";
import { CONVERSION_NO_SERVER } from "./state/trajectory/constants";

export const store = createReduxStore();
interface LocationWithState extends Location {
Expand All @@ -36,7 +40,7 @@ function useLocationChange() {
if (location.pathname === IMPORT_PATHNAME) {
batch(() => {
dispatch(setIsPlaying(false));
dispatch(setStatus({ status: VIEWER_IMPORTING }));
dispatch(setConversionStatus({ status: CONVERSION_NO_SERVER }));
});
} else if (location.pathname === VIEWER_PATHNAME) {
batch(() => {
Expand Down
1 change: 0 additions & 1 deletion src/state/viewer/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ export const VIEWER_EMPTY = "empty";
export const VIEWER_LOADING = "loading";
export const VIEWER_ERROR = "error";
export const VIEWER_SUCCESS = "success";
export const VIEWER_IMPORTING = "importing";
5 changes: 1 addition & 4 deletions src/state/viewer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
VIEWER_ERROR,
VIEWER_EMPTY,
VIEWER_SUCCESS,
VIEWER_IMPORTING,
} from "./constants";

export interface ViewerStateBranch {
Expand Down Expand Up @@ -46,10 +45,8 @@ type VIEWER_LOADING = typeof VIEWER_LOADING;
type VIEWER_ERROR = typeof VIEWER_ERROR;
type VIEWER_EMPTY = typeof VIEWER_EMPTY;
type VIEWER_SUCCESS = typeof VIEWER_SUCCESS;
type VIEWER_IMPORTING = typeof VIEWER_IMPORTING;
export type ViewerStatus =
| VIEWER_LOADING
| VIEWER_ERROR
| VIEWER_EMPTY
| VIEWER_SUCCESS
| VIEWER_IMPORTING;
| VIEWER_SUCCESS;

0 comments on commit 8e08476

Please sign in to comment.