make console function fetchTableListBySchema reusable (#2008)

This commit is contained in:
Rishichandra Wawhal
2019-04-15 16:04:26 +05:30
committed by Rikin Kachhia
parent f567f7f586
commit e94ee34017
6 changed files with 43 additions and 53 deletions

View File

@@ -29,7 +29,6 @@ const FETCH_SCHEMA_LIST = 'Data/FETCH_SCHEMA_LIST';
const UPDATE_CURRENT_SCHEMA = 'Data/UPDATE_CURRENT_SCHEMA';
const ADMIN_SECRET_ERROR = 'Data/ADMIN_SECRET_ERROR';
const UPDATE_DATA_HEADERS = 'Data/UPDATE_DATA_HEADERS';
const UPDATE_MANUAL_REL_TABLE_LIST = 'Data/UPDATE_MANUAL_REL_TABLE_LIST';
const RESET_MANUAL_REL_TABLE_LIST = 'Data/RESET_MANUAL_REL_TABLE_LIST';
const UPDATE_REMOTE_SCHEMA_MANUAL_REL = 'Data/UPDATE_SCHEMA_MANUAL_REL';
@@ -545,7 +544,10 @@ const makeMigrationCall = (
);
};
const fetchTableListBySchema = schemaName => (dispatch, getState) => {
const fetchTableListBySchema = (schemaName, successAction, errorAction) => (
dispatch,
getState
) => {
const url = Endpoints.getSchema;
const options = {
credentials: globalCookiePolicy,
@@ -573,10 +575,15 @@ const fetchTableListBySchema = schemaName => (dispatch, getState) => {
};
return dispatch(requestAction(url, options)).then(
data => {
dispatch({ type: UPDATE_MANUAL_REL_TABLE_LIST, data: data });
if (successAction) {
dispatch({ type: successAction, data });
}
},
error => {
console.error('Failed to load table list' + JSON.stringify(error));
if (errorAction) {
dispatch({ type: errorAction, data: error });
}
}
);
};
@@ -695,20 +702,6 @@ const dataReducer = (state = defaultState, action) => {
},
},
};
case UPDATE_MANUAL_REL_TABLE_LIST:
return {
...state,
modify: {
...state.modify,
relAdd: {
...state.modify.relAdd,
manualRelInfo: {
...state.modify.relAdd.manualRelInfo,
tables: action.data,
},
},
},
};
case RESET_MANUAL_REL_TABLE_LIST:
return {
...state,

View File

@@ -34,6 +34,7 @@ import {
REL_ADD_NEW_CLICKED,
REL_SET_MANUAL_COLUMNS,
REL_ADD_MANUAL_CLICKED,
UPDATE_MANUAL_REL_TABLE_LIST,
} from '../TableRelationships/Actions';
// TABLE PERMISSIONS
@@ -552,6 +553,18 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
fkModify: action.fks,
};
case UPDATE_MANUAL_REL_TABLE_LIST:
return {
...modifyState,
relAdd: {
...modifyState.relAdd,
manualRelInfo: {
...modifyState.relAdd.manualRelInfo,
tables: action.data,
},
},
};
default:
return modifyState;
}

View File

@@ -20,6 +20,8 @@ export const REL_NAME_CHANGED = 'ModifyTable/REL_NAME_CHANGED';
export const REL_ADD_NEW_CLICKED = 'ModifyTable/REL_ADD_NEW_CLICKED';
export const REL_SET_MANUAL_COLUMNS = 'ModifyTable/REL_SET_MANUAL_COLUMNS';
export const REL_ADD_MANUAL_CLICKED = 'ModifyTable/REL_ADD_MANUAL_CLICKED';
export const UPDATE_MANUAL_REL_TABLE_LIST =
'ModifyTable/UPDATE_MANUAL_REL_TABLE_LIST';
const resetRelationshipForm = () => ({ type: REL_RESET });
const addNewRelClicked = () => ({ type: REL_ADD_NEW_CLICKED });

View File

@@ -10,6 +10,7 @@ import {
relTypeChange,
addRelViewMigrate,
REL_SET_MANUAL_COLUMNS,
UPDATE_MANUAL_REL_TABLE_LIST,
} from './Actions';
import {
fetchTableListBySchema,
@@ -36,7 +37,12 @@ class AddManualRelationship extends Component {
type: UPDATE_REMOTE_SCHEMA_MANUAL_REL,
data: this.props.currentSchema,
});
this.props.dispatch(fetchTableListBySchema(this.props.currentSchema));
this.props.dispatch(
fetchTableListBySchema(
this.props.currentSchema,
UPDATE_MANUAL_REL_TABLE_LIST
)
);
}
componentWillUnmount() {
this.props.dispatch({ type: RESET_MANUAL_REL_TABLE_LIST });
@@ -53,7 +59,9 @@ class AddManualRelationship extends Component {
type: REL_SET_MANUAL_COLUMNS,
data: [],
});
this.props.dispatch(fetchTableListBySchema(e.target.value));
this.props.dispatch(
fetchTableListBySchema(e.target.value, UPDATE_MANUAL_REL_TABLE_LIST)
);
}
onRelNameChange(e) {
this.props.dispatch(relNameChanged(e.target.value));

View File

@@ -1,6 +1,3 @@
import Endpoints, { globalCookiePolicy } from '../../../../Endpoints';
import dataHeaders from '../Common/Headers';
import requestAction from '../../../../utils/requestAction';
import defaultState from './AddState';
import _push from '../push';
import {
@@ -11,6 +8,7 @@ import {
} from '../EventActions';
import { showSuccessNotification } from '../Notification';
import { UPDATE_MIGRATION_STATUS_ERROR } from '../../../Main/Actions';
import { fetchTableListBySchema } from '../../Data/DataActions';
const SET_DEFAULTS = 'AddTrigger/SET_DEFAULTS';
const SET_TRIGGERNAME = 'AddTrigger/SET_TRIGGERNAME';
@@ -193,33 +191,9 @@ const createTrigger = () => {
};
};
const fetchTableListBySchema = schemaName => (dispatch, getState) => {
const url = Endpoints.getSchema;
const options = {
credentials: globalCookiePolicy,
method: 'POST',
headers: dataHeaders(getState),
body: JSON.stringify({
type: 'select',
args: {
table: {
name: 'hdb_table',
schema: 'hdb_catalog',
},
columns: ['*.*'],
where: { table_schema: schemaName },
order_by: ['+table_name'],
},
}),
};
return dispatch(requestAction(url, options)).then(
data => {
dispatch({ type: UPDATE_TABLE_LIST, data: data });
},
error => {
console.error('Failed to load triggers' + JSON.stringify(error));
}
);
const loadTableList = schemaName => {
return dispatch =>
dispatch(fetchTableListBySchema(schemaName, UPDATE_TABLE_LIST));
};
const operationToggleColumn = (
@@ -447,7 +421,7 @@ export {
setRetryInterval,
setRetryTimeout,
createTrigger,
fetchTableListBySchema,
loadTableList,
operationToggleColumn,
operationToggleAllColumns,
setOperationSelection,

View File

@@ -23,11 +23,11 @@ import {
setOperationSelection,
setDefaults,
UPDATE_WEBHOOK_URL_TYPE,
loadTableList,
} from './AddActions';
import { listDuplicate } from '../../../../utils/data';
import { showErrorNotification } from '../Notification';
import { createTrigger } from './AddActions';
import { fetchTableListBySchema } from './AddActions';
import DropdownButton from '../../../Common/DropdownButton/DropdownButton';
@@ -36,7 +36,7 @@ import semverCheck from '../../../../helpers/semver';
class AddTrigger extends Component {
constructor(props) {
super(props);
this.props.dispatch(fetchTableListBySchema('public'));
this.props.dispatch(loadTableList('public'));
this.state = {
advancedExpanded: false,
supportColumnChangeFeature: false,
@@ -245,7 +245,7 @@ class AddTrigger extends Component {
}
const updateTableList = e => {
dispatch(setSchemaName(e.target.value));
dispatch(fetchTableListBySchema(e.target.value));
dispatch(loadTableList(e.target.value));
};
const updateTableSelection = e => {