Skip to content

Commit

Permalink
refactor: run Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
MrChocolatine committed Nov 4, 2023
1 parent 7dfc7bc commit d55147f
Show file tree
Hide file tree
Showing 29 changed files with 265 additions and 211 deletions.
10 changes: 3 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict'

module.exports = {
root: true,
Expand All @@ -7,11 +7,7 @@ module.exports = {
ecmaVersion: 'latest',
},
plugins: ['ember', '@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
extends: ['eslint:recommended', 'plugin:ember/recommended', 'plugin:prettier/recommended'],
env: {
browser: true,
},
Expand Down Expand Up @@ -55,4 +51,4 @@ module.exports = {
extends: ['plugin:qunit/recommended'],
},
],
};
}
4 changes: 2 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict'

module.exports = {
overrides: [
Expand All @@ -10,4 +10,4 @@ module.exports = {
},
},
],
};
}
4 changes: 2 additions & 2 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
'use strict'

module.exports = {
extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],
};
}
20 changes: 10 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

## Installation

* `git clone <repository-url>`
* `cd ember-feature-controls`
* `yarn install`
- `git clone <repository-url>`
- `cd ember-feature-controls`
- `yarn install`

## Linting

* `yarn lint`
* `yarn lint:fix`
- `yarn lint`
- `yarn lint:fix`

## Running tests

* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions
- `ember test` – Runs the test suite on the current Ember version
- `ember test --server` – Runs the test suite in "watch mode"
- `ember try:each` – Runs the test suite against multiple Ember versions

## Running the dummy application

* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).
- `ember serve`
- Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://cli.emberjs.com/release/](https://cli.emberjs.com/release/).
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Demo is available here: [https://dazzlingfugu.github.io/ember-feature-controls/]

## Compatibility

* Ember.js v4.8 or above
* Ember CLI v4.8 or above
* Node.js v18 or above
- Ember.js v4.8 or above
- Ember CLI v4.8 or above
- Node.js v18 or above

## Installation

Expand Down Expand Up @@ -73,30 +73,30 @@ Then, you can configure a set of metadata for your feature flags by defining the

```js
// config/environment.js
module.exports = function(environment) {
module.exports = function (environment) {
var ENV = {
featureFlags: {
"show-spinners": true,
"download-cats": false
"download-cats": false,
},
featureControls: {
useLocalStorage: true,
metadata: [
{
key: "show-spinners",
description: "Show spinners"
description: "Show spinners",
},
{
key: "download-cats",
description: "Add button to download cats image",
reload: true
reload: true,
},
{
key: "easter-egg",
hide: true
}
]
}
hide: true,
},
],
},
};

return ENV;
Expand Down
2 changes: 1 addition & 1 deletion addon/components/feature-controls.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{!-- template-lint-disable no-bare-strings --}}
{{! template-lint-disable no-bare-strings }}

<table class="ember-feature-controls-table">
<thead>
Expand Down
36 changes: 23 additions & 13 deletions addon/components/feature-controls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Component from '@glimmer/component'
import { get, set, action } from '@ember/object'
import { inject as service } from '@ember/service'
import { service } from '@ember/service'
import { camelize } from '@ember/string'
import { assign } from '@ember/polyfills'
import windowUtil from 'ember-feature-controls/utils/window'
Expand All @@ -15,9 +15,7 @@ export default class FeatureControlsComponent extends Component {
}

get featureControls() {
return this.args.featureControls
? this.args.featureControls
: this._featureControls
return this.args.featureControls ? this.args.featureControls : this._featureControls
}

get showRefresh() {
Expand All @@ -30,8 +28,9 @@ export default class FeatureControlsComponent extends Component {

constructor() {
super(...arguments)
let { featureFlags, featureControls } =
getOwner(this).resolveRegistration('config:environment')

let { featureFlags, featureControls } = getOwner(this).resolveRegistration('config:environment')

this._featureFlags = featureFlags
this._featureControls = featureControls
this.refresh()
Expand All @@ -47,46 +46,53 @@ export default class FeatureControlsComponent extends Component {
// Take the existing flags from the config and put them in a list of default values
let featureFlags = this.featureFlags
let defaults = {}

Object.keys(featureFlags).forEach(
(key) => (defaults[this._normalizeFlag(key)] = featureFlags[key])
(key) => (defaults[this._normalizeFlag(key)] = featureFlags[key]),
)

// Model is a local copy of the list of flags register for features service, used to compute properties on the full list
let model = (this.features.flags || []).map((key) => {
let meta =
((this.featureControls && this.featureControls.metadata) || []).find(
(obj) => {
return this._normalizeFlag(obj.key) === key
}
) || {}
((this.featureControls && this.featureControls.metadata) || []).find((obj) => {
return this._normalizeFlag(obj.key) === key
}) || {}

if (meta.hide === true) {
return undefined
}

let isFlagLS =
this.featureControls.useLocalStorage &&
get(this, `featureControlsStorage.featuresLS.${key}`) !== undefined

let featureFlag = {
key,
isEnabled: isFlagLS
? get(this, `featureControlsStorage.featuresLS.${key}`)
: this.features.isEnabled(key),
default: defaults[key] || false,
}

return assign({}, meta, featureFlag)
})

set(
this,
'model',
model.filter((item) => item !== undefined)
model.filter((item) => item !== undefined),
)
}

@action
reset() {
// Reset the flags from the features service to the default value in the config
let featureFlags = this.featureFlags

Object.keys(featureFlags).forEach((key) => {
this.updateFeature(this._normalizeFlag(key), featureFlags[key])
})

// If we use local storage then we want to clear the stored data
if (this.featureControls.useLocalStorage) {
this.featureControlsStorage.featuresLS.reset()
Expand All @@ -100,12 +106,15 @@ export default class FeatureControlsComponent extends Component {
} else {
this.features.disable(key)
}

// Update the local model accordingly
let modelFlag = this.model.find((obj) => {
return obj.key === key
})

if (modelFlag) {
set(modelFlag, 'isEnabled', isEnabled)

if (modelFlag.reload) {
windowUtil.reload()
}
Expand All @@ -115,6 +124,7 @@ export default class FeatureControlsComponent extends Component {
@action
doToggleFeature(key, checkboxState) {
this.updateFeature(key, !checkboxState)

if (this.featureControls.useLocalStorage) {
set(this, `featureControlsStorage.featuresLS.${key}`, !checkboxState)
}
Expand Down
10 changes: 5 additions & 5 deletions addon/instance-initializers/load-feature-controls.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export function initialize(appInstance) {
const features = appInstance.lookup('service:features')
const { featureControls } =
appInstance.resolveRegistration('config:environment')
const { featureControls } = appInstance.resolveRegistration('config:environment')

if (featureControls && featureControls.useLocalStorage) {
const storageService = appInstance.lookup(
'service:feature-controls-storage'
)
const storageService = appInstance.lookup('service:feature-controls-storage')

// result of storageService.get('featuresLS') is an ObjectProxy we need to use "content"
let { content: featureControls } = storageService.get('featuresLS')

if (featureControls) {
Object.keys(featureControls).forEach((flag) => {
if (features.get('flags').includes(flag)) {
Expand Down
2 changes: 1 addition & 1 deletion addon/templates/features-list.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{!-- template-lint-disable no-bare-strings --}}
{{! template-lint-disable no-bare-strings }}

<div class="ember-feature-controls">
<h1 class="ember-feature-controls-title">Feature Flags Controls Room</h1>
Expand Down
14 changes: 7 additions & 7 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
'use strict'

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon')

module.exports = function (defaults) {
const app = new EmberAddon(defaults, {
'ember-cli-babel': { enableTypeScriptTransform: true },

// Add options here
});
})

/*
This build file specifies the options for the dummy test app of this
Expand All @@ -17,7 +17,7 @@ module.exports = function (defaults) {
*/
app.import('node_modules/milligram/dist/milligram.css')

const { maybeEmbroider } = require('@embroider/test-setup');
const { maybeEmbroider } = require('@embroider/test-setup')
return maybeEmbroider(app, {
skipBabel: [
{
Expand All @@ -35,7 +35,7 @@ module.exports = function (defaults) {
* https://github.com/mansona/ember-get-config/pull/29
*/
compatAdapters: new Map([
[ 'ember-get-config', null ] // eslint-disable-line prettier/prettier
['ember-get-config', null], // eslint-disable-line prettier/prettier
]),
});
};
})
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
'use strict'

module.exports = {
name: require('./package').name,

options: {
'ember-cli-babel': { enableTypeScriptTransform: true },
},
};
}
4 changes: 2 additions & 2 deletions testem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict'

module.exports = {
test_page: 'tests/index.html?hidepassed',
Expand All @@ -20,4 +20,4 @@ module.exports = {
].filter(Boolean),
},
},
};
}
Loading

0 comments on commit d55147f

Please sign in to comment.