Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace $http with axios #4497

Merged
merged 49 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
05117ed
Add axios dependency
gabrieldutra Dec 26, 2019
18e8bc5
Update plain usage of $http to axios
gabrieldutra Dec 26, 2019
52098b5
Temporarily use $q in AlertDestinations
gabrieldutra Dec 26, 2019
a9e581c
Abstract axios with default interceptor
gabrieldutra Dec 27, 2019
2d8d163
AlertDestination service
gabrieldutra Dec 27, 2019
e26df5b
DataSource service
gabrieldutra Dec 27, 2019
90d36ef
AlertSubscription service
gabrieldutra Dec 27, 2019
89b29ed
Allow non-angular requests in ItemsSource
gabrieldutra Dec 27, 2019
b934add
Alert service
gabrieldutra Dec 27, 2019
ddf40e3
getTags service
gabrieldutra Dec 27, 2019
8e548a9
recordEvent/Event service
gabrieldutra Dec 27, 2019
7fe15b7
QuerySnippet service (with class example)
gabrieldutra Dec 27, 2019
823daa0
Group service
gabrieldutra Dec 27, 2019
7c3355d
Conver missing Alert mute and unmute
gabrieldutra Dec 27, 2019
e7f60da
Update UserShow jest test
gabrieldutra Dec 27, 2019
b888e18
OrganizationSettings service
gabrieldutra Dec 27, 2019
4fa6a04
OrganizationStatus service
gabrieldutra Dec 27, 2019
7393b55
Add getResponse to axios error interceptor
gabrieldutra Dec 27, 2019
ac1e047
User service
gabrieldutra Dec 27, 2019
9d38114
Use plain axios usages to import from service
gabrieldutra Dec 27, 2019
7a9409f
Query service
gabrieldutra Dec 29, 2019
410feb1
Temp add $applyAsync to query pages
gabrieldutra Dec 29, 2019
7a0f47d
Widget service
gabrieldutra Dec 29, 2019
2c6d895
Inject apiKey in axios (tmp with $injector)
gabrieldutra Dec 29, 2019
8cf00f3
Fix associatedDropdown
gabrieldutra Dec 29, 2019
9fdc33e
Map query results
gabrieldutra Dec 30, 2019
34b7ef0
Fix axios call in widget service
gabrieldutra Dec 30, 2019
3a89092
QueryResult service
gabrieldutra Dec 30, 2019
20ab4cd
Temp add $applyAsync to axios
gabrieldutra Dec 30, 2019
aa7cb1f
Address comments
gabrieldutra Dec 30, 2019
4ca22d7
Visualization service
gabrieldutra Dec 30, 2019
702bf63
Dashboard service
gabrieldutra Dec 30, 2019
5cbbaf3
Update $favorite and $unfavorite
gabrieldutra Dec 30, 2019
95b3585
Add dashboard delete
gabrieldutra Dec 30, 2019
dc7a4bb
Auth service
gabrieldutra Dec 30, 2019
fadd78b
Update dashboard after archive it
gabrieldutra Dec 30, 2019
89b4e4c
Updates for GH comments
gabrieldutra Dec 31, 2019
acd7974
Remove angular-resource
gabrieldutra Dec 31, 2019
261715f
Merge branch 'master' into axios
gabrieldutra Jan 6, 2020
b589be5
Remove events service
gabrieldutra Jan 6, 2020
b3e12c8
Remove temp $promise handlers
gabrieldutra Jan 6, 2020
0ed6dc2
Fix AddToDashboardDialog
gabrieldutra Jan 6, 2020
131aabc
Use save to create Alerts
gabrieldutra Jan 6, 2020
0ac577d
Remove $applyAsync for query angular pages
gabrieldutra Jan 7, 2020
1f949a9
Remove unnecessary import
gabrieldutra Jan 7, 2020
6d27c39
Keep refresh in getSchema
gabrieldutra Jan 7, 2020
aad39dc
Add $applyAsync for Param url update
gabrieldutra Jan 7, 2020
484e248
Merge branch 'master' into axios
gabrieldutra Jan 8, 2020
a2ae12b
Merge branch 'master' into axios
gabrieldutra Jan 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions client/app/components/EditParameterSettingsDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ function EditParameterSettingsDialog(props) {
useEffect(() => {
const queryId = props.parameter.queryId;
if (queryId) {
Query.get({ id: queryId }, query => {
setInitialQuery(query);
});
Query.get({ id: queryId }).then(setInitialQuery);
}
}, [props.parameter.queryId]);

Expand Down
7 changes: 2 additions & 5 deletions client/app/components/QuerySelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ const { Option } = Select;
function search(term) {
// get recent
if (!term) {
return Query.recent().$promise.then(results => {
const filteredResults = results.filter(item => !item.is_draft); // filter out draft
return Promise.resolve(filteredResults);
});
return Query.recent().then(results => results.filter(item => !item.is_draft)); // filter out draft
}

// search by query
return Query.query({ q: term }).$promise.then(({ results }) => Promise.resolve(results));
return Query.query({ q: term }).then(({ results }) => results);
}

export function QuerySelector(props) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useMemo, useCallback, useEffect } from "react";
import PropTypes from "prop-types";
import { isEmpty, template } from "lodash";
import { isEmpty, template, get } from "lodash";

import Dropdown from "antd/lib/dropdown";
import Icon from "antd/lib/icon";
Expand All @@ -18,8 +18,9 @@ export default function FavoritesDropdown({ fetch, urlTemplate }) {
const fetchItems = useCallback(
(showLoadingState = true) => {
setLoading(showLoadingState);
fetch()
.$promise.then(({ results }) => {
const request = fetch();
get(request, "$promise", request)
.then(({ results }) => {
setItems(results);
})
.finally(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/dashboards/AddWidgetDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AddWidgetDialog extends React.Component {
});

if (selectedQuery) {
Query.get({ id: selectedQuery.id }, query => {
Query.get({ id: selectedQuery.id }).then(query => {
if (query) {
const existingParamNames = map(this.props.dashboard.getParametersDefs(), param => param.name);
this.setState({
Expand Down
5 changes: 3 additions & 2 deletions client/app/components/dashboards/CreateDashboardDialog.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { trim } from "lodash";
import React, { useRef, useState, useEffect } from "react";
import { axios } from "@/services/axios";
import Modal from "antd/lib/modal";
import Input from "antd/lib/input";
import DynamicComponent from "@/components/DynamicComponent";
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
import { $location, $http } from "@/services/ng";
import { $location } from "@/services/ng";
import recordEvent from "@/services/recordEvent";
import { policy } from "@/services/policy";

Expand Down Expand Up @@ -36,7 +37,7 @@ function CreateDashboardDialog({ dialog }) {
if (name !== "") {
setSaveInProgress(true);

$http.post("api/dashboards", { name }).then(({ data }) => {
axios.post("api/dashboards", { name }).then(data => {
dialog.close();
$location
.path(`/dashboard/${data.slug}`)
Expand Down
9 changes: 3 additions & 6 deletions client/app/components/groups/CreateGroupDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react";
import Modal from "antd/lib/modal";
import Input from "antd/lib/input";
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
import { Group } from "@/services/group";

class CreateGroupDialog extends React.Component {
static propTypes = {
Expand All @@ -14,11 +13,9 @@ class CreateGroupDialog extends React.Component {
};

save = () => {
this.props.dialog.close(
new Group({
name: this.state.name,
})
);
this.props.dialog.close({
name: this.state.name,
});
};

render() {
Expand Down
3 changes: 2 additions & 1 deletion client/app/components/groups/DeleteGroupButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Button from "antd/lib/button";
import Modal from "antd/lib/modal";
import Tooltip from "antd/lib/tooltip";
import notification from "@/services/notification";
import Group from "@/services/group";

function deleteGroup(event, group, onGroupDeleted) {
Modal.confirm({
Expand All @@ -14,7 +15,7 @@ function deleteGroup(event, group, onGroupDeleted) {
okType: "danger",
cancelText: "No",
onOk: () => {
group.$delete(() => {
Group.delete(group).then(() => {
notification.success("Group deleted successfully.");
onGroupDeleted();
});
Expand Down
4 changes: 2 additions & 2 deletions client/app/components/groups/GroupName.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from "react";
import PropTypes from "prop-types";
import { EditInPlace } from "@/components/EditInPlace";
import { currentUser } from "@/services/auth";
import Group from "@/services/group";

function updateGroupName(group, name, onChange) {
group.name = name;
group.$save();
Group.save(group);
onChange();
}

Expand Down Expand Up @@ -33,7 +34,6 @@ export default function GroupName({ group, onChange, ...props }) {
GroupName.propTypes = {
group: PropTypes.shape({
name: PropTypes.string.isRequired,
$save: PropTypes.func.isRequired,
}),
onChange: PropTypes.func,
};
Expand Down
7 changes: 4 additions & 3 deletions client/app/components/items-list/classes/ItemsSource.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFunction, identity, map, extend } from "lodash";
import { isFunction, identity, map, extend, get } from "lodash";
import Paginator from "./Paginator";
import Sorter from "./Sorter";
import PromiseRejectionError from "@/lib/promise-rejection-error";
Expand Down Expand Up @@ -156,8 +156,9 @@ export class ResourceItemsSource extends ItemsSource {
super({
...rest,
doRequest: (request, context) => {
const resource = getResource(context);
return resource(request).$promise;
const resource = getResource(context)(request);
// ANGULAR_REMOVE_ME just return resource when all Services are migrated
return get(resource, "$promise", resource);
},
processResults: (results, context) => {
let processItem = getItemProcessor(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect, useCallback } from "react";
import { axios } from "@/services/axios";
import PropTypes from "prop-types";
import { each, debounce, get, find } from "lodash";
import Button from "antd/lib/button";
Expand All @@ -8,12 +9,11 @@ import Select from "antd/lib/select";
import Tag from "antd/lib/tag";
import Tooltip from "antd/lib/tooltip";
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
import { $http } from "@/services/ng";
import { toHuman } from "@/filters";
import HelpTrigger from "@/components/HelpTrigger";
import { UserPreviewCard } from "@/components/PreviewCard";
import notification from "@/services/notification";
import { User } from "@/services/user";
import User from "@/services/user";

import "./PermissionsEditorDialog.less";

Expand All @@ -23,7 +23,7 @@ const DEBOUNCE_SEARCH_DURATION = 200;
function useGrantees(url) {
const loadGrantees = useCallback(
() =>
$http.get(url).then(({ data }) => {
axios.get(url).then(data => {
const resultGrantees = [];
each(data, (grantees, accessType) => {
grantees.forEach(grantee => {
Expand All @@ -38,15 +38,15 @@ function useGrantees(url) {

const addPermission = useCallback(
(userId, accessType = "modify") =>
$http
axios
.post(url, { access_type: accessType, user_id: userId })
.catch(() => notification.error("Could not grant permission to the user")),
[url]
);

const removePermission = useCallback(
(userId, accessType = "modify") =>
$http
axios
.delete(url, { data: { access_type: accessType, user_id: userId } })
.catch(() => notification.error("Could not remove permission from the user")),
[url]
Expand All @@ -57,7 +57,7 @@ function useGrantees(url) {

const searchUsers = searchTerm =>
User.query({ q: searchTerm })
.$promise.then(({ results }) => results)
.then(({ results }) => results)
.catch(() => []);

function PermissionsEditorDialogHeader({ context }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from "prop-types";
import cx from "classnames";
import { AceEditor, snippetsModule, updateSchemaCompleter } from "./ace";
import resizeObserver from "@/services/resizeObserver";
import { QuerySnippet } from "@/services/query-snippet";
import QuerySnippet from "@/services/query-snippet";

const editorProps = { $blockScrolling: Infinity };

Expand Down Expand Up @@ -91,7 +91,7 @@ const QueryEditorComponent = React.forwardRef(function(
}
});

QuerySnippet.query(snippets => {
QuerySnippet.query().then(snippets => {
const snippetManager = snippetsModule.snippetManager;
const m = {
snippetText: "",
Expand Down
5 changes: 3 additions & 2 deletions client/app/components/queries/VisualizationEmbed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import QueryResultsLink from "@/components/EditVisualizationButton/QueryResultsL
import VisualizationName from "@/visualizations/VisualizationName";
import { VisualizationRenderer } from "@/visualizations/VisualizationRenderer";
import { VisualizationType } from "@/visualizations";
import { Query } from "@/services/query";

import logoUrl from "@/assets/images/redash_icon_small.png";

Expand Down Expand Up @@ -201,10 +202,10 @@ export default function init(ngModule) {
return Auth.loadConfig();
}

function loadQuery($route, Auth, Query) {
function loadQuery($route, Auth) {
"ngInject";

return loadSession($route, Auth).then(() => Query.get({ id: $route.current.params.queryId }).$promise);
return loadSession($route, Auth).then(() => Query.get({ id: $route.current.params.queryId }));
}

ngModule.config($routeProvider => {
Expand Down
14 changes: 6 additions & 8 deletions client/app/components/users/ChangePasswordDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Form from "antd/lib/form";
import Modal from "antd/lib/modal";
import Input from "antd/lib/input";
import { isFunction } from "lodash";
import { User } from "@/services/user";
import User from "@/services/user";
import notification from "@/services/notification";
import { UserProfile } from "../proptypes";
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
Expand Down Expand Up @@ -67,17 +67,15 @@ class ChangePasswordDialog extends React.Component {

this.setState({ updatingPassword: true });

User.save(
userData,
() => {
User.save(userData)
.then(() => {
notification.success("Saved.");
this.props.dialog.close({ success: true });
},
(error = {}) => {
})
.catch((error = {}) => {
notification.error((error.data && error.data.message) || "Failed saving.");
this.setState({ updatingPassword: false });
}
);
});
} else {
this.setState(prevState => ({
currentPassword: { ...prevState.currentPassword, touched: true },
Expand Down
20 changes: 9 additions & 11 deletions client/app/components/users/UserEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Button from "antd/lib/button";
import Form from "antd/lib/form";
import Modal from "antd/lib/modal";
import Tag from "antd/lib/tag";
import { User } from "@/services/user";
import { Group } from "@/services/group";
import User from "@/services/user";
import Group from "@/services/group";
import { currentUser } from "@/services/auth";
import { absoluteUrl } from "@/services/utils";
import { UserProfile } from "../proptypes";
Expand All @@ -33,7 +33,7 @@ export default class UserEdit extends React.Component {
}

componentDidMount() {
Group.query(groups => {
Group.query().then(groups => {
this.setState({
groups: groups.map(({ id, name }) => ({ value: id, name })),
loadingGroups: false,
Expand Down Expand Up @@ -102,7 +102,7 @@ export default class UserEdit extends React.Component {
toggleUser(user)
.then(data => {
if (data) {
this.setState({ user: User.convertUserInfo(data.data) });
this.setState({ user: User.convertUserInfo(data) });
}
})
.finally(() => {
Expand All @@ -116,16 +116,14 @@ export default class UserEdit extends React.Component {
...values,
};

User.save(
data,
user => {
User.save(data)
.then(user => {
successCallback("Saved.");
this.setState({ user: User.convertUserInfo(user) });
},
(error = {}) => {
})
.catch((error = {}) => {
errorCallback((error.data && error.data.message) || "Failed saving.");
}
);
});
};

renderUserInfoForm() {
Expand Down
4 changes: 2 additions & 2 deletions client/app/components/users/UserShow.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { includes } from "lodash";
import Tag from "antd/lib/tag";
import { Group } from "@/services/group";
import Group from "@/services/group";
import { UserProfile } from "../proptypes";

export default class UserShow extends React.Component {
Expand All @@ -15,7 +15,7 @@ export default class UserShow extends React.Component {
}

componentDidMount() {
Group.query(groups => {
Group.query().then(groups => {
this.setState({ groups, loadingGroups: false });
});
}
Expand Down
4 changes: 2 additions & 2 deletions client/app/components/users/UserShow.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import renderer from "react-test-renderer";
import { Group } from "@/services/group";
import Group from "@/services/group";
import UserShow from "./UserShow";

beforeEach(() => {
Group.query = jest.fn(dataCallback => dataCallback([]));
Group.query = jest.fn().mockResolvedValue([]);
});

test("renders correctly", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports[`renders correctly 1`] = `
Groups:
</dt>
<dd>
<div />
Loading...
</dd>
</dl>
</div>
Expand Down
8 changes: 8 additions & 0 deletions client/app/lib/defer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function defer() {
gabrieldutra marked this conversation as resolved.
Show resolved Hide resolved
const result = {};
result.promise = new Promise((resolve, reject) => {
result.resolve = resolve;
result.reject = reject;
});
return result;
}
Loading