Skip to content

Commit

Permalink
move the remainder of the admin routes onto the global redux store + …
Browse files Browse the repository at this point in the history
…redux router
  • Loading branch information
agilliland committed Jun 23, 2016
1 parent 62193f0 commit 8c1f6dc
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 168 deletions.
12 changes: 12 additions & 0 deletions frontend/src/metabase/Routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ import PulseListApp from "metabase/pulse/containers/PulseListApp.jsx";
import QueryBuilder from "metabase/query_builder/containers/QueryBuilder.jsx";

// admin containers
import DatabaseListApp from "metabase/admin/databases/containers/DatabaseListApp.jsx";
import DatabaseEditApp from "metabase/admin/databases/containers/DatabaseEditApp.jsx";
import MetadataEditorApp from "metabase/admin/datamodel/containers/MetadataEditorApp.jsx";
import MetricApp from "metabase/admin/datamodel/containers/MetricApp.jsx";
import SegmentApp from "metabase/admin/datamodel/containers/SegmentApp.jsx";
import RevisionHistoryApp from "metabase/admin/datamodel/containers/RevisionHistoryApp.jsx";
import AdminPeopleApp from "metabase/admin/people/containers/AdminPeopleApp.jsx";
import SettingsEditorApp from "metabase/admin/settings/containers/SettingsEditorApp.jsx";


export default class Routes extends Component {
Expand All @@ -36,6 +40,10 @@ export default class Routes extends Component {
<Route path="/" component={this._forwardProps(HomepageApp, ["onChangeLocation"])} />

<Route path="/admin">
<Route path="databases" component={DatabaseListApp} />
<Route path="databases/create" component={this._forwardProps(DatabaseEditApp, ["onChangeLocation"])} />
<Route path="databases/:databaseId" component={this._forwardProps(DatabaseEditApp, ["onChangeLocation"])} />

<Route path="datamodel">
<Route path="database" component={this._forwardProps(MetadataEditorApp, ["onChangeLocation"])} />
<Route path="database/:databaseId" component={this._forwardProps(MetadataEditorApp, ["onChangeLocation"])} />
Expand All @@ -47,8 +55,12 @@ export default class Routes extends Component {
<Route path="segment/:id" component={this._forwardProps(SegmentApp, ["onChangeLocation"])} />
<Route path=":entity/:id/revisions" component={RevisionHistoryApp} />
</Route>

<Route path="people" component={this._forwardProps(AdminPeopleApp, ["onChangeLocation"])} />
<Route path="settings" component={this._forwardProps(SettingsEditorApp, ["refreshSiteSettings"])} />
</Route>


<Route path="/card/:cardId" component={QueryBuilder} />

<Route path="/dash/:dashboardId" component={this._forwardProps(DashboardApp, ["onChangeLocation", "onChangeLocationSearch", "onBroadcast"])} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import * as databaseActions from "../database";

const mapStateToProps = (state, props) => {
return {
database: getEditingDatabase(state),
formState: getFormState(state)
databaseId: state.router && state.router.params && state.router.params.databaseId,
database: getEditingDatabase(state),
formState: getFormState(state),
onChangeLocation: props.onChangeLocation
}
}

Expand All @@ -36,7 +38,7 @@ export default class DatabaseEditApp extends Component {
};

componentWillMount() {
this.props.initializeDatabase(this.props.databaseId);
this.props.initializeDatabase(this.props.databaseId, this.props.onChangeLocation);
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import * as databaseActions from "../database";


const mapStateToProps = (state, props) => {
return {
databases: getDatabasesSorted(state),
hasSampleDataset: hasSampleDataset(state),
engines: MetabaseSettings.get('engines')
}
return {
created: state.router && state.router.params && state.router.params.created,
databases: getDatabasesSorted(state),
hasSampleDataset: hasSampleDataset(state),
engines: MetabaseSettings.get('engines')
}
}

const mapDispatchToProps = {
Expand Down
31 changes: 20 additions & 11 deletions frontend/src/metabase/admin/databases/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export const fetchDatabases = createThunkAction("FETCH_DATABASES", function() {
});

// initializeDatabase
export const initializeDatabase = createThunkAction("INITIALIZE_DATABASE", function(databaseId) {
export const initializeDatabase = createThunkAction("INITIALIZE_DATABASE", function(databaseId, onChangeLocation) {
return async function(dispatch, getState) {
if (databaseId) {
try {
return await MetabaseApi.db_get({"dbId": databaseId});
let database = await MetabaseApi.db_get({"dbId": databaseId});
return {
database,
onChangeLocation
}
} catch (error) {
if (error.status == 404) {
//$location.path('/admin/databases/');
Expand All @@ -41,11 +45,14 @@ export const initializeDatabase = createThunkAction("INITIALIZE_DATABASE", funct

} else {
return {
name: '',
engine: Object.keys(MetabaseSettings.get('engines'))[0],
details: {},
created: false
};
database: {
name: '',
engine: Object.keys(MetabaseSettings.get('engines'))[0],
details: {},
created: false
},
onChangeLocation
}
}
}
})
Expand All @@ -68,7 +75,7 @@ export const addSampleDataset = createThunkAction("ADD_SAMPLE_DATASET", function
// saveDatabase
export const saveDatabase = createThunkAction("SAVE_DATABASE", function(database, details) {
return async function(dispatch, getState) {
const { onChangeLocation } = getState();
const { databases: { onChangeLocation } } = getState();

let savedDatabase, formState;

Expand Down Expand Up @@ -107,7 +114,7 @@ export const saveDatabase = createThunkAction("SAVE_DATABASE", function(database
// deleteDatabase
export const deleteDatabase = createThunkAction("DELETE_DATABASE", function(databaseId, redirect=false) {
return async function(dispatch, getState) {
const { onChangeLocation } = getState();
const { databases: { onChangeLocation } } = getState();

try {
console.log("deleting database", databaseId);
Expand Down Expand Up @@ -141,7 +148,9 @@ export const syncDatabase = createThunkAction("SYNC_DATABASE", function(database
// reducers

// this is a backwards compatibility thing with angular to allow programmatic route changes. remove/change this when going to ReduxRouter
const onChangeLocation = handleActions({}, () => null);
const onChangeLocation = handleActions({
["INITIALIZE_DATABASE"]: { next: (state, { payload }) => payload ? payload.onChangeLocation : state },
}, () => null);

const databases = handleActions({
["FETCH_DATABASES"]: { next: (state, { payload }) => payload },
Expand All @@ -150,7 +159,7 @@ const databases = handleActions({
}, null);

const editingDatabase = handleActions({
["INITIALIZE_DATABASE"]: { next: (state, { payload }) => payload ? payload : state },
["INITIALIZE_DATABASE"]: { next: (state, { payload }) => payload ? payload.database : state },
["SAVE_DATABASE"]: { next: (state, { payload }) => payload.database || state },
["DELETE_DATABASE"]: { next: (state, { payload }) => null },
["SELECT_ENGINE"]: { next: (state, { payload }) => ({...state, engine: payload }) }
Expand Down
45 changes: 0 additions & 45 deletions frontend/src/metabase/admin/databases/databases.module.js

This file was deleted.

6 changes: 3 additions & 3 deletions frontend/src/metabase/admin/databases/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createSelector } from 'reselect';


// Database List
export const databases = state => state.databases;
export const databases = state => state.databases.databases;

export const getDatabasesSorted = createSelector(
[databases],
Expand All @@ -19,5 +19,5 @@ export const hasSampleDataset = createSelector(


// Database Edit
export const getEditingDatabase = state => state.editingDatabase;
export const getFormState = state => state.formState;
export const getEditingDatabase = state => state.databases.editingDatabase;
export const getFormState = state => state.databases.formState;
10 changes: 2 additions & 8 deletions frontend/src/metabase/admin/people/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ export const fetchUsers = createThunkAction(FETCH_USERS, function() {

export const grantAdmin = createThunkAction(GRANT_ADMIN, function(user) {
return async function(dispatch, getState) {
// give this user admin perms
user.is_superuser = true;

// do the update
let updatedUser = await UserApi.update(user);
let updatedUser = await UserApi.update({...user, is_superuser: true});
updatedUser.date_joined = (updatedUser.date_joined) ? moment(updatedUser.date_joined) : null;
updatedUser.last_login = (updatedUser.last_login) ? moment(updatedUser.last_login) : null;

Expand Down Expand Up @@ -109,11 +106,8 @@ export const resetPasswordViaEmail = createThunkAction(RESET_PASSWORD_EMAIL, fun

export const revokeAdmin = createThunkAction(REVOKE_ADMIN, function(user) {
return async function(dispatch, getState) {
// remove user admin perms
user.is_superuser = false;

// do the update
let updatedUser = await UserApi.update(user);
let updatedUser = await UserApi.update({...user, is_superuser: false});
updatedUser.date_joined = (updatedUser.date_joined) ? moment(updatedUser.date_joined) : null;
updatedUser.last_login = (updatedUser.last_login) ? moment(updatedUser.last_login) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { connect } from "react-redux";
import AdminPeople from "../components/AdminPeople.jsx";
import { adminPeopleSelectors } from "../selectors";

@connect(adminPeopleSelectors)

const mapStateToProps = (state, props) => {
return {
...adminPeopleSelectors(state),
user: state.currentUser
}
}

@connect(mapStateToProps)
export default class AdminPeopleApp extends Component {
render() {
return <AdminPeople {...this.props} />;
Expand Down
23 changes: 0 additions & 23 deletions frontend/src/metabase/admin/people/people.controllers.js

This file was deleted.

17 changes: 0 additions & 17 deletions frontend/src/metabase/admin/people/people.module.js

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/metabase/admin/people/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { createSelector } from 'reselect';

// our master selector which combines all of our partial selectors above
export const adminPeopleSelectors = createSelector(
[state => state.modal, state => state.users],
[state => state.people.modal, state => state.people.users],
(modal, users) => ({modal, users})
);
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import {
} from "../selectors";
import * as settingsActions from "../settings";


const mapStateToProps = (state, props) => {
return {
settings: getSettings(state),
sections: getSections(state),
activeSection: getActiveSection(state),
newVersionAvailable: getNewVersionAvailable(state)
}
return {
initialSection: state.router && state.router.location && state.router.location.query.section,
refreshSiteSettings: props.refreshSiteSettings,
settings: getSettings(state),
sections: getSections(state),
activeSection: getActiveSection(state),
newVersionAvailable: getNewVersionAvailable(state)
}
}

const mapDispatchToProps = {
Expand All @@ -53,7 +54,7 @@ export default class SettingsEditorApp extends Component {
};

componentWillMount() {
this.props.initializeSettings();
this.props.initializeSettings(this.props.initialSection, this.props.refreshSiteSettings);
}

updateSetting(setting, value) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/metabase/admin/settings/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const SECTIONS = [
}
];

export const getSettings = state => state.settings;
export const getSettings = state => state.settings.settings;

export const getNewVersionAvailable = createSelector(
getSettings,
Expand Down Expand Up @@ -163,7 +163,7 @@ export const getSections = createSelector(
);

export const getActiveSection = createSelector(
state => state.activeSection,
state => state.settings.activeSection,
getSections,
(section, sections) => {
if (sections) {
Expand Down
Loading

0 comments on commit 8c1f6dc

Please sign in to comment.