1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00

eslint --fix

This commit is contained in:
sveisvei 2016-06-18 21:55:46 +02:00
parent 0f7c17654a
commit 61532301fb
56 changed files with 327 additions and 330 deletions

View File

@ -32,7 +32,7 @@ module.exports = function(config) {
app.use(bodyParser.json({ strict: false }));
app.use(log4js.connectLogger(logger, {
format: ':remote-addr :status :method :url :response-timems',
level: 'auto' // 3XX=WARN, 4xx/5xx=ERROR
level: 'auto', // 3XX=WARN, 4xx/5xx=ERROR
}));
// Setup API routes

View File

@ -5,6 +5,6 @@ module.exports = function(databaseConnection) {
return knex({
client: 'pg',
connection: databaseConnection,
pool: { min: 2, max: 20 }
pool: { min: 2, max: 20 },
});
};

View File

@ -6,7 +6,7 @@ module.exports = function(db) {
return db('events').insert({
type: event.type,
created_by: event.createdBy, // eslint-disable-line
data: event.data
data: event.data,
});
}
@ -22,7 +22,7 @@ module.exports = function(db) {
return db
.select(EVENT_COLUMNS)
.from('events')
.whereRaw("data ->> 'name' = ?", [name])
.whereRaw('data ->> \'name\' = ?', [name])
.orderBy('created_at', 'desc')
.map(rowToEvent);
}
@ -33,14 +33,14 @@ module.exports = function(db) {
type: row.type,
createdBy: row.created_by,
createdAt: row.created_at,
data: row.data
data: row.data,
};
}
return {
store: storeEvent,
getEvents,
getEventsFilterByName
getEventsFilterByName,
};
};

View File

@ -50,7 +50,7 @@ module.exports = function(db, eventStore) {
description: row.description,
enabled: row.enabled > 0,
strategy: row.strategy_name, // eslint-disable-line
parameters: row.parameters
parameters: row.parameters,
};
}
@ -61,7 +61,7 @@ module.exports = function(db, eventStore) {
enabled: data.enabled ? 1 : 0,
archived: data.archived ? 1 :0,
strategy_name: data.strategy, // eslint-disable-line
parameters: data.parameters
parameters: data.parameters,
};
}
@ -106,6 +106,6 @@ module.exports = function(db, eventStore) {
getFeature,
getArchivedFeatures,
_createFeature: createFeature, // visible for testing
_updateFeature: updateFeature // visible for testing
_updateFeature: updateFeature, // visible for testing
};
};

View File

@ -40,7 +40,7 @@ module.exports = function(db, eventStore) {
return {
name: row.name,
description: row.description,
parametersTemplate: row.parameters_template
parametersTemplate: row.parameters_template,
};
}
@ -63,7 +63,7 @@ module.exports = function(db, eventStore) {
return {
getStrategies,
getStrategy,
_createStrategy: createStrategy // visible for testing
_createStrategy: createStrategy, // visible for testing
};
};

View File

@ -1,11 +1,11 @@
'use strict';
const Promise = require("bluebird");
const Promise = require('bluebird');
const ValidationError = require('./ValidationError');
function validateRequest(req) {
return new Promise((resolve, reject) => {
if (req.validationErrors()) {
reject(new ValidationError("Invalid syntax"));
reject(new ValidationError('Invalid syntax'));
} else {
resolve(req);
}

View File

@ -4,14 +4,14 @@ const diff = require('deep-diff').diff;
const strategyTypes = [
eventType.strategyCreated,
eventType.strategyDeleted
eventType.strategyDeleted,
];
const featureTypes = [
eventType.featureCreated,
eventType.featureUpdated,
eventType.featureArchived,
eventType.featureRevived
eventType.featureRevived,
];
function baseTypeFor(event) {
@ -74,5 +74,5 @@ function addDiffs(events) {
module.exports = {
addDiffs
addDiffs,
};

View File

@ -5,5 +5,5 @@ module.exports = {
featureArchived: 'feature-archived',
featureRevived: 'feature-revived',
strategyCreated: 'strategy-created',
strategyDeleted: 'strategy-deleted'
strategyDeleted: 'strategy-deleted',
};

View File

@ -1,5 +1,5 @@
'use strict';
function extractUsername(req) {
return req.cookies.username || "unknown";
return req.cookies.username || 'unknown';
}
module.exports = extractUsername;

View File

@ -19,16 +19,16 @@ module.exports = function (app, config) {
validateRequest(req)
.then(() => eventStore.create({
type: eventType.featureRevived,
createdBy: req.connection.remoteAddress,
data: req.body
})).then(() => {
type: eventType.featureRevived,
createdBy: req.connection.remoteAddress,
data: req.body,
})).then(() => {
res.status(200).end();
}).catch(ValidationError, () => {
res.status(400).json(req.validationErrors());
})
.catch(err => {
logger.error("Could not revive feature toggle", err);
logger.error('Could not revive feature toggle', err);
res.status(500).end();
});
});

View File

@ -1,5 +1,5 @@
'use strict';
const Promise = require("bluebird");
const Promise = require('bluebird');
const logger = require('../logger');
const eventType = require('../eventType');
const NameExistsError = require('../error/NameExistsError');
@ -35,23 +35,23 @@ module.exports = function (app, config) {
validateRequest(req)
.then(validateUniqueName)
.then(() => eventStore.create({
type: eventType.featureCreated,
createdBy: extractUser(req),
data: req.body
}))
type: eventType.featureCreated,
createdBy: extractUser(req),
data: req.body,
}))
.then(() => {
res.status(201).end();
})
.catch(NameExistsError, () => {
res.status(403).json([{
msg: `A feature named '${req.body.name}' already exists. It could be archived.`
msg: `A feature named '${req.body.name}' already exists. It could be archived.`,
}]).end();
})
.catch(ValidationError, () => {
res.status(400).json(req.validationErrors());
})
.catch(err => {
logger.error("Could not create feature toggle", err);
logger.error('Could not create feature toggle', err);
res.status(500).end();
});
});
@ -65,10 +65,10 @@ module.exports = function (app, config) {
featureDb.getFeature(featureName)
.then(() => eventStore.create({
type: eventType.featureUpdated,
createdBy: userName,
data: updatedFeature
}))
type: eventType.featureUpdated,
createdBy: userName,
data: updatedFeature,
}))
.then(() => {
res.status(200).end();
})
@ -87,12 +87,12 @@ module.exports = function (app, config) {
featureDb.getFeature(featureName)
.then(() => eventStore.create({
type: eventType.featureArchived,
createdBy: userName,
data: {
name: featureName
}
}))
type: eventType.featureArchived,
createdBy: userName,
data: {
name: featureName,
},
}))
.then(() => {
res.status(200).end();
})
@ -109,7 +109,7 @@ module.exports = function (app, config) {
return new Promise((resolve, reject) => {
featureDb.getFeature(req.body.name)
.then(() => {
reject(new NameExistsError("Feature name already exist"));
reject(new NameExistsError('Feature name already exist'));
}, () => {
resolve(req);
});

View File

@ -1,5 +1,5 @@
'use strict';
const Promise = require("bluebird");
const Promise = require('bluebird');
const eventType = require('../eventType');
const logger = require('../logger');
const NameExistsError = require('../error/NameExistsError');
@ -33,12 +33,12 @@ module.exports = function (app, config) {
strategyDb.getStrategy(strategyName)
.then(() => eventStore.create({
type: eventType.strategyDeleted,
createdBy: extractUser(req),
data: {
name: strategyName
}
}))
type: eventType.strategyDeleted,
createdBy: extractUser(req),
data: {
name: strategyName,
},
}))
.then(() => {
res.status(200).end();
})
@ -60,10 +60,10 @@ module.exports = function (app, config) {
validateRequest(req)
.then(validateStrategyName)
.then(() => eventStore.create({
type: eventType.strategyCreated,
createdBy: extractUser(req),
data: newStrategy
}))
type: eventType.strategyCreated,
createdBy: extractUser(req),
data: newStrategy,
}))
.then(() => {
res.status(201).end();
})
@ -74,7 +74,7 @@ module.exports = function (app, config) {
res.status(400).json(req.validationErrors());
})
.catch(err => {
logger.error("Could not create strategy", err);
logger.error('Could not create strategy', err);
res.status(500).end();
});
});
@ -83,7 +83,7 @@ module.exports = function (app, config) {
return new Promise((resolve, reject) => {
strategyDb.getStrategy(req.body.name)
.then(() => {
reject(new NameExistsError("Feature name already exist"));
reject(new NameExistsError('Feature name already exist'));
}, () => {
resolve(req);
});

View File

@ -13,7 +13,7 @@ module.exports = {
return {
up: runMigration.bind(null, util.format(format, name, 'up')),
down: runMigration.bind(null, util.format(format, name, 'down'))
down: runMigration.bind(null, util.format(format, name, 'down')),
};
}
},
};

View File

@ -21,7 +21,7 @@ function start(options) {
eventStore,
featureDb,
strategyDb,
publicFolder: options.publicFolder
publicFolder: options.publicFolder,
};
const app = require('./app')(config);
@ -33,7 +33,7 @@ function start(options) {
return {
app,
server,
config
config,
};
}
@ -43,5 +43,5 @@ process.on('uncaughtException', err => {
});
module.exports = {
start
start,
};

View File

@ -7,5 +7,5 @@ function getDatabaseUri() {
}
}
module.exports = {
getDatabaseUri
getDatabaseUri,
};

View File

@ -7,7 +7,7 @@ describe('eventDiffer', () => {
it('fails if events include an unknown event type', () => {
const events = [
{ type: eventType.featureCreated, data: {} },
{ type: 'unknown-type', data: {} }
{ type: 'unknown-type', data: {} },
];
assert.throws(() => {
@ -22,19 +22,19 @@ describe('eventDiffer', () => {
const events = [
{
type: eventType.featureUpdated,
data: { name, description: desc, strategy: 'default', enabled: true, parameters: { value: 2 } }
data: { name, description: desc, strategy: 'default', enabled: true, parameters: { value: 2 } },
},
{
type: eventType.featureCreated,
data: { name, description: desc, strategy: 'default', enabled: false, parameters: { value: 1 } }
}
data: { name, description: desc, strategy: 'default', enabled: false, parameters: { value: 1 } },
},
];
eventDiffer.addDiffs(events);
assert.deepEqual(events[0].diffs, [
{ kind: 'E', path: ["enabled"], lhs: false, rhs: true },
{ kind: 'E', path: ["parameters", "value"], lhs: 1, rhs: 2 }
{ kind: 'E', path: ['enabled'], lhs: false, rhs: true },
{ kind: 'E', path: ['parameters', 'value'], lhs: 1, rhs: 2 },
]);
assert.strictEqual(events[1].diffs, null);
@ -44,20 +44,20 @@ describe('eventDiffer', () => {
const events = [
{
type: eventType.featureUpdated,
data: { name: 'bar', description: 'desc', strategy: 'default', enabled: true, parameters: {} }
data: { name: 'bar', description: 'desc', strategy: 'default', enabled: true, parameters: {} },
},
{
type: eventType.featureUpdated,
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: false, parameters: {} }
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: false, parameters: {} },
},
{
type: eventType.featureCreated,
data: { name: 'bar', description: 'desc', strategy: 'default', enabled: false, parameters: {} }
data: { name: 'bar', description: 'desc', strategy: 'default', enabled: false, parameters: {} },
},
{
type: eventType.featureCreated,
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: true, parameters: {} }
}
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: true, parameters: {} },
},
];
eventDiffer.addDiffs(events);
@ -72,12 +72,12 @@ describe('eventDiffer', () => {
const events = [
{
type: eventType.featureUpdated,
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: true, parameters: {} }
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: true, parameters: {} },
},
{
type: eventType.featureCreated,
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: true, parameters: {} }
}
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: true, parameters: {} },
},
];
eventDiffer.addDiffs(events);
@ -88,8 +88,8 @@ describe('eventDiffer', () => {
const events = [
{
type: eventType.featureUpdated,
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: true, parameters: {} }
}
data: { name: 'foo', description: 'desc', strategy: 'default', enabled: true, parameters: {} },
},
];
eventDiffer.addDiffs(events);

View File

@ -17,7 +17,7 @@ const app = require('../app')({
eventDb,
eventStore,
featureDb,
strategyDb
strategyDb,
});
Promise.promisifyAll(request);
@ -26,73 +26,73 @@ request = request(app);
function createStrategies() {
return Promise.map([
{
name: "default",
description: "Default on or off Strategy.",
parametersTemplate: {}
name: 'default',
description: 'Default on or off Strategy.',
parametersTemplate: {},
},
{
name: "usersWithEmail",
description: "Active for users defined in the comma-separated emails-parameter.",
name: 'usersWithEmail',
description: 'Active for users defined in the comma-separated emails-parameter.',
parametersTemplate: {
emails: "String"
}
}
emails: 'String',
},
},
], strategy => strategyDb._createStrategy(strategy));
}
function createFeatures() {
return Promise.map([
{
name: "featureX",
description: "the #1 feature",
name: 'featureX',
description: 'the #1 feature',
enabled: true,
strategy: "default"
strategy: 'default',
},
{
name: "featureY",
description: "soon to be the #1 feature",
name: 'featureY',
description: 'soon to be the #1 feature',
enabled: false,
strategy: "baz",
strategy: 'baz',
parameters: {
foo: "bar"
}
foo: 'bar',
},
},
{
name: "featureZ",
description: "terrible feature",
name: 'featureZ',
description: 'terrible feature',
enabled: true,
strategy: "baz",
strategy: 'baz',
parameters: {
foo: "rab"
}
foo: 'rab',
},
},
{
name: "featureArchivedX",
description: "the #1 feature",
name: 'featureArchivedX',
description: 'the #1 feature',
enabled: true,
archived: true,
strategy: "default"
strategy: 'default',
},
{
name: "featureArchivedY",
description: "soon to be the #1 feature",
name: 'featureArchivedY',
description: 'soon to be the #1 feature',
enabled: false,
archived: true,
strategy: "baz",
strategy: 'baz',
parameters: {
foo: "bar"
}
foo: 'bar',
},
},
{
name: "featureArchivedZ",
description: "terrible feature",
name: 'featureArchivedZ',
description: 'terrible feature',
enabled: true,
archived: true,
strategy: "baz",
strategy: 'baz',
parameters: {
foo: "rab"
}
}
foo: 'rab',
},
},
], feature => featureDb._createFeature(feature));
}
@ -119,6 +119,6 @@ module.exports = {
setup: setupDatabase,
resetAndSetup() {
return resetDatabase().then(setupDatabase);
}
}
},
},
};

View File

@ -5,5 +5,5 @@ const ReactTools = require('react-tools');
module.exports = {
process(src) {
return ReactTools.transform(src);
}
},
};

View File

@ -2,5 +2,5 @@
const path = require('path');
module.exports = {
publicFolder: path.join(__dirname, '..', 'public')
publicFolder: path.join(__dirname, '..', 'public'),
};

View File

@ -12,5 +12,5 @@ const compiler = webpack(webpackConfig);
app.use(config.baseUriPath, webpackDevMiddleware(compiler, {
publicPath: '/js',
noInfo: true
noInfo: true,
}));

View File

@ -12,32 +12,32 @@ const RouteHandler = Router.RouteHandler;
const UnleashApp = React.createClass({
contextTypes: {
router: React.PropTypes.func
router: React.PropTypes.func,
},
getInitialState() {
return {
features: FeatureToggleStore.getFeatureToggles(),
strategies: StrategyStore.getStrategies(),
archivedFeatures: ArchiveStore.getArchivedToggles()
features: FeatureToggleStore.getFeatureToggles(),
strategies: StrategyStore.getStrategies(),
archivedFeatures: ArchiveStore.getArchivedToggles(),
};
},
onFeatureToggleChange() {
this.setState({
features: FeatureToggleStore.getFeatureToggles()
features: FeatureToggleStore.getFeatureToggles(),
});
},
onStrategiesChange() {
this.setState({
strategies: StrategyStore.getStrategies()
strategies: StrategyStore.getStrategies(),
});
},
onArchiveChange() {
this.setState({
archivedFeatures: ArchiveStore.getArchivedToggles()
archivedFeatures: ArchiveStore.getArchivedToggles(),
});
},
@ -68,10 +68,10 @@ const UnleashApp = React.createClass({
return (
<div>
<Menu>
{this.renderLink("features", "Toggles")}
{this.renderLink("strategies", "Strategies")}
{this.renderLink("log", "Log")}
{this.renderLink("archive", "Archive")}
{this.renderLink('features', 'Toggles')}
{this.renderLink('strategies', 'Strategies')}
{this.renderLink('log', 'Log')}
{this.renderLink('archive', 'Archive')}
</Menu>
<div className="container">
<div className="page">
@ -91,7 +91,7 @@ const UnleashApp = React.createClass({
</div>
</div>
);
}
},
});

View File

@ -2,10 +2,10 @@
'use strict';
jest.dontMock("../../components/Menu");
jest.dontMock('../../components/Menu');
const Menu = require("../../components/Menu");
const React = require("react/addons");
const Menu = require('../../components/Menu');
const React = require('react/addons');
const TestUtils = React.addons.TestUtils;
describe('Menu test', () => {

View File

@ -1,19 +1,19 @@
'use strict';
jest.dontMock("../../../components/feature/ArchiveFeatureComponent");
jest.mock("../../../stores/FeatureToggleActions");
jest.dontMock('../../../components/feature/ArchiveFeatureComponent');
jest.mock('../../../stores/FeatureToggleActions');
jest.autoMockOff();
const React = require("react/addons");
const React = require('react/addons');
const TestUtils = React.addons.TestUtils;
const FeatureArchive = require("../../../components/feature/ArchiveFeatureComponent");
const FeatureActions = require("../../../stores/FeatureToggleActions");
const FeatureArchive = require('../../../components/feature/ArchiveFeatureComponent');
const FeatureActions = require('../../../stores/FeatureToggleActions');
describe("FeatureForm", () => {
describe('FeatureForm', () => {
let Component;
beforeEach(() => {
const archivedToggles = [
{ name: "featureX" },
{ name: "featureY" }
{ name: 'featureX' },
{ name: 'featureY' },
];
Component = TestUtils.renderIntoDocument(
@ -24,14 +24,14 @@ describe("FeatureForm", () => {
React.unmountComponentAtNode(document.body);
});
it("should render two archived features", () => {
const rows = Component.getDOMNode().querySelectorAll("tbody tr");
it('should render two archived features', () => {
const rows = Component.getDOMNode().querySelectorAll('tbody tr');
expect(rows.length).toEqual(2);
});
it("should revive archived feature toggle", () => {
const button = Component.getDOMNode().querySelector("tbody button");
it('should revive archived feature toggle', () => {
const button = Component.getDOMNode().querySelector('tbody button');
TestUtils.Simulate.click(button);
jest.runAllTimers();

View File

@ -1,35 +1,35 @@
'use strict';
jest.dontMock("../../../components/feature/FeatureForm");
jest.dontMock('../../../components/feature/FeatureForm');
const React = require("react/addons");
const React = require('react/addons');
const TestUtils = React.addons.TestUtils;
const FeatureForm = require("../../../components/feature/FeatureForm");
const FeatureForm = require('../../../components/feature/FeatureForm');
describe("FeatureForm", () => {
describe('FeatureForm', () => {
let Component;
const strategies = [
{ name: "default" }
{ name: 'default' },
];
afterEach(() => {
React.unmountComponentAtNode(document.body);
});
describe("new", () => {
it("should render empty form", () => {
describe('new', () => {
it('should render empty form', () => {
Component = TestUtils .renderIntoDocument(<FeatureForm strategies={strategies} />);
const name = Component.getDOMNode().querySelectorAll("input");
expect(name[0].value).toEqual("");
const name = Component.getDOMNode().querySelectorAll('input');
expect(name[0].value).toEqual('');
});
});
describe("edit", () => {
const feature = { name: "Test", strategy: "unknown" };
describe('edit', () => {
const feature = { name: 'Test', strategy: 'unknown' };
it("should show unknown strategy as default", () => {
it('should show unknown strategy as default', () => {
Component = TestUtils .renderIntoDocument(<FeatureForm feature={feature} strategies={strategies} />);
const strategySelect = Component.getDOMNode().querySelector("select");
expect(strategySelect.value).toEqual("default");
const strategySelect = Component.getDOMNode().querySelector('select');
expect(strategySelect.value).toEqual('default');
});
});
});

View File

@ -1,22 +1,22 @@
'use strict';
jest.dontMock("../../../components/feature/FeatureList");
jest.dontMock("../../../components/feature/Feature");
jest.dontMock('../../../components/feature/FeatureList');
jest.dontMock('../../../components/feature/Feature');
const React = require("react/addons");
const React = require('react/addons');
const TestUtils = React.addons.TestUtils;
const FeatureList = require("../../../components/feature/FeatureList");
const FeatureList = require('../../../components/feature/FeatureList');
describe("FeatureList", () => {
describe('FeatureList', () => {
let Component;
let features;
beforeEach(() => {
features = [
{ name: "featureX", strategy: "other" },
{ name: "group.featureY", strategy: "default" }
{ name: 'featureX', strategy: 'other' },
{ name: 'group.featureY', strategy: 'default' },
];
const strategies=[
{ name: "default" }
{ name: 'default' },
];
Component = TestUtils .renderIntoDocument(<FeatureList features={features} strategies={strategies} />);
});
@ -25,34 +25,34 @@ describe("FeatureList", () => {
React.unmountComponentAtNode(document.body);
});
it("should render all features", () => {
const features = Component.getDOMNode().querySelectorAll(".feature");
it('should render all features', () => {
const features = Component.getDOMNode().querySelectorAll('.feature');
expect(features.length).toEqual(2);
});
it("should filter list of features", () => {
it('should filter list of features', () => {
const filterNode = Component.refs.filter.getDOMNode();
TestUtils.Simulate.change(filterNode, { target: { value: "group" } });
TestUtils.Simulate.change(filterNode, { target: { value: 'group' } });
const features = Component.getDOMNode().querySelectorAll(".feature");
const features = Component.getDOMNode().querySelectorAll('.feature');
expect(features.length).toEqual(1);
});
it("should filter list of features ignoring case", () => {
it('should filter list of features ignoring case', () => {
const filterNode = Component.refs.filter.getDOMNode();
TestUtils.Simulate.change(filterNode, { target: { value: "GROUP" } });
TestUtils.Simulate.change(filterNode, { target: { value: 'GROUP' } });
const features = Component.getDOMNode().querySelectorAll(".feature");
const features = Component.getDOMNode().querySelectorAll('.feature');
expect(features.length).toEqual(1);
expect(features[0].textContent).toMatch("group");
expect(features[0].textContent).toMatch('group');
});
it("should filter list of features by strategy name", () => {
const searchString = "other";
it('should filter list of features by strategy name', () => {
const searchString = 'other';
const filterNode = Component.refs.filter.getDOMNode();
TestUtils.Simulate.change(filterNode, { target: { value: searchString } });
const features = Component.getDOMNode().querySelectorAll(".feature");
const features = Component.getDOMNode().querySelectorAll('.feature');
expect(features.length).toEqual(1);
expect(features[0].textContent).toMatch(searchString);
});

View File

@ -12,7 +12,7 @@ describe('FeatureToggleStore', () => {
Actions = require('../../stores/FeatureToggleActions');
Store = require('../../stores/FeatureToggleStore');
toggles = [
{ name: "app.feature", enabled: true, strategy: "default" }
{ name: 'app.feature', enabled: true, strategy: 'default' },
];
});
@ -25,19 +25,19 @@ describe('FeatureToggleStore', () => {
jest.runAllTimers();
expect(Store.getFeatureToggles().length).toBe(1);
expect(Store.getFeatureToggles()[0].name).toEqual("app.feature");
expect(Store.getFeatureToggles()[0].name).toEqual('app.feature');
});
it('should add a another toggle', () => {
Actions.init.completed(toggles);
const newToggle = { name: "app.featureB", enabled: true, strategy: "default" };
const newToggle = { name: 'app.featureB', enabled: true, strategy: 'default' };
Actions.create.completed(newToggle);
jest.runAllTimers();
expect(Store.getFeatureToggles().length).toBe(2);
expect(Store.getFeatureToggles()[1].name).toEqual("app.featureB");
expect(Store.getFeatureToggles()[1].name).toEqual('app.featureB');
});
it('should archive toggle', () => {
@ -51,17 +51,17 @@ describe('FeatureToggleStore', () => {
it('should keep toggles in sorted order', () => {
Actions.init.completed([
{ name: "A" },
{ name: "B" },
{ name: "C" }
{ name: 'A' },
{ name: 'B' },
{ name: 'C' },
]);
Actions.create.completed({ name: "AA" });
Actions.create.completed({ name: 'AA' });
jest.runAllTimers();
expect(Store.getFeatureToggles()[0].name).toEqual("A");
expect(Store.getFeatureToggles()[1].name).toEqual("AA");
expect(Store.getFeatureToggles()[3].name).toEqual("C");
expect(Store.getFeatureToggles()[0].name).toEqual('A');
expect(Store.getFeatureToggles()[1].name).toEqual('AA');
expect(Store.getFeatureToggles()[3].name).toEqual('C');
});
it('should update toggle', () => {

View File

@ -6,23 +6,23 @@ const ErrorActions = require('../stores/ErrorActions');
const ErrorMessages = React.createClass({
getInitialState() {
return {
errors: ErrorStore.getErrors()
};
return {
errors: ErrorStore.getErrors(),
};
},
onStoreChange() {
this.setState({
errors: ErrorStore.getErrors()
});
this.setState({
errors: ErrorStore.getErrors(),
});
},
componentDidMount() {
this.unsubscribe = ErrorStore.listen(this.onStoreChange);
this.unsubscribe = ErrorStore.listen(this.onStoreChange);
},
componentWillUnmount() {
this.unsubscribe();
this.unsubscribe();
},
onClearErrors() {
@ -33,7 +33,7 @@ const ErrorMessages = React.createClass({
return (
<Ui errors={this.state.errors} onClearErrors={this.onClearErrors}></Ui>
);
}
},
});
module.exports = ErrorMessages;

View File

@ -29,7 +29,7 @@ const ErrorMessages = React.createClass({
</div>
</div>
);
}
},
});
module.exports = ErrorMessages;

View File

@ -57,7 +57,7 @@ const Menu = React.createClass({
</div>
</div>
);
}
},
});
module.exports = Menu;

View File

@ -4,13 +4,13 @@ const UserStore = require('../stores/UserStore');
const User = React.createClass({
onSave() {
const value = this.refs.username.getDOMNode().value.trim();
UserStore.set(value);
},
onSave() {
const value = this.refs.username.getDOMNode().value.trim();
UserStore.set(value);
},
render() {
return (
render() {
return (
<div className="r-pvm">
<input type="text" placeholder="username"
ref="username"
@ -18,7 +18,7 @@ const User = React.createClass({
onBlur={this.onSave} />
</div>
);
}
},
});
module.exports = User;

View File

@ -1,5 +1,5 @@
'use strict';
const React = require("react");
const React = require('react');
const FeatureActions = require('../../stores/FeatureToggleActions');
const ArchiveFeatureComponent = React.createClass({
@ -41,7 +41,7 @@ const ArchiveFeatureComponent = React.createClass({
</button>
</td>
</tr>);
}
},
});
module.exports = ArchiveFeatureComponent;

View File

@ -9,22 +9,22 @@ const Feature = React.createClass({
return {
editMode: false,
showHistory: false,
events: []
events: [],
};
},
handleEventsResponse(response) {
this.setState({events: response});
this.setState({ events: response });
},
toggleHistory() {
eventStore.getEventsByName(this.props.feature.name).then(this.handleEventsResponse);
this.setState({showHistory: !this.state.showHistory});
this.setState({ showHistory: !this.state.showHistory });
},
toggleEditMode() {
this.setState({editMode: !this.state.editMode});
this.setState({ editMode: !this.state.editMode });
},
saveFeature(feature) {
@ -51,16 +51,15 @@ const Feature = React.createClass({
</td>
</tr>
);
},
render() {
return (
<tbody className="feature">
<tr className={this.state.editMode ? "edit bg-lilac-xlt" : ""}>
<tr className={this.state.editMode ? 'edit bg-lilac-xlt' : ''}>
<td width="20">
<span className=
{this.props.feature.enabled ? "toggle-active" : "toggle-inactive"} title="Status">
{this.props.feature.enabled ? 'toggle-active' : 'toggle-inactive'} title="Status">
</span>
</td>
<td>
@ -78,23 +77,23 @@ const Feature = React.createClass({
<div className="line">
<div className="unit size1of3">
<button
title='Archive'
title="Archive"
onClick={this.archiveFeature}>
<span className="icon-kryss1" />
</button>
</div>
<div className="unit size1of3">
<button
className={this.state.editMode ? "primary" : ""}
title='Edit'
className={this.state.editMode ? 'primary' : ''}
title="Edit"
onClick={this.toggleEditMode}>
<span className="icon-redigere" />
</button>
</div>
<div className="unit size1of3">
<button
className={this.state.showHistory ? "primary" : ""}
title='History'
className={this.state.showHistory ? 'primary' : ''}
title="History"
onClick={this.toggleHistory}>
<span className="icon-visning_liste" />
</button>
@ -118,7 +117,7 @@ const Feature = React.createClass({
<LogEntryList events={this.state.events} />
</td>
</tr>);
}
},
});

View File

@ -7,38 +7,38 @@ const FeatureForm = React.createClass({
return {
strategyOptions: this.props.strategies,
requiredParams: [],
currentStrategy: this.props.feature ? this.props.feature.strategy : "default"
currentStrategy: this.props.feature ? this.props.feature.strategy : 'default',
};
},
componentWillMount() {
if(this.props.feature) {
if (this.props.feature) {
this.setSelectedStrategy(this.props.feature.strategy);
}
},
onStrategyChange(e) {
this.setSelectedStrategy(e.target.value);
this.setState({currentStrategy: e.target.value});
this.setState({ currentStrategy: e.target.value });
},
getParameterValue(name) {
if(this.props.feature && this.props.feature.parameters) {
if (this.props.feature && this.props.feature.parameters) {
return this.props.feature.parameters[name];
} else {
return "";
return '';
}
},
setSelectedStrategy(name) {
const selectedStrategy = this.props.strategies.filter(strategy => strategy.name === name)[0];
if(selectedStrategy) {
if (selectedStrategy) {
this.setStrategyParams(selectedStrategy);
} else {
this.setState({
currentStrategy: 'default',
requiredParams: []
requiredParams: [],
});
}
},
@ -46,17 +46,17 @@ const FeatureForm = React.createClass({
setStrategyParams(strategy) {
const requiredParams = [];
let key;
for(key in strategy.parametersTemplate) {
requiredParams.push({name: key, value: this.getParameterValue(key)});
for (key in strategy.parametersTemplate) {
requiredParams.push({ name: key, value: this.getParameterValue(key) });
}
this.setState({requiredParams});
this.setState({ requiredParams });
},
render() {
const feature = this.props.feature || {
name: '',
strategy: 'default',
enabled: false
enabled: false,
};
const idPrefix = this.props.feature ? this.props.feature.name : 'new';
@ -66,7 +66,7 @@ const FeatureForm = React.createClass({
<form ref="form" className="r-size1of2">
<fieldset>
{this.props.feature ? "" : <legend>Create new toggle</legend>}
{this.props.feature ? '' : <legend>Create new toggle</legend>}
<TextInput
id={`${idPrefix}-name`}
@ -150,7 +150,7 @@ const FeatureForm = React.createClass({
description: this.refs.description.getValue(),
strategy: this.state.currentStrategy,
enabled: this.refs.enabled.getDOMNode().checked,
parameters: this.getParameters()
parameters: this.getParameters(),
};
this.props.onSubmit(feature);
@ -167,7 +167,7 @@ const FeatureForm = React.createClass({
parameters[param.name] = this.refs[param.name].getValue();
});
return parameters;
}
},
});
module.exports = FeatureForm;

View File

@ -7,37 +7,35 @@ const noop = function() {};
const FeatureList = React.createClass({
propTypes: {
features: React.PropTypes.array.isRequired,
strategies: React.PropTypes.array.isRequired
strategies: React.PropTypes.array.isRequired,
},
getDefaultProps() {
return {
onFeatureChanged: noop,
onFeatureArchive: noop
onFeatureArchive: noop,
};
},
getInitialState() {
return {
filter: undefined
filter: undefined,
};
},
onFilterChange(e) {
e.preventDefault();
this.setState({filter: e.target.value.trim()});
this.setState({ filter: e.target.value.trim() });
},
filteredFeatures() {
if(this.state.filter) {
const regex = new RegExp(this.state.filter, "i");
if (this.state.filter) {
const regex = new RegExp(this.state.filter, 'i');
return this.props.features.filter(item => regex.test(item.name) || regex.test(item.strategy));
} else {
return this.props.features;
}
},
render() {
@ -50,8 +48,8 @@ const FeatureList = React.createClass({
/>);
return (
<div className=''>
<table className='outerborder man'>
<div className="">
<table className="outerborder man">
<thead>
<tr>
<th></th>
@ -78,7 +76,7 @@ const FeatureList = React.createClass({
</table>
</div>
);
}
},
});
module.exports = FeatureList;

View File

@ -8,12 +8,12 @@ const ErrorActions = require('../../stores/ErrorActions');
const FeatureTogglesComponent = React.createClass({
getInitialState() {
return {
createView: false
createView: false,
};
},
updateFeature(feature) {
FeatureActions.update.triggerPromise(feature);
FeatureActions.update.triggerPromise(feature);
},
archiveFeature(feature) {
@ -26,11 +26,11 @@ const FeatureTogglesComponent = React.createClass({
},
newFeature() {
this.setState({createView: true});
this.setState({ createView: true });
},
cancelNewFeature() {
this.setState({createView: false});
this.setState({ createView: false });
ErrorActions.clear();
},
@ -55,15 +55,15 @@ const FeatureTogglesComponent = React.createClass({
},
renderCreateView() {
return <FeatureForm
return (<FeatureForm
onCancel={this.cancelNewFeature}
onSubmit={this.createFeature}
strategies={this.props.strategies} />;
strategies={this.props.strategies} />);
},
renderCreateButton() {
return <button className="mal" onClick={this.newFeature}>Create feature toggle</button>;
}
},
});
module.exports = FeatureTogglesComponent;

View File

@ -8,12 +8,12 @@ const TextInput = React.createClass({
id: React.PropTypes.string.isRequired,
placeholder: React.PropTypes.string,
value: React.PropTypes.string,
required: React.PropTypes.bool
required: React.PropTypes.bool,
},
getDefaultProps() {
return {
required: false
required: false,
};
},
@ -41,7 +41,7 @@ const TextInput = React.createClass({
</div>
</div>
);
}
},
});
module.exports = TextInput;
module.exports = TextInput;

View File

@ -8,18 +8,18 @@ const LogEntriesComponent = React.createClass({
getInitialState() {
return {
createView: false,
events: []
events: [],
};
},
componentDidMount() {
eventStore.getEvents().then(res => {
this.setState({events: res.events});
this.setState({ events: res.events });
}, this.initError);
},
initError() {
ErrorActions.error("Could not load events from server");
ErrorActions.error('Could not load events from server');
},
render() {

View File

@ -6,7 +6,7 @@ const DIFF_PREFIXES = {
A: ' ',
E: ' ',
D: '-',
N: '+'
N: '+',
};
const SPADEN_CLASS = {
@ -18,7 +18,7 @@ const SPADEN_CLASS = {
const LogEntry = React.createClass({
propTypes: {
event: React.PropTypes.object.isRequired
event: React.PropTypes.object.isRequired,
},
render() {
@ -33,7 +33,7 @@ const LogEntry = React.createClass({
<td>
<strong>{this.props.event.data.name}</strong><em>[{this.props.event.type}]</em>
</td>
<td style={{maxWidth: 300}}>
<td style={{ maxWidth: 300 }}>
{this.renderEventDiff()}
</td>
<td>{this.props.event.createdBy}</td>
@ -48,14 +48,14 @@ const LogEntry = React.createClass({
const prettyPrinted = JSON.stringify(localEventData, null, 2);
return (<code className='JSON smalltext man'>{prettyPrinted}</code>);
return (<code className="JSON smalltext man">{prettyPrinted}</code>);
},
renderEventDiff() {
if (!this.props.showFullEvents && this.props.event.diffs) {
const changes = this.props.event.diffs.map(this.buildDiff);
return (
<code className='smalltext man'>{changes.length === 0 ? '(no changes)' : changes}</code>
<code className="smalltext man">{changes.length === 0 ? '(no changes)' : changes}</code>
);
} else {
return this.renderFullEventData();
@ -81,7 +81,7 @@ const LogEntry = React.createClass({
}
return (<div key={idx}>{change}</div>);
}
},
});

View File

@ -4,12 +4,12 @@ const LogEntry = require('./LogEntry');
const LogEntryList = React.createClass({
propTypes: {
events: React.PropTypes.array.isRequired
events: React.PropTypes.array.isRequired,
},
getInitialState() {
return {
showFullEvents: false
showFullEvents: false,
};
},
@ -28,7 +28,7 @@ const LogEntryList = React.createClass({
</input>
</label>
<table className='outerborder zebra-striped'>
<table className="outerborder zebra-striped">
<thead>
<tr>
<th>When</th>
@ -48,8 +48,8 @@ const LogEntryList = React.createClass({
},
toggleFullEvents() {
this.setState({showFullEvents: !this.state.showFullEvents});
}
this.setState({ showFullEvents: !this.state.showFullEvents });
},
});

View File

@ -7,16 +7,16 @@ const StrategyActions = require('../../stores/StrategyActions');
const StrategiesComponent = React.createClass({
getInitialState() {
return {
createView: false
createView: false,
};
},
onNewStrategy() {
this.setState({createView: true});
this.setState({ createView: true });
},
onCancelNewStrategy() {
this.setState({createView: false});
this.setState({ createView: false });
},
onSave(strategy) {
@ -48,15 +48,15 @@ const StrategiesComponent = React.createClass({
onCancelNewStrategy={this.onCancelNewStrategy}
onSave={this.onSave}
/>);
},
},
renderCreateButton() {
return (
renderCreateButton() {
return (
<button className="mal" onClick={this.onNewStrategy}>
Create strategy
</button>
);
}
});
},
});
module.exports = StrategiesComponent;

View File

@ -3,7 +3,7 @@ const React = require('react');
const Strategy = React.createClass({
propTypes: {
strategy: React.PropTypes.object.isRequired
strategy: React.PropTypes.object.isRequired,
},
onRemove(event) {
@ -25,7 +25,7 @@ const Strategy = React.createClass({
</div>
</div>
);
}
},
});
module.exports = Strategy;

View File

@ -6,13 +6,13 @@ const StrategyForm = React.createClass({
getDefaultProps() {
return {
maxParams: 4
maxParams: 4,
};
},
getInitialState() {
return {
parameters: []
parameters: [],
};
},
@ -27,9 +27,9 @@ const StrategyForm = React.createClass({
const that = this;
this.state.parameters.forEach(parameter => {
const name = that.refs[parameter.name].getDOMNode().value.trim();
if(name) {
strategy.parametersTemplate[name] = "string";
const name = that.refs[parameter.name].getDOMNode().value.trim();
if (name) {
strategy.parametersTemplate[name] = 'string';
}
});
@ -45,15 +45,15 @@ const StrategyForm = React.createClass({
onAddParam(event) {
event.preventDefault();
const id = this.state.parameters.length + 1;
const params = this.state.parameters.concat([{id, name: `param_${id}`, label: `Parameter ${id}`}]);
this.setState({parameters: params});
const params = this.state.parameters.concat([{ id, name: `param_${id}`, label: `Parameter ${id}` }]);
this.setState({ parameters: params });
},
onRemoveParam(event) {
event.preventDefault();
const params = this.state.parameters.slice(0, -1);
this.setState({parameters: params});
this.setState({ parameters: params });
},
render() {
@ -119,12 +119,12 @@ const StrategyForm = React.createClass({
},
renderAddLink() {
if(this.state.parameters.length < this.props.maxParams) {
if (this.state.parameters.length < this.props.maxParams) {
return <a href="#add" onClick={this.onAddParam}>+ Add required parameter</a>;
}
},
renderRemoveLink() {
if(this.state.parameters.length > 0) {
if (this.state.parameters.length > 0) {
return (
<div className="formelement mtn">
<a href="#add"
@ -135,7 +135,7 @@ const StrategyForm = React.createClass({
</div>
);
}
}
},
});
module.exports = StrategyForm;

View File

@ -4,7 +4,7 @@ const Strategy = require('./Strategy');
const StrategyList = React.createClass({
propTypes: {
strategies: React.PropTypes.array.isRequired
strategies: React.PropTypes.array.isRequired,
},
render() {
@ -12,7 +12,7 @@ const StrategyList = React.createClass({
return (
<div>{strategyNodes}</div>
);
}
},
});
module.exports = StrategyList;
module.exports = StrategyList;

View File

@ -40,7 +40,7 @@ const FeatureStore = Reflux.createStore({
initStore(archivedToggles) {
_archivedToggles = archivedToggles;
}
},
});
module.exports = FeatureStore;

View File

@ -2,8 +2,8 @@
const Reflux = require('reflux');
const ErrorActions = Reflux.createActions([
"clear",
"error"
'clear',
'error',
]);
module.exports = ErrorActions;

View File

@ -24,7 +24,7 @@ const FeatureStore = Reflux.createStore({
this.addError(e.msg);
});
} else if (error.status === 0) {
this.addError("server unreachable");
this.addError('server unreachable');
} else {
this.addError(error);
}
@ -52,7 +52,7 @@ const FeatureStore = Reflux.createStore({
} catch (e) {
if (e instanceof SyntaxError) {
// fall through;
console.log("Syntax error!");
console.log('Syntax error!');
} else {
throw e;
}
@ -63,7 +63,7 @@ const FeatureStore = Reflux.createStore({
getErrors() {
return this.errors;
}
},
});
module.exports = FeatureStore;

View File

@ -8,7 +8,7 @@ const EventStore = {
return reqwest({
url: 'events',
method: 'get',
type: TYPE
type: TYPE,
});
},
@ -16,9 +16,9 @@ const EventStore = {
return reqwest({
url: `events/${name}`,
method: 'get',
type: TYPE
type: TYPE,
});
}
},
};

View File

@ -1,5 +1,5 @@
'use strict';
const Reflux = require("reflux");
const Reflux = require('reflux');
const Server = require('./FeatureToggleServerFacade');
const FeatureToggleActions = Reflux.createActions({
@ -8,7 +8,7 @@ const FeatureToggleActions = Reflux.createActions({
create: { asyncResult: true },
update: { asyncResult: true },
archive: { asyncResult: true },
revive: { asyncResult: true }
revive: { asyncResult: true },
});
FeatureToggleActions.init.listen(function() {

View File

@ -17,7 +17,7 @@ const FeatureToggleServerFacade = {
},
success() {
cb();
}
},
});
},
@ -33,7 +33,7 @@ const FeatureToggleServerFacade = {
},
success() {
cb();
}
},
});
},
@ -47,7 +47,7 @@ const FeatureToggleServerFacade = {
},
success() {
cb();
}
},
});
},
@ -61,7 +61,7 @@ const FeatureToggleServerFacade = {
},
success(data) {
cb(null, data.features);
}
},
});
},
@ -75,7 +75,7 @@ const FeatureToggleServerFacade = {
},
success(data) {
cb(null, data.features);
}
},
});
},
@ -91,9 +91,9 @@ const FeatureToggleServerFacade = {
},
success() {
cb();
}
},
});
}
},
};
module.exports = FeatureToggleServerFacade;

View File

@ -50,7 +50,7 @@ const FeatureStore = Reflux.createStore({
initStore(toggles) {
_featureToggles = toggles;
}
},
});
module.exports = FeatureStore;

View File

@ -17,7 +17,7 @@ const StrategyAPI = {
},
success() {
cb(null, strategy);
}
},
});
},
@ -31,7 +31,7 @@ const StrategyAPI = {
},
success() {
cb(null, strategy);
}
},
});
},
@ -45,9 +45,9 @@ const StrategyAPI = {
},
success(data) {
cb(null, data.strategies);
}
},
});
}
},
};
module.exports = StrategyAPI;

View File

@ -1,5 +1,5 @@
'use strict';
const Reflux = require("reflux");
const Reflux = require('reflux');
const StrategyAPI = require('./StrategyAPI');
const StrategyActions = Reflux.createActions({

View File

@ -35,7 +35,7 @@ const StrategyStore = Reflux.createStore({
initStore(strategies) {
_strategies = strategies;
}
},
});
module.exports = StrategyStore;

View File

@ -19,7 +19,7 @@ function readCookie(name) {
const UserStore = {
init() {
_username = readCookie("username");
_username = readCookie('username');
},
set(username) {
@ -29,7 +29,7 @@ const UserStore = {
get() {
return _username;
}
},
};
module.exports = UserStore;

View File

@ -7,7 +7,7 @@ const Timer = function(cb, interval) {
Timer.prototype.start = function() {
if (this.timerId != null) {
console.warn("timer already started");
console.warn('timer already started');
}
console.log('starting timer');

View File

@ -14,25 +14,25 @@ module.exports = {
output: {
path: jsroot,
filename: 'bundle.js',
publicPath: '/js/'
publicPath: '/js/',
},
resolve: {
root: [jsroot],
extensions: ['', '.js', '.jsx'],
modulesDirectories: ["web_modules", "node_modules"]
modulesDirectories: ['web_modules', 'node_modules'],
},
module: {
loaders: [
{ test: /\.jsx$/, loader: 'jsx?harmony' }
]
{ test: /\.jsx$/, loader: 'jsx?harmony' },
],
},
devtool: "source-map",
devtool: 'source-map',
externals: {
// stuff not in node_modules can be resolved here.
}
},
};