Skip to content

Commit df4dd4c

Browse files
committedOct 19, 2016
Get rid of AngularResourceProxy, make names consistent
1 parent f8914ea commit df4dd4c

File tree

26 files changed

+173
-238
lines changed

26 files changed

+173
-238
lines changed
 

‎frontend/src/metabase/admin/databases/database.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import _ from "underscore";
22

33
import { createAction } from "redux-actions";
4-
import { handleActions, combineReducers, AngularResourceProxy, createThunkAction } from "metabase/lib/redux";
4+
import { handleActions, combineReducers, createThunkAction } from "metabase/lib/redux";
55
import { push } from "react-router-redux";
66

77
import MetabaseAnalytics from "metabase/lib/analytics";
88
import MetabaseSettings from "metabase/lib/settings";
99

10+
import { MetabaseApi } from "metabase/services";
11+
1012
const RESET = "metabase/admin/databases/RESET";
1113
const SELECT_ENGINE = "metabase/admin/databases/SELECT_ENGINE";
1214
const FETCH_DATABASES = "metabase/admin/databases/FETCH_DATABASES";
@@ -16,9 +18,6 @@ const SAVE_DATABASE = "metabase/admin/databases/SAVE_DATABASE";
1618
const DELETE_DATABASE = "metabase/admin/databases/DELETE_DATABASE";
1719
const SYNC_DATABASE = "metabase/admin/databases/SYNC_DATABASE";
1820

19-
// resource wrappers
20-
const MetabaseApi = new AngularResourceProxy("Metabase", ["db_list", "db_get", "db_add_sample_dataset", "db_create", "db_update", "db_delete", "db_sync_metadata"]);
21-
2221
export const reset = createAction(RESET);
2322

2423
// selectEngine (uiControl)

‎frontend/src/metabase/admin/datamodel/datamodel.js

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import _ from "underscore";
22

3-
import { handleActions, combineReducers, AngularResourceProxy, createAction, createThunkAction, momentifyTimestamps } from "metabase/lib/redux";
3+
import { handleActions, combineReducers, createAction, createThunkAction, momentifyTimestamps } from "metabase/lib/redux";
44
import { push } from "react-router-redux";
55

66
import MetabaseAnalytics from "metabase/lib/analytics";
77
import { loadTableAndForeignKeys } from "metabase/lib/table";
88
import { isFK } from "metabase/lib/types";
99

10-
11-
// resource wrappers
12-
const MetabaseApi = new AngularResourceProxy("Metabase", ["db_list", "db_metadata", "db_idfields", "table_update", "field_update"]);
13-
const SegmentApi = new AngularResourceProxy("Segment", ["delete"]);
14-
const MetricApi = new AngularResourceProxy("Metric", ["delete"]);
15-
const Segment = new AngularResourceProxy("Segment", ["get", "create", "update", "delete"]);
16-
const Metric = new AngularResourceProxy("Metric", ["get", "create", "update", "delete"]);
17-
const Metabase = new AngularResourceProxy("Metabase", ["dataset"]);
18-
const Revisions = new AngularResourceProxy("Revisions", ["get"]);
19-
10+
import { MetabaseApi, SegmentApi, MetricApi, RevisionsApi } from "metabase/services";
2011

2112
function loadDatabaseMetadata(databaseId) {
2213
return MetabaseApi.db_metadata({ 'dbId': databaseId });
@@ -207,10 +198,10 @@ export const CREATE_SEGMENT = "CREATE_SEGMENT";
207198
export const UPDATE_SEGMENT = "UPDATE_SEGMENT";
208199
export const DELETE_SEGMENT = "DELETE_SEGMENT";
209200

210-
export const getSegment = createAction(GET_SEGMENT, Segment.get);
211-
export const createSegment = createAction(CREATE_SEGMENT, Segment.create);
212-
export const updateSegment = createAction(UPDATE_SEGMENT, Segment.update);
213-
export const deleteSegment = createAction(DELETE_SEGMENT, Segment.delete);
201+
export const getSegment = createAction(GET_SEGMENT, SegmentApi.get);
202+
export const createSegment = createAction(CREATE_SEGMENT, SegmentApi.create);
203+
export const updateSegment = createAction(UPDATE_SEGMENT, SegmentApi.update);
204+
export const deleteSegment = createAction(DELETE_SEGMENT, SegmentApi.delete);
214205

215206
// METRICS
216207

@@ -219,10 +210,10 @@ export const CREATE_METRIC = "CREATE_METRIC";
219210
export const UPDATE_METRIC = "UPDATE_METRIC";
220211
export const DELETE_METRIC = "DELETE_METRIC";
221212

222-
export const getMetric = createAction(GET_METRIC, Metric.get);
223-
export const createMetric = createAction(CREATE_METRIC, Metric.create);
224-
export const updateMetric = createAction(UPDATE_METRIC, Metric.update);
225-
export const deleteMetric = createAction(DELETE_METRIC, Metric.delete);
213+
export const getMetric = createAction(GET_METRIC, MetricApi.get);
214+
export const createMetric = createAction(CREATE_METRIC, MetricApi.create);
215+
export const updateMetric = createAction(UPDATE_METRIC, MetricApi.update);
216+
export const deleteMetric = createAction(DELETE_METRIC, MetricApi.delete);
226217

227218
// SEGMENT DETAIL
228219

@@ -231,7 +222,7 @@ export const UPDATE_PREVIEW_SUMMARY = "UPDATE_PREVIEW_SUMMARY";
231222

232223
export const loadTableMetadata = createAction(LOAD_TABLE_METADATA, loadTableAndForeignKeys);
233224
export const updatePreviewSummary = createAction(UPDATE_PREVIEW_SUMMARY, async (query) => {
234-
let result = await Metabase.dataset(query);
225+
let result = await MetabaseApi.dataset(query);
235226
return result.data.rows[0][0];
236227
});
237228

@@ -248,7 +239,7 @@ export const fetchRevisions = createThunkAction(FETCH_REVISIONS, ({ entity, id }
248239
}
249240
let [object, revisions] = await Promise.all([
250241
dispatch(action),
251-
Revisions.get({ entity, id })
242+
RevisionsApi.get({ entity, id })
252243
]);
253244
await dispatch(loadTableMetadata(object.payload.definition.source_table));
254245
return { object: object.payload, revisions };

‎frontend/src/metabase/admin/people/components/GroupDetail.jsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import React, { Component } from "react";
33
import _ from "underscore";
44
import cx from "classnames";
55

6-
import { AngularResourceProxy } from "metabase/lib/redux";
76
import { isAdminGroup, isDefaultGroup, canEditMembership } from "metabase/lib/groups";
87

8+
import { PermissionsApi } from "metabase/services";
9+
910
import Icon from "metabase/components/Icon.jsx";
1011
import Popover from "metabase/components/Popover.jsx";
1112
import UserAvatar from "metabase/components/UserAvatar.jsx";
@@ -19,8 +20,6 @@ import Typeahead from "metabase/hoc/Typeahead.jsx";
1920

2021
import AddRow from "./AddRow.jsx";
2122

22-
const PermissionsAPI = new AngularResourceProxy("Permissions", ["createMembership", "deleteMembership"]);
23-
2423
const GroupDescription = ({ group }) =>
2524
isDefaultGroup(group) ?
2625
<div className="px2 text-measure">
@@ -197,7 +196,7 @@ export default class GroupDetail extends Component {
197196
});
198197
try {
199198
await Promise.all(this.state.selectedUsers.map(async (user) => {
200-
let members = await PermissionsAPI.createMembership({group_id: this.props.group.id, user_id: user.id});
199+
let members = await PermissionsApi.createMembership({group_id: this.props.group.id, user_id: user.id});
201200
this.setState({ members });
202201
}));
203202
} catch (error) {
@@ -226,7 +225,7 @@ export default class GroupDetail extends Component {
226225

227226
async onRemoveUserClicked(membership) {
228227
try {
229-
await PermissionsAPI.deleteMembership({ id: membership.membership_id })
228+
await PermissionsApi.deleteMembership({ id: membership.membership_id })
230229
const newMembers = _.reject(this.getMembers(), (m) => m.user_id === membership.user_id);
231230
this.setState({ members: newMembers });
232231
} catch (error) {

‎frontend/src/metabase/admin/people/components/GroupsListing.jsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { Link } from "react-router";
44
import _ from "underscore";
55
import cx from "classnames";
66

7-
import { AngularResourceProxy } from "metabase/lib/redux";
87
import MetabaseAnalytics from "metabase/lib/analytics";
98
import { isDefaultGroup, isAdminGroup } from "metabase/lib/groups";
109

10+
import { PermissionsApi } from "metabase/services";
11+
1112
import Icon from "metabase/components/Icon.jsx";
1213
import Input from "metabase/components/Input.jsx";
1314
import ModalContent from "metabase/components/ModalContent.jsx";
@@ -21,9 +22,6 @@ import AdminPaneLayout from "metabase/components/AdminPaneLayout.jsx";
2122

2223
import AddRow from "./AddRow.jsx";
2324

24-
const PermissionsAPI = new AngularResourceProxy("Permissions", ["createGroup", "deleteGroup", "updateGroup"]);
25-
26-
2725
// ------------------------------------------------------------ Add Group ------------------------------------------------------------
2826

2927
function AddGroupRow({ text, onCancelClicked, onCreateClicked, onTextChange }) {
@@ -202,7 +200,7 @@ export default class GroupsListing extends Component {
202200
// TODO: move this to Redux
203201
onAddGroupCreateButtonClicked() {
204202
MetabaseAnalytics.trackEvent("People Groups", "Group Added");
205-
PermissionsAPI.createGroup({name: this.state.text}).then((newGroup) => {
203+
PermissionsApi.createGroup({name: this.state.text}).then((newGroup) => {
206204
const groups = this.state.groups || this.props.groups || [];
207205
const newGroups = sortGroups(_.union(groups, [newGroup]));
208206

@@ -270,7 +268,7 @@ export default class GroupsListing extends Component {
270268

271269
// ok, fire off API call to change the group
272270
MetabaseAnalytics.trackEvent("People Groups", "Group Updated");
273-
PermissionsAPI.updateGroup({id: group.id, name: group.name}).then((newGroup) => {
271+
PermissionsApi.updateGroup({id: group.id, name: group.name}).then((newGroup) => {
274272
// now replace the original group with the new group and update state
275273
let newGroups = _.reject(groups, (g) => g.id === group.id);
276274
newGroups = sortGroups(_.union(newGroups, [newGroup]));
@@ -290,7 +288,7 @@ export default class GroupsListing extends Component {
290288
async onDeleteGroupClicked(group) {
291289
const groups = this.state.groups || this.props.groups || [];
292290
MetabaseAnalytics.trackEvent("People Groups", "Group Deleted");
293-
PermissionsAPI.deleteGroup({id: group.id}).then(() => {
291+
PermissionsApi.deleteGroup({id: group.id}).then(() => {
294292
const newGroups = sortGroups(_.reject(groups, (g) => g.id === group.id));
295293
this.setState({
296294
groups: newGroups

‎frontend/src/metabase/admin/people/people.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11

2-
import { AngularResourceProxy, createAction, createThunkAction, handleActions, combineReducers } from "metabase/lib/redux";
2+
import { createAction, createThunkAction, handleActions, combineReducers } from "metabase/lib/redux";
33
import { normalize, Schema, arrayOf } from "normalizr";
44

55
import MetabaseAnalytics from "metabase/lib/analytics";
66

7+
import { SessionApi, UserApi, PermissionsApi } from "metabase/services";
8+
79
import moment from "moment";
810
import _ from "underscore";
911
import { assoc, dissoc } from "icepick";
1012

1113
const user = new Schema('user');
1214

13-
// resource wrappers
14-
const SessionApi = new AngularResourceProxy("Session", [
15-
"forgot_password"
16-
]);
17-
const UserApi = new AngularResourceProxy("User", [
18-
"list", "update", "create", "delete", "update_password", "send_invite"
19-
]);
20-
const PermissionsApi = new AngularResourceProxy("Permissions", [
21-
"groups", "groupDetails", "memberships", "createMembership", "deleteMembership"
22-
]);
23-
2415
// action constants
2516
export const CREATE_USER = 'metabase/admin/people/CREATE_USER';
2617
export const DELETE_USER = 'metabase/admin/people/DELETE_USER';

‎frontend/src/metabase/admin/permissions/permissions.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { createAction, createThunkAction, handleActions, combineReducers, AngularResourceProxy } from "metabase/lib/redux";
1+
import { createAction, createThunkAction, handleActions, combineReducers } from "metabase/lib/redux";
22

33
import { canEditPermissions } from "metabase/lib/groups";
44
import MetabaseAnalytics from "metabase/lib/analytics";
55

6-
const MetadataApi = new AngularResourceProxy("Metabase", ["db_list_with_tables"]);
7-
const PermissionsApi = new AngularResourceProxy("Permissions", ["groups", "graph", "updateGraph"]);
6+
import { MetabaseApi, PermissionsApi } from "metabase/services";
87

98
const INITIALIZE = "metabase/admin/permissions/INITIALIZE";
109
export const initialize = createThunkAction(INITIALIZE, () =>
@@ -24,7 +23,7 @@ const LOAD_GROUPS = "metabase/admin/permissions/LOAD_GROUPS";
2423
export const loadGroups = createAction(LOAD_GROUPS, () => PermissionsApi.groups());
2524

2625
const LOAD_METADATA = "metabase/admin/permissions/LOAD_METADATA";
27-
export const loadMetadata = createAction(LOAD_METADATA, () => MetadataApi.db_list_with_tables());
26+
export const loadMetadata = createAction(LOAD_METADATA, () => MetabaseApi.db_list_with_tables());
2827

2928
const UPDATE_PERMISSION = "metabase/admin/permissions/UPDATE_PERMISSION";
3029
export const updatePermission = createThunkAction(UPDATE_PERMISSION, ({ groupId, entityId, value, updater, postAction }) =>

‎frontend/src/metabase/admin/settings/settings.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11

2-
import { handleActions, combineReducers, AngularResourceProxy, createThunkAction } from "metabase/lib/redux";
2+
import { handleActions, combineReducers, createThunkAction } from "metabase/lib/redux";
33

4-
// resource wrappers
5-
const SettingsApi = new AngularResourceProxy("Settings", ["list", "put"]);
6-
const EmailApi = new AngularResourceProxy("Email", ["updateSettings", "sendTest"]);
7-
const SlackApi = new AngularResourceProxy("Slack", ["updateSettings"]);
4+
import { SettingsApi, EmailApi, SlackApi } from "metabase/services";
85

96
import { refreshSiteSettings } from "metabase/redux/settings";
107

‎frontend/src/metabase/auth/auth.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { handleActions, combineReducers, AngularResourceProxy, createThunkAction } from "metabase/lib/redux";
2+
import { handleActions, combineReducers, createThunkAction } from "metabase/lib/redux";
33

44
import { push } from "react-router-redux";
55

@@ -11,8 +11,7 @@ import { clearGoogleAuthCredentials } from "metabase/lib/auth";
1111

1212
import { refreshCurrentUser } from "metabase/user";
1313

14-
// resource wrappers
15-
const SessionApi = new AngularResourceProxy("Session", ["create", "createWithGoogleAuth", "delete", "reset_password"]);
14+
import { SessionApi } from "metabase/services";
1615

1716

1817
// login

‎frontend/src/metabase/auth/containers/ForgotPasswordApp.jsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Component, PropTypes } from "react";
2-
import { AngularResourceProxy } from "metabase/lib/redux";
32

43
import _ from "underscore";
54
import cx from "classnames";
@@ -15,7 +14,7 @@ import Icon from "metabase/components/Icon.jsx";
1514
import MetabaseSettings from "metabase/lib/settings";
1615

1716

18-
const SessionApi = new AngularResourceProxy("Session", ["forgot_password"]);
17+
import { SessionApi } from "metabase/services";
1918

2019

2120
export default class ForgotPasswordApp extends Component {

‎frontend/src/metabase/auth/containers/PasswordResetApp.jsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { Component, PropTypes } from "react";
22
import { connect } from "react-redux";
33
import { Link } from "react-router";
4-
import { AngularResourceProxy } from "metabase/lib/redux";
54

65
import cx from "classnames";
76

@@ -17,7 +16,7 @@ import MetabaseSettings from "metabase/lib/settings";
1716
import * as authActions from "../auth";
1817

1918

20-
const SessionApi = new AngularResourceProxy("Session", ["password_reset_token_valid"]);
19+
import { SessionApi } from "metabase/services";
2120

2221
const mapStateToProps = (state, props) => {
2322
return {

‎frontend/src/metabase/dashboard/dashboard.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _ from "underscore";
55
import moment from "moment";
66

77
import { createAction } from "redux-actions";
8-
import { handleActions, combineReducers, AngularResourceProxy, createThunkAction } from "metabase/lib/redux";
8+
import { handleActions, combineReducers, createThunkAction } from "metabase/lib/redux";
99
import { normalize, Schema, arrayOf } from "normalizr";
1010

1111
import MetabaseAnalytics from "metabase/lib/analytics";
@@ -17,6 +17,8 @@ import Utils from "metabase/lib/utils";
1717
import type { Dashboard, DashCard, DashCardId } from "metabase/meta/types/Dashboard";
1818
import type { Card, CardId } from "metabase/meta/types/Card";
1919

20+
import { DashboardApi, MetabaseApi, CardApi, RevisionApi } from "metabase/services";
21+
2022
const DATASET_SLOW_TIMEOUT = 15 * 1000;
2123
const DATASET_USUALLY_FAST_THRESHOLD = 15 * 1000;
2224

@@ -72,14 +74,6 @@ export const SET_PARAMETER_NAME = "metabase/dashboard/SET_PARAMETER_NAME";
7274
export const SET_PARAMETER_VALUE = "metabase/dashboard/SET_PARAMETER_VALUE";
7375
export const SET_PARAMETER_DEFAULT_VALUE = "metabase/dashboard/SET_PARAMETER_DEFAULT_VALUE";
7476

75-
// resource wrappers
76-
const DashboardApi = new AngularResourceProxy("Dashboard", [
77-
"list", "get", "create", "update", "delete", "reposition_cards", "addcard", "removecard"
78-
]);
79-
const MetabaseApi = new AngularResourceProxy("Metabase", ["dataset", "dataset_duration", "db_metadata"]);
80-
const CardApi = new AngularResourceProxy("Card", ["list", "update", "delete", "query"]);
81-
const RevisionApi = new AngularResourceProxy("Revision", ["list", "revert"]);
82-
8377
// action creators
8478

8579
export const initialize = createAction(INITIALIZE);

‎frontend/src/metabase/home/actions.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import _ from "underscore";
22
import moment from "moment";
33

4-
import { AngularResourceProxy, createThunkAction } from "metabase/lib/redux";
4+
import { createThunkAction } from "metabase/lib/redux";
55

6-
// resource wrappers
7-
const ActivityApi = new AngularResourceProxy("Activity", ["list", "recent_views"]);
6+
import { ActivityApi } from "metabase/services";
87

98

109
// action constants

‎frontend/src/metabase/lib/card.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import _ from "underscore";
22
import Query from "metabase/lib/query";
33
import Utils from "metabase/lib/utils";
44
import { createQuery } from "metabase/lib/query";
5-
import { AngularResourceProxy } from "metabase/lib/redux";
65

7-
const Card = new AngularResourceProxy("Card", ["get"]);
6+
import { CardApi } from "metabase/services";
87

98

109
export function createCard(name = null) {
@@ -28,7 +27,7 @@ export function startNewCard(type, databaseId, tableId) {
2827
// load a card either by ID or from a base64 serialization. if both are present then they are merged, which the serialized version taking precedence
2928
export async function loadCard(cardId) {
3029
try {
31-
let card = await Card.get({ "cardId": cardId });
30+
let card = await CardApi.get({ "cardId": cardId });
3231
return card && cleanCopyCard(card);
3332
} catch (error) {
3433
console.log("error loading card", error);

‎frontend/src/metabase/lib/redux.js

-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ export const createStore = compose(
3131
window.devToolsExtension ? window.devToolsExtension() : f => f
3232
)(originalCreateStore);
3333

34-
import * as services from "metabase/services";
35-
36-
// HACK: just use our Angular resources for now
37-
export function AngularResourceProxy(serviceName, methods) {
38-
return services[serviceName];
39-
}
40-
4134
// similar to createAction but accepts a (redux-thunk style) thunk and dispatches based on whether
4235
// the promise returned from the thunk resolves or rejects, similar to redux-promise
4336
export function createThunkAction(actionType, actionThunkCreator) {

0 commit comments

Comments
 (0)
Please sign in to comment.