Skip to content

Commit

Permalink
Merge pull request #1396 from jdi-testing/issue_1344
Browse files Browse the repository at this point in the history
issue 1344: improve versions errors handling
  • Loading branch information
MariiaNebesnova authored Jul 24, 2023
2 parents aec184f + 2f0f119 commit 7fd5f6e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/app/components/Guide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useDispatch, useSelector } from "react-redux";
import readme from "../../../README.md";
import { BackendStatus } from "../types/mainSlice.types";
import { RootState } from "../store/store";
import { defineServer } from "../reducers/defineServer.thunk";
import { useGuideRehype } from "../utils/useGuideRehype";
import { redefineServer } from "../reducers/redefineServer.thunk";

const splitMD = (source: string) => source.match(/^#+ [^#]*/gm);

Expand All @@ -19,10 +19,8 @@ const serverGuide = (splittedMD: Array<string>) =>

export const Guide = () => {
const backendStatus = useSelector((_state: RootState) => _state.main.backendAvailable);
const step =
backendStatus === BackendStatus.OutdatedServerLocal || backendStatus === BackendStatus.AccessFailed ? 1 : 0;
const [isSettingsChecking, setSettingsChecking] = useState(false);
const [currentStep, setCurrentStep] = useState(step);
const isSettingsChecking = backendStatus === BackendStatus.Retry;
const [currentStep, setCurrentStep] = useState(0);
const [pluginGuideComponent, setPluginGuide] = useGuideRehype();
const [serverGuideComponent, setServerGuide] = useGuideRehype();
const dispatch = useDispatch();
Expand All @@ -34,6 +32,13 @@ export const Guide = () => {
setServerGuide(serverGuide(splittedMD));
}, []);

useEffect(() => {
if (backendStatus === BackendStatus.Retry) return;
const _step =
backendStatus === BackendStatus.OutdatedServerLocal || backendStatus === BackendStatus.AccessFailed ? 1 : 0;
setCurrentStep(_step);
}, [backendStatus]);

const steps = [
{
title: "Step 1",
Expand Down Expand Up @@ -65,8 +70,7 @@ export const Guide = () => {
};

const onCheckButtonClick = async () => {
setSettingsChecking(true);
dispatch(defineServer());
dispatch(redefineServer());
};

return (
Expand Down
3 changes: 2 additions & 1 deletion src/app/main.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineServerReducer } from "./reducers/defineServer.thunk";
import { PageObjectId } from "../features/pageObjects/types/pageObjectSlice.types";
import { BackendStatus, MainState, Notification, PageType } from "./types/mainSlice.types";
import { removeAllReducer } from "./reducers/removeAll.thunk";
import { redefineServerReducer } from "./reducers/redefineServer.thunk";

const initialState: MainState = {
backendAvailable: BackendStatus.TryToAccess,
Expand Down Expand Up @@ -62,7 +63,7 @@ const mainSlice = createSlice({
},
},
extraReducers: (builder) => {
defineServerReducer(builder), removeAllReducer(builder);
defineServerReducer(builder), redefineServerReducer(builder), removeAllReducer(builder);
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/app/reducers/defineServer.thunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toInteger } from "lodash";
import { BackendStatus, BaseUrl, MainState } from "../types/mainSlice.types";
import { LocalUrl, RemoteUrl } from "../utils/constants";
import { HttpEndpoint, request } from "../../services/backend";
import { compatibleBuildVer, compatibleMajorVer, compatibleMinorVer } from "../../common/constants/compatibleVersions";
import { compatibleBuildVer, compatibleMajorVer, compatibleMinorVer } from "../utils/compatibleVersions";

export const defineServer = createAsyncThunk("main/defineServer", async () => {
const checkVersion = (request: Promise<AxiosResponse<BaseUrl>>, isRemote: boolean) =>
Expand Down
13 changes: 13 additions & 0 deletions src/app/reducers/redefineServer.thunk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ActionReducerMapBuilder, createAsyncThunk } from "@reduxjs/toolkit";
import { BackendStatus, MainState } from "../types/mainSlice.types";
import { defineServer } from "./defineServer.thunk";

export const redefineServer = createAsyncThunk("main/redefineServer", async (_, thunkApi) => {
thunkApi.dispatch(defineServer());
});

export const redefineServerReducer = (builder: ActionReducerMapBuilder<MainState>) => {
return builder.addCase(redefineServer.pending, (state) => {
state.backendAvailable = BackendStatus.Retry;
});
};
1 change: 1 addition & 0 deletions src/app/types/mainSlice.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export enum BackendStatus {
OutdatedPluginLocal = "Plugin version need to be updated.",
IncompatibleVersionRemote = "Remote server version is incompatible. Please, update plugin",
IncompatibleVersions = "Remote and local server versions are incompatible. Please, update plugin or local server, or try to connect the remote server.",
Retry = "Retrying...",
}

export enum PageType {
Expand Down
File renamed without changes.

0 comments on commit 7fd5f6e

Please sign in to comment.