@kineticdata/react
Version:
A React library for the Kinetic Platform
139 lines (138 loc) • 4.71 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.IntegrationTable = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
var _Table = require("../../table/Table");
var _apis = require("../../../apis");
var _http = require("../../../apis/http");
var _excluded = ["integrations"];
var fetchIntegrationsWithSupportingData = function fetchIntegrationsWithSupportingData(options) {
return (0, _apis.fetchIntegrations)(options).then(function (_ref) {
var integrations = _ref.integrations,
response = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
// Get ids of all operations in the table
var ids = integrations === null || integrations === void 0 ? void 0 : integrations.map(function (integration) {
return integration.operationId;
});
// Fetch supporting integrator data for the table
return Promise.all([
// Get all connections
(0, _apis.fetchConnections)(),
// Get the operations that are used in the integrations
(ids === null || ids === void 0 ? void 0 : ids.length) > 0 ? (0, _apis.fetchBulkOperations)({
ids: ids
}) : Promise.resolve({
operations: []
})]).then(function (_ref2) {
var _ref3 = (0, _slicedToArray2["default"])(_ref2, 2),
_ref3$ = _ref3[0],
connections = _ref3$.connections,
integratorError = _ref3$.error,
operations = _ref3[1].operations;
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, response), {}, {
integrations: integrations.map(function (integration) {
var _connections$find, _operations$find;
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, integration), {}, {
// Add the connection and operation names to the records
connectionName: connections === null || connections === void 0 ? void 0 : (_connections$find = connections.find(function (conn) {
return conn.id === integration.connectionId;
})) === null || _connections$find === void 0 ? void 0 : _connections$find.name,
operationName: operations === null || operations === void 0 ? void 0 : (_operations$find = operations.find(function (op) {
return op.id === integration.operationId;
})) === null || _operations$find === void 0 ? void 0 : _operations$find.name
});
}),
integratorError: integratorError
});
});
});
};
var dataSource = function dataSource(_ref4) {
var kappSlug = _ref4.kappSlug;
return {
fn: fetchIntegrationsWithSupportingData,
params: function params(paramData) {
return [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({
include: 'details',
kappSlug: kappSlug
}, (0, _http.generateSortParams)(paramData)), (0, _http.generatePaginationParams)(paramData))];
},
transform: function transform(result) {
return {
data: result.integrations,
nextPageToken: result.nextPageToken,
extraData: {
integratorError: result.integratorError
}
};
}
};
};
var filters = function filters() {
return function () {
return [{
name: 'name',
label: 'Name',
type: 'text'
}];
};
};
var columns = [{
value: 'name',
title: 'Name',
sortable: true,
toggleable: false,
columnOrder: 'first'
}, {
value: 'connectionId',
title: 'Connection ID',
sortable: false,
toggleable: true
}, {
value: 'connectionName',
title: 'Connection',
sortable: false,
toggleable: true
}, {
value: 'operationId',
title: 'Operation ID',
sortable: false,
toggleable: true
}, {
value: 'operationName',
title: 'Operation',
sortable: false,
toggleable: true
}, {
value: 'createdAt',
title: 'Created At',
sortable: true,
toggleable: true
}, {
value: 'createdBy',
title: 'Created By',
sortable: true,
toggleable: true
}, {
value: 'updatedAt',
title: 'Updated At',
sortable: true,
toggleable: true
}, {
value: 'updatedBy',
title: 'Updated By',
sortable: true,
toggleable: true
}];
var IntegrationTable = exports.IntegrationTable = (0, _Table.generateTable)({
tableOptions: ['kappSlug'],
columns: columns,
filters: filters,
dataSource: dataSource
});
IntegrationTable.displayName = 'IntegrationTable';