Merge pull request #4813 from abpframework/feat/4812

Added getFeature method to ConfigStateService
pull/4823/head
Levent Arman Özak 5 years ago committed by GitHub
commit b491e8fff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -127,6 +127,17 @@ const defaultLang = this.config.getSetting("Abp.Localization.DefaultLanguage");
// 'en'
```
### How to Get a Specific Feature From the Store
You can use the `getFeature` method of `ConfigStateService` to get a specific feature from the configuration state. Here is an example:
```js
// this.config is instance of ConfigStateService
const isChatEnabled = this.config.getFeature("Chat.Enable");
// 'en'
```
### How to Get a Specific Permission From the Store
You can use the `getGrantedPolicy` method of `ConfigStateService` to get a specific permission from the configuration state. For that, you should pass a policy key as parameter to the method.

@ -29,6 +29,10 @@ export class ConfigStateService {
return this.store.selectSnapshot(ConfigState.getApiUrl(...args));
}
getFeature(...args: Parameters<typeof ConfigState.getFeature>) {
return this.store.selectSnapshot(ConfigState.getFeature(...args));
}
getSetting(...args: Parameters<typeof ConfigState.getSetting>) {
return this.store.selectSnapshot(ConfigState.getSetting(...args));
}

@ -65,6 +65,14 @@ export class ConfigState {
return selector;
}
static getFeature(key: string) {
const selector = createSelector([ConfigState], (state: Config.State) => {
return snq(() => state.features.values[key]);
});
return selector;
}
static getSetting(key: string) {
const selector = createSelector([ConfigState], (state: Config.State) => {
return snq(() => state.setting.values[key]);

@ -93,7 +93,9 @@ export const CONFIG_STATE_DATA = {
roles: [],
},
features: {
values: {},
values: {
'Chat.Enable': 'True',
},
},
} as Config.State;
@ -163,6 +165,14 @@ describe('ConfigState', () => {
});
});
describe('#getFeature', () => {
it('should return a setting', () => {
expect(ConfigState.getFeature('Chat.Enable')(CONFIG_STATE_DATA)).toEqual(
CONFIG_STATE_DATA.features.values['Chat.Enable'],
);
});
});
describe('#getSetting', () => {
it('should return a setting', () => {
expect(ConfigState.getSetting('Abp.Localization.DefaultLanguage')(CONFIG_STATE_DATA)).toEqual(

Loading…
Cancel
Save