ConfigDB: Refactor updateFromAdmin in reducers/soapbox
This commit is contained in:
parent
e1a86d4e1c
commit
48d0572403
4 changed files with 2768 additions and 3 deletions
2735
app/soapbox/__fixtures__/config_db.json
Normal file
2735
app/soapbox/__fixtures__/config_db.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,12 +1,21 @@
|
|||
import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin';
|
||||
import { SOAPBOX_CONFIG_REQUEST_SUCCESS } from '../actions/soapbox';
|
||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||
import { ConfigDB } from 'soapbox/utils/config_db';
|
||||
|
||||
const initialState = ImmutableMap();
|
||||
|
||||
const updateFromAdmin = (state, config) => {
|
||||
// TODO: Generalize this with an API similar to `Pleroma.Config` in Pleroma BE
|
||||
return config.getIn(['configs', 0, 'value', 0, 'tuple', 1], state);
|
||||
const configs = config.get('configs', ImmutableList());
|
||||
|
||||
try {
|
||||
return ConfigDB.find(configs, ':pleroma', ':frontend_configurations')
|
||||
.get('value')
|
||||
.find(value => value.getIn(['tuple', 0] === ':soapbox_fe'))
|
||||
.getIn(['tuple', 1]);
|
||||
} catch {
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default function soapbox(state = initialState, action) {
|
||||
|
|
12
app/soapbox/utils/__tests__/config_db-test.js
Normal file
12
app/soapbox/utils/__tests__/config_db-test.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { ConfigDB } from '../config_db';
|
||||
import config_db from 'soapbox/__fixtures__/config_db.json';
|
||||
import { fromJS } from 'immutable';
|
||||
|
||||
test('find', () => {
|
||||
const configs = fromJS(config_db).get('configs');
|
||||
expect(ConfigDB.find(configs, ':phoenix', ':json_library')).toEqual(fromJS({
|
||||
group: ':phoenix',
|
||||
key: ':json_library',
|
||||
value: 'Jason',
|
||||
}));
|
||||
});
|
9
app/soapbox/utils/config_db.js
Normal file
9
app/soapbox/utils/config_db.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
export const ConfigDB = {
|
||||
find: (configs, group, key) => {
|
||||
return configs.find(config =>
|
||||
config.isSuperset({ group, key })
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export default ConfigDB;
|
Loading…
Reference in a new issue