bug(portal-data): query by deployment slug works

This commit is contained in:
geek 2017-06-09 13:13:22 -05:00 committed by Judit Greskovits
parent 1cc2330b22
commit 5220139fdb
5 changed files with 74 additions and 27 deletions

View File

@ -1430,6 +1430,10 @@ clap@^1.0.9:
dependencies:
chalk "^1.1.3"
classnames@^2.2.5:
version "2.2.5"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d"
clean-css@4.1.x:
version "4.1.3"
resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.1.3.tgz#07cfe8980edb20d455ddc23aadcf1e04c6e509ce"
@ -1497,6 +1501,10 @@ code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
codemirror@^5.18.2:
version "5.26.0"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.26.0.tgz#bcbee86816ed123870c260461c2b5c40b68746e5"
color-convert@^1.0.0, color-convert@^1.3.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a"
@ -1721,7 +1729,7 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"
create-react-class@^15.5.3:
create-react-class@^15.5.1, create-react-class@^15.5.3:
version "15.5.3"
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.5.3.tgz#fb0f7cae79339e9a179e194ef466efa3923820fe"
dependencies:
@ -4176,6 +4184,10 @@ lodash.cond@^4.3.0:
version "4.5.2"
resolved "https://registry.yarnpkg.com/lodash.cond/-/lodash.cond-4.5.2.tgz#f471a1da486be60f6ab955d17115523dd1d255d5"
lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
lodash.defaults@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"
@ -4188,7 +4200,7 @@ lodash.isarraylike@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.isarraylike/-/lodash.isarraylike-4.2.0.tgz#4623310ab318804b667ddc3619058137559400c4"
lodash.isequal@^4.1.1:
lodash.isequal@^4.1.1, lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
@ -4603,10 +4615,6 @@ npmlog@^4.0.2:
gauge "~2.7.3"
set-blocking "~2.0.0"
nprogress@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
nth-check@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-1.0.1.tgz#9929acdf628fc2c41098deab82ac580cf149aae4"
@ -5416,6 +5424,17 @@ react-apollo@^1.2.0:
optionalDependencies:
react-dom "0.14.x || 15.* || ^15.0.0 || ^16.0.0-alpha"
react-codemirror@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-codemirror/-/react-codemirror-1.0.0.tgz#91467b53b1f5d80d916a2fd0b4c7adb85a9001ba"
dependencies:
classnames "^2.2.5"
codemirror "^5.18.2"
create-react-class "^15.5.1"
lodash.debounce "^4.0.8"
lodash.isequal "^4.5.0"
prop-types "^15.5.4"
react-dev-utils@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-3.0.0.tgz#3677f37718ba0cae892ba9c01fe54d1622e6ef7c"

View File

@ -20,7 +20,7 @@ type User {
type DeploymentGroup {
id: ID!
name: String!
slug: String
slug: String!
services(name: String, slug: String, parentId: ID): [Service]
version: Version
history: [Version]
@ -71,7 +71,7 @@ enum ManifestFormat {
type Manifest {
id: ID!
created: Date
created: Float
type: ManifestType!
format: ManifestFormat!
raw: String!
@ -85,8 +85,8 @@ type Service {
name: String! # human readable name
slug: String!
instances(name: String, machineId: ID, status: InstanceStatus): [Instance]!
# metrics: [MetricType]!
currentMetrics: [CurrentMetric]!
# metrics: [MetricType]
currentMetrics: [CurrentMetric]
connections: [String!] # list of serviceIds
parent: ID # parent service id
package: Package! # we don't have this in current mock data,

View File

@ -2,7 +2,6 @@
const Data = require('portal-data');
const data = new Data();
const ifError = function (err) {
if (err) {
@ -11,7 +10,10 @@ const ifError = function (err) {
}
};
data.connect(() => {
const bootstrap = function () {
const data = new Data();
data.connect(() => {
data.createDatacenter({ region: 'us-sw', name: 'us-sw' }, (err, datacenter) => {
ifError(err);
@ -23,14 +25,21 @@ data.connect(() => {
datacenter
}, (err, portal) => {
ifError(err);
data.createDeploymentGroup({ name: 'test' }, (err) => {
ifError(err);
console.log('data bootstrapped');
process.exit(0);
});
});
});
});
});
};
const main = function () {
const dropData = new Data();
dropData.connect(() => {
dropData._db.r.dbDrop('portal').run(dropData._db._connection, () => {
bootstrap();
});
});
};
main();

View File

@ -252,15 +252,16 @@ module.exports = class Data extends EventEmitter {
}
getDeploymentGroup (query, cb) {
this._db.deployment_groups.single(query, (err, deploymentGroup) => {
this._db.deployment_groups.query(query, (err, deploymentGroups) => {
if (err) {
return cb(err);
}
if (!deploymentGroup) {
if (!deploymentGroups || !deploymentGroups.length) {
return cb(null, {});
}
const deploymentGroup = deploymentGroups[0];
if (!deploymentGroup.service_ids || !deploymentGroup.service_ids.length) {
return cb(null, Transform.fromDeploymentGroup(deploymentGroup));
}
@ -274,7 +275,7 @@ module.exports = class Data extends EventEmitter {
return reject(err);
}
resolve(services);
resolve(services || []);
});
});
};
@ -711,7 +712,25 @@ module.exports = class Data extends EventEmitter {
});
}
_getDeploymentGroupServices (deploymentGroupSlug, cb) {
this.getDeploymentGroup({ slug: deploymentGroupSlug }, (err, deploymentGroup) => {
if (err) {
return cb(err);
}
if (!deploymentGroup) {
return cb(null, {});
}
return this.getServices({ deploymentGroupId: deploymentGroup.id }, cb);
});
}
getServices (options, cb) {
if (options.deploymentGroupSlug) {
return this._getDeploymentGroupServices(options.deploymentGroupSlug, cb);
}
const query = {};
if (options.ids && options.ids.length) {
query.id = this._db.or(options.ids);

View File

@ -37,7 +37,7 @@ exports.fromDeploymentGroup = function (deploymentGroup, services) {
exports.toDeploymentGroup = function ({ name }) {
return {
name,
slug: '',
slug: name,
services: [],
version_id: '',
history_version_ids: []
@ -63,7 +63,7 @@ exports.fromService = function ({ service, instances, packages }) {
exports.toService = function (clientService) {
return {
version_hash: clientService.hash || '',
version_hash: clientService.hash || clientService.name,
deployment_group_id: clientService.deploymentGroupId,
name: clientService.name,
slug: clientService.slug || '',