Files
redash/client/app/services/data-source.js
Gabriel Dutra f9cc230227 Migrate Data Sources and Alert Destinations pages to React (#3470)
* Migrate TypePicker to React

* Migrate DataSources and Destinations List

* Fixes to DestinationsList

* Add CreateDataSource (testing with Steps)

* Render the form after type selection

* Add HELP_LINKS to CreateDataSource

* Add Done behavior

* Add scrollToTop to CreateDataSource

* TypePicker styling adjusts

* Add CreateDestination

* Update resouce gets to componentDidMount

* Create EditForm components

* Migrate Edit pages

* Remove angular logic from DynamicForm

* Add actions to EditPages

* TypePicker title style adjustments

* Add Empty and Loading state

* UX improvements

* Review changes

* Styling updates on TypePicker, forms background fix

* Add blank line removed by mistaken

* Reorganize TypePicker

* Hide Search on List Pages

* Fix spacing in Forms

* Update Create Data Source and Destination to be a Dialog

* Remove max-height from the form

* Fix DynamicForm import in CreateUserDialog

* Route /new to open CreateSourceDialog

* Add HelpTrigger + refine styling and Edit Pages

* Remove help links from data source resource

* Update Cypress specs

* TypePicker -> CardsList

* Remove old TypePicker styling and change CardsList styling to less

* Test if Percy shows Dialogs

* Personal review cleanup

* CR

* Remove unnecessary query on dialog success

* Handle resource errors in Edit Pages

* Add CreateDestination policy

* Add placeholder and separator to the Name field

* Use cy.click instead of cy.wait

* Revert "Use cy.click instead of cy.wait" (Didn't work)

This reverts commit 77285d9fa3.

* Align help trigger on the right and rename Steps

* Refine behavior for long names

* Update toastr calls to use notification instead

* Redirect to target after creation

* Remove autoFocus on DynamicForm for Edit Pages

* Add eslint-disable for cy.wait
2019-03-28 10:06:46 +02:00

65 lines
1.5 KiB
JavaScript

export const SCHEMA_NOT_SUPPORTED = 1;
export const SCHEMA_LOAD_ERROR = 2;
export const IMG_ROOT = '/static/images/db-logos';
export let DataSource = null; // eslint-disable-line import/no-mutable-exports
function DataSourceService($q, $resource, $http) {
function fetchSchema(dataSourceId, refresh = false) {
const params = {};
if (refresh) {
params.refresh = true;
}
return $http.get(`api/data_sources/${dataSourceId}/schema`, { params });
}
const actions = {
get: { method: 'GET', cache: false, isArray: false },
query: { method: 'GET', cache: false, isArray: true },
save: { method: 'POST' },
types: {
method: 'GET',
cache: false,
isArray: true,
url: 'api/data_sources/types',
},
test: {
method: 'POST',
cache: false,
isArray: false,
url: 'api/data_sources/:id/test',
},
};
const DataSourceResource = $resource('api/data_sources/:id', { id: '@id' }, actions);
DataSourceResource.prototype.getSchema = function getSchema(refresh = false) {
if (this._schema === undefined || refresh) {
return fetchSchema(this.id, refresh).then((response) => {
const data = response.data;
this._schema = data;
return data;
});
}
return $q.resolve(this._schema);
};
return DataSourceResource;
}
export default function init(ngModule) {
ngModule.factory('DataSource', DataSourceService);
ngModule.run(($injector) => {
DataSource = $injector.get('DataSource');
});
}
init.init = true;