refactor: remove redux, some rearrangement
This commit is contained in:
@@ -18,15 +18,12 @@
|
||||
"@material-ui/core": "^4.9.1",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@material-ui/lab": "4.0.0-alpha.45",
|
||||
"@rematch/core": "^1.4.0",
|
||||
"@types/react-lazylog": "^4.5.0",
|
||||
"@types/react-redux": "^7.1.8",
|
||||
"circleci-api": "^4.0.0",
|
||||
"moment": "^2.25.3",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"react-lazylog": "^4.5.2",
|
||||
"react-redux": "^7.2.0",
|
||||
"react-router": "^5.1.2",
|
||||
"react-router-dom": "^5.1.2",
|
||||
"react-use": "^13.0.0"
|
||||
|
||||
@@ -13,40 +13,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import React, { FC, useReducer, Dispatch } from 'react';
|
||||
import React, { FC, useReducer, Dispatch, Reducer } from 'react';
|
||||
import { circleCIApiRef } from '../../api';
|
||||
import { BuildSummary, BuildWithSteps } from 'circleci-api';
|
||||
import { State, PollingState, Action, SettingsState } from './types';
|
||||
export { SettingsState };
|
||||
|
||||
export const AppContext = React.createContext<[AppState, Dispatch<Action>]>(
|
||||
export const AppContext = React.createContext<[State, Dispatch<Action>]>(
|
||||
[] as any,
|
||||
);
|
||||
|
||||
type SettingsState = {
|
||||
owner: string;
|
||||
repo: string;
|
||||
token: string;
|
||||
};
|
||||
|
||||
export enum PollingState {
|
||||
Polling,
|
||||
Idle,
|
||||
}
|
||||
|
||||
export type BuildsState = {
|
||||
builds: BuildSummary[];
|
||||
pollingIntervalId: number | null;
|
||||
pollingState: PollingState;
|
||||
};
|
||||
|
||||
export const STORAGE_KEY = `${circleCIApiRef.id}.settings`;
|
||||
|
||||
export type AppState = {
|
||||
settings: SettingsState;
|
||||
builds: BuildsState;
|
||||
buildsWithSteps: BuildsWithStepsState;
|
||||
};
|
||||
|
||||
const initialState: AppState = {
|
||||
const initialState: State = {
|
||||
settings: {
|
||||
owner: '',
|
||||
repo: '',
|
||||
@@ -65,45 +42,7 @@ const initialState: AppState = {
|
||||
},
|
||||
};
|
||||
|
||||
type SettingsAction = {
|
||||
type: 'setCredentials';
|
||||
payload: {
|
||||
repo: string;
|
||||
owner: string;
|
||||
token: string;
|
||||
};
|
||||
};
|
||||
|
||||
type BuildsAction =
|
||||
| {
|
||||
type: 'setBuilds';
|
||||
payload: BuildSummary[];
|
||||
}
|
||||
| {
|
||||
type: 'setPollingIntervalId';
|
||||
payload: number | null;
|
||||
};
|
||||
|
||||
type BuildsWithStepsAction =
|
||||
| {
|
||||
type: 'setBuildWithSteps';
|
||||
payload: BuildWithSteps;
|
||||
}
|
||||
| {
|
||||
type: 'setPollingIntervalIdForBuildsWithSteps';
|
||||
payload: number | null;
|
||||
};
|
||||
|
||||
export type BuildsWithStepsState = {
|
||||
builds: Record<number, BuildWithSteps>;
|
||||
pollingIntervalId: number | null;
|
||||
pollingState: PollingState;
|
||||
getBuildError: Error | null;
|
||||
};
|
||||
|
||||
type Action = SettingsAction | BuildsAction | BuildsWithStepsAction;
|
||||
|
||||
const reducer = (state: AppState, action: Action): AppState => {
|
||||
const reducer: Reducer<State, Action> = (state, action) => {
|
||||
switch (action.type) {
|
||||
case 'setCredentials':
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { BuildSummary, BuildWithSteps } from '../../api';
|
||||
|
||||
export type SettingsState = {
|
||||
owner: string;
|
||||
repo: string;
|
||||
token: string;
|
||||
};
|
||||
|
||||
export enum PollingState {
|
||||
Polling,
|
||||
Idle,
|
||||
}
|
||||
|
||||
export type BuildsState = {
|
||||
builds: BuildSummary[];
|
||||
pollingIntervalId: number | null;
|
||||
pollingState: PollingState;
|
||||
};
|
||||
|
||||
export type State = {
|
||||
settings: SettingsState;
|
||||
builds: BuildsState;
|
||||
buildsWithSteps: BuildsWithStepsState;
|
||||
};
|
||||
|
||||
type SettingsAction = {
|
||||
type: 'setCredentials';
|
||||
payload: {
|
||||
repo: string;
|
||||
owner: string;
|
||||
token: string;
|
||||
};
|
||||
};
|
||||
|
||||
type BuildsAction =
|
||||
| {
|
||||
type: 'setBuilds';
|
||||
payload: BuildSummary[];
|
||||
}
|
||||
| {
|
||||
type: 'setPollingIntervalId';
|
||||
payload: number | null;
|
||||
};
|
||||
|
||||
type BuildsWithStepsAction =
|
||||
| {
|
||||
type: 'setBuildWithSteps';
|
||||
payload: BuildWithSteps;
|
||||
}
|
||||
| {
|
||||
type: 'setPollingIntervalIdForBuildsWithSteps';
|
||||
payload: number | null;
|
||||
};
|
||||
|
||||
export type BuildsWithStepsState = {
|
||||
builds: Record<number, BuildWithSteps>;
|
||||
pollingIntervalId: number | null;
|
||||
pollingState: PollingState;
|
||||
getBuildError: Error | null;
|
||||
};
|
||||
|
||||
export type Action = SettingsAction | BuildsAction | BuildsWithStepsAction;
|
||||
@@ -17,7 +17,7 @@ import { errorApiRef, useApi } from '@backstage/core';
|
||||
import { GitType } from 'circleci-api';
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { circleCIApiRef } from '../../api/index';
|
||||
import { AppContext, BuildsState } from '../../components/Store';
|
||||
import { AppContext } from '../../components/Store';
|
||||
|
||||
export type BuildsDispatch = {
|
||||
restartBuild: (buildId: number) => Promise<void>;
|
||||
@@ -25,7 +25,7 @@ export type BuildsDispatch = {
|
||||
|
||||
const INTERVAL_AMOUNT = 3000;
|
||||
|
||||
export function useBuilds(): [BuildsState, BuildsDispatch] {
|
||||
export function useBuilds() {
|
||||
const [{ builds, settings }, dispatch] = useContext(AppContext);
|
||||
const api = useApi(circleCIApiRef);
|
||||
const errorApi = useApi(errorApiRef);
|
||||
@@ -98,5 +98,5 @@ export function useBuilds(): [BuildsState, BuildsDispatch] {
|
||||
{
|
||||
restartBuild,
|
||||
},
|
||||
];
|
||||
] as const;
|
||||
}
|
||||
|
||||
@@ -14,19 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { AppContext, STORAGE_KEY } from '../../components/Store';
|
||||
import { AppContext, STORAGE_KEY, SettingsState } from '../../components/Store';
|
||||
import { useApi, errorApiRef } from '@backstage/core';
|
||||
|
||||
export type SettingsDispatch = {
|
||||
saveSettings: (settings: SettingsState) => void;
|
||||
};
|
||||
|
||||
export type SettingsState = {
|
||||
token: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
};
|
||||
|
||||
// type Effect = {
|
||||
// type: 'rehydrate',
|
||||
// payload: any
|
||||
@@ -35,7 +25,7 @@ export type SettingsState = {
|
||||
// const effects = [];
|
||||
// pushEffect, popEffect
|
||||
|
||||
export function useSettings(): [SettingsState, SettingsDispatch] {
|
||||
export function useSettings() {
|
||||
const [{ settings }, dispatch] = useContext(AppContext);
|
||||
|
||||
// const interpret = eff => {
|
||||
@@ -69,6 +59,7 @@ export function useSettings(): [SettingsState, SettingsDispatch] {
|
||||
errorApi.post(error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
rehydrate();
|
||||
}, []);
|
||||
@@ -88,5 +79,5 @@ export function useSettings(): [SettingsState, SettingsDispatch] {
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
] as const;
|
||||
}
|
||||
|
||||
@@ -2740,13 +2740,6 @@
|
||||
prop-types "^15.6.1"
|
||||
react-lifecycles-compat "^3.0.4"
|
||||
|
||||
"@rematch/core@^1.4.0":
|
||||
version "1.4.0"
|
||||
resolved "https://registry.npmjs.org/@rematch/core/-/core-1.4.0.tgz#686ce814e1cf125029c5e9fba23ef3ab7c3eb2a7"
|
||||
integrity sha512-1zy9cTYxbvDHP0PwIL1QqkwagCEnqA0uWMmPf8v2BYvLi2OsxIfX1xiV+vCP3sdJAjjZ0b9+IbSmj0DL2MEgLQ==
|
||||
dependencies:
|
||||
redux "^4.0.5"
|
||||
|
||||
"@rollup/plugin-commonjs@^11.0.2":
|
||||
version "11.0.2"
|
||||
resolved "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-11.0.2.tgz#837cc6950752327cb90177b608f0928a4e60b582"
|
||||
@@ -4090,14 +4083,6 @@
|
||||
resolved "https://registry.npmjs.org/@types/history/-/history-4.7.5.tgz#527d20ef68571a4af02ed74350164e7a67544860"
|
||||
integrity sha512-wLD/Aq2VggCJXSjxEwrMafIP51Z+13H78nXIX0ABEuIGhmB5sNGbR113MOKo+yfw+RDo1ZU3DM6yfnnRF/+ouw==
|
||||
|
||||
"@types/hoist-non-react-statics@^3.3.0":
|
||||
version "3.3.1"
|
||||
resolved "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
|
||||
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
|
||||
dependencies:
|
||||
"@types/react" "*"
|
||||
hoist-non-react-statics "^3.3.0"
|
||||
|
||||
"@types/html-minifier@*":
|
||||
version "3.5.3"
|
||||
resolved "https://registry.npmjs.org/@types/html-minifier/-/html-minifier-3.5.3.tgz#5276845138db2cebc54c789e0aaf87621a21e84f"
|
||||
@@ -4343,16 +4328,6 @@
|
||||
"@types/react" "*"
|
||||
immutable ">=3.8.2"
|
||||
|
||||
"@types/react-redux@^7.1.8":
|
||||
version "7.1.8"
|
||||
resolved "https://registry.npmjs.org/@types/react-redux/-/react-redux-7.1.8.tgz#3631feb559f7858d6ad9eea1d6ef41fa64fe7205"
|
||||
integrity sha512-kpplH7Wg2SYU00sZVT98WBN0ou6QKrYcShRaW+5Vpe5l7bluKWJbWmAL+ieiso07OQzpcP5i1PeY3690640ZWg==
|
||||
dependencies:
|
||||
"@types/hoist-non-react-statics" "^3.3.0"
|
||||
"@types/react" "*"
|
||||
hoist-non-react-statics "^3.3.0"
|
||||
redux "^4.0.0"
|
||||
|
||||
"@types/react-router-dom@^5.1.3":
|
||||
version "5.1.3"
|
||||
resolved "https://registry.npmjs.org/@types/react-router-dom/-/react-router-dom-5.1.3.tgz#b5d28e7850bd274d944c0fbbe5d57e6b30d71196"
|
||||
@@ -17713,7 +17688,7 @@ react-popper@^1.3.6:
|
||||
typed-styles "^0.0.7"
|
||||
warning "^4.0.2"
|
||||
|
||||
react-redux@^7.0.3, react-redux@^7.2.0:
|
||||
react-redux@^7.0.3:
|
||||
version "7.2.0"
|
||||
resolved "https://registry.npmjs.org/react-redux/-/react-redux-7.2.0.tgz#f970f62192b3981642fec46fd0db18a074fe879d"
|
||||
integrity sha512-EvCAZYGfOLqwV7gh849xy9/pt55rJXPwmYvI4lilPM5rUT/1NxuuN59ipdBksRVSvz0KInbPnp4IfoXJXCqiDA==
|
||||
@@ -18179,7 +18154,7 @@ redeyed@~2.1.0:
|
||||
dependencies:
|
||||
esprima "~4.0.0"
|
||||
|
||||
redux@^4.0.0, redux@^4.0.1, redux@^4.0.5:
|
||||
redux@^4.0.1:
|
||||
version "4.0.5"
|
||||
resolved "https://registry.npmjs.org/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"
|
||||
integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w==
|
||||
|
||||
Reference in New Issue
Block a user