mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
update to 4.0
This commit is contained in:
230
web/src/reducer/globalStatusReducer.js
Normal file
230
web/src/reducer/globalStatusReducer.js
Normal file
@@ -0,0 +1,230 @@
|
||||
const defaultStatus = {
|
||||
recording: true,
|
||||
panelRefreshing: true, // indicate whether the record panel should be refreshing
|
||||
showFilter: false, // if the filter panel is showing
|
||||
showMapLocal: false,
|
||||
activeMenuKey: '',
|
||||
canLoadMore: false,
|
||||
interceptHttpsFlag: false,
|
||||
globalProxyFlag: false, // is global proxy now
|
||||
filterStr: '',
|
||||
directory: [],
|
||||
lastActiveRecordId: -1,
|
||||
currentActiveRecordId: -1,
|
||||
shouldClearAllRecord: false,
|
||||
appVersion: '',
|
||||
panelLoadingNext: false,
|
||||
panelLoadingPrev: false,
|
||||
showNewRecordTip: false,
|
||||
isRootCAFileExists: false,
|
||||
fetchingRecord: false,
|
||||
wsPort: null,
|
||||
mappedConfig:[] // configured map config
|
||||
};
|
||||
|
||||
import { MenuKeyMap } from 'common/Constant';
|
||||
|
||||
import {
|
||||
STOP_RECORDING,
|
||||
RESUME_RECORDING,
|
||||
SHOW_FILTER,
|
||||
HIDE_FILTER,
|
||||
UPDATE_FILTER,
|
||||
UPDATE_LOCAL_DIRECTORY,
|
||||
SHOW_MAP_LOCAL,
|
||||
HIDE_MAP_LOCAL,
|
||||
UPDATE_LOCAL_MAPPED_CONFIG,
|
||||
UPDATE_ACTIVE_RECORD_ITEM,
|
||||
UPDATE_LOCAL_INTERCEPT_HTTPS_FLAG,
|
||||
UPDATE_LOCAL_GLOBAL_PROXY_FLAG,
|
||||
HIDE_ROOT_CA,
|
||||
SHOW_ROOT_CA,
|
||||
UPDATE_CAN_LOAD_MORE,
|
||||
INCREASE_DISPLAY_RECORD_LIST,
|
||||
UPDATE_SHOULD_CLEAR_RECORD,
|
||||
UPDATE_APP_VERSION,
|
||||
UPDATE_IS_ROOTCA_EXISTS,
|
||||
UPDATE_SHOW_NEW_RECORD_TIP,
|
||||
UPDATE_GLOBAL_WSPORT,
|
||||
UPDATE_FETCHING_RECORD_STATUS
|
||||
} from 'action/globalStatusAction';
|
||||
|
||||
// The map to save the mapping relationships of the path and it's location in the tree node
|
||||
const directoryNodeMap = {};
|
||||
|
||||
// The map to store all the directory in a tree way
|
||||
let direcotryList = [];
|
||||
|
||||
function getTreeMap(path, sub) {
|
||||
|
||||
const children = [];
|
||||
sub.directory.forEach((item) => {
|
||||
if (!(item.name.indexOf('.') === 0)) {
|
||||
item.isLeaf = false;
|
||||
directoryNodeMap[item.fullPath] = item;
|
||||
children.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
sub.file.forEach((item) => {
|
||||
if (!(item.name.indexOf('.') === 0)) {
|
||||
item.isLeaf = true;
|
||||
directoryNodeMap[item.fullPath] = item;
|
||||
children.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
if (!path) {
|
||||
direcotryList = children;
|
||||
} else {
|
||||
directoryNodeMap[path].children = children;
|
||||
}
|
||||
|
||||
return direcotryList;
|
||||
}
|
||||
|
||||
function requestListReducer(state = defaultStatus, action) {
|
||||
switch (action.type) {
|
||||
case STOP_RECORDING: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.recording = false;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case RESUME_RECORDING: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.recording = true;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case SHOW_FILTER: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.activeMenuKey = MenuKeyMap.RECORD_FILTER;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case HIDE_FILTER: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.activeMenuKey = '';
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_FILTER: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.filterStr = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case SHOW_MAP_LOCAL: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.activeMenuKey = MenuKeyMap.MAP_LOCAL;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case HIDE_MAP_LOCAL: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.activeMenuKey = '';
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_LOCAL_DIRECTORY: {
|
||||
const newState = Object.assign({}, state);
|
||||
const { path, sub } = action.data;
|
||||
|
||||
newState.directory = getTreeMap(path, sub);
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_LOCAL_MAPPED_CONFIG: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.mappedConfig = action.data;
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_ACTIVE_RECORD_ITEM: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.lastActiveRecordId = state.currentActiveRecordId;
|
||||
newState.currentActiveRecordId = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_LOCAL_INTERCEPT_HTTPS_FLAG: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.interceptHttpsFlag = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_LOCAL_GLOBAL_PROXY_FLAG: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.globalProxyFlag = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case SHOW_ROOT_CA: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.activeMenuKey = MenuKeyMap.ROOT_CA;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case HIDE_ROOT_CA: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.activeMenuKey = '';
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_CAN_LOAD_MORE: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.canLoadMore = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_SHOULD_CLEAR_RECORD: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.shouldClearAllRecord = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case INCREASE_DISPLAY_RECORD_LIST: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.displayRecordLimit += action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_APP_VERSION: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.appVersion = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_SHOW_NEW_RECORD_TIP: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.showNewRecordTip = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_IS_ROOTCA_EXISTS: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.isRootCAFileExists = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_GLOBAL_WSPORT: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.wsPort = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_FETCHING_RECORD_STATUS: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.fetchingRecord = action.data;
|
||||
return newState;
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default requestListReducer;
|
||||
120
web/src/reducer/requestRecordReducer.js
Normal file
120
web/src/reducer/requestRecordReducer.js
Normal file
@@ -0,0 +1,120 @@
|
||||
const defaultState = {
|
||||
recordList: [],
|
||||
recordDetail: null
|
||||
};
|
||||
|
||||
import {
|
||||
UPDATE_WHOLE_REQUEST,
|
||||
UPDATE_SINGLE_RECORD,
|
||||
CLEAR_ALL_LOCAL_RECORD,
|
||||
UPDATE_MULTIPLE_RECORDS,
|
||||
SHOW_RECORD_DETAIL,
|
||||
HIDE_RECORD_DETAIL
|
||||
} from 'action/recordAction';
|
||||
|
||||
const getRecordInList = function (recordId, recordList) {
|
||||
const newRecordList = recordList.slice();
|
||||
for (let i = 0; i< newRecordList.length ; i++) {
|
||||
const record = newRecordList[i];
|
||||
if (record.id === recordId) {
|
||||
return record;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function requestListReducer (state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case UPDATE_WHOLE_REQUEST: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.recordList = action.data.slice();
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_SINGLE_RECORD: {
|
||||
|
||||
const newState = Object.assign({}, state);
|
||||
|
||||
const list = newState.recordList.slice();
|
||||
|
||||
list.forEach((item) => {
|
||||
item._render = false;
|
||||
});
|
||||
|
||||
const record = action.data;
|
||||
|
||||
const index = list.findIndex((item) => {
|
||||
return item.id === record.id;
|
||||
});
|
||||
|
||||
if (index >= 0) {
|
||||
// set the mark to ensure the item get re-rendered
|
||||
record._render = true;
|
||||
list[index] = record;
|
||||
} else {
|
||||
list.push(record);
|
||||
}
|
||||
|
||||
newState.recordList = list;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case UPDATE_MULTIPLE_RECORDS: {
|
||||
const newState = Object.assign({}, state);
|
||||
const list = newState.recordList.slice();
|
||||
|
||||
list.forEach((item) => {
|
||||
item._render = false;
|
||||
});
|
||||
|
||||
const records = action.data;
|
||||
records.forEach((record) => {
|
||||
const index = list.findIndex((item) => {
|
||||
return item.id === record.id;
|
||||
});
|
||||
|
||||
if (index >= 0) {
|
||||
// set the mark to ensure the item get re-rendered
|
||||
record._render = true;
|
||||
list[index] = record;
|
||||
} else {
|
||||
list.push(record);
|
||||
}
|
||||
});
|
||||
|
||||
newState.recordList = list;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case CLEAR_ALL_LOCAL_RECORD: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.recordList = [];
|
||||
return newState;
|
||||
}
|
||||
|
||||
case SHOW_RECORD_DETAIL: {
|
||||
const newState = Object.assign({}, state);
|
||||
const responseBody = action.data;
|
||||
const originRecord = getRecordInList(responseBody.id, newState.recordList);
|
||||
// 只在id存在的时候,才更新, 否则取消
|
||||
if (originRecord) {
|
||||
newState.recordDetail = Object.assign(responseBody, originRecord);
|
||||
} else {
|
||||
newState.recordDetail = null;
|
||||
}
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
case HIDE_RECORD_DETAIL: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.recordDetail = null;
|
||||
return newState;
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default requestListReducer;
|
||||
13
web/src/reducer/rootReducer.js
Normal file
13
web/src/reducer/rootReducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import requestRecordReducer from './requestRecordReducer';
|
||||
import globalStatusReducer from './globalStatusReducer';
|
||||
|
||||
const defaultState = {
|
||||
|
||||
};
|
||||
|
||||
export default function(state = defaultState, action) {
|
||||
return {
|
||||
requestRecord: requestRecordReducer(state.requestRecord, action),
|
||||
globalStatus: globalStatusReducer(state.globalStatus, action)
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user