Add support for Applications

This commit is contained in:
nitsua
2020-10-20 14:15:05 -04:00
committed by Qstick
parent 191d06deca
commit 47fbab02c5
37 changed files with 1607 additions and 3 deletions

View File

@@ -0,0 +1,115 @@
import { createAction } from 'redux-actions';
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
import createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
import createSaveProviderHandler, { createCancelSaveProviderHandler } from 'Store/Actions/Creators/createSaveProviderHandler';
import createTestProviderHandler, { createCancelTestProviderHandler } from 'Store/Actions/Creators/createTestProviderHandler';
import createSetProviderFieldValueReducer from 'Store/Actions/Creators/Reducers/createSetProviderFieldValueReducer';
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
import { createThunk } from 'Store/thunks';
import selectProviderSchema from 'Utilities/State/selectProviderSchema';
//
// Variables
const section = 'settings.applications';
//
// Actions Types
export const FETCH_APPLICATIONS = 'settings/applications/fetchApplications';
export const FETCH_APPLICATION_SCHEMA = 'settings/applications/fetchApplicationSchema';
export const SELECT_APPLICATION_SCHEMA = 'settings/applications/selectApplicationSchema';
export const SET_APPLICATION_VALUE = 'settings/applications/setApplicationValue';
export const SET_APPLICATION_FIELD_VALUE = 'settings/applications/setApplicationFieldValue';
export const SAVE_APPLICATION = 'settings/applications/saveApplication';
export const CANCEL_SAVE_APPLICATION = 'settings/applications/cancelSaveApplication';
export const DELETE_APPLICATION = 'settings/applications/deleteApplication';
export const TEST_APPLICATION = 'settings/applications/testApplication';
export const CANCEL_TEST_APPLICATION = 'settings/applications/cancelTestApplication';
//
// Action Creators
export const fetchApplications = createThunk(FETCH_APPLICATIONS);
export const fetchApplicationSchema = createThunk(FETCH_APPLICATION_SCHEMA);
export const selectApplicationSchema = createAction(SELECT_APPLICATION_SCHEMA);
export const saveApplication = createThunk(SAVE_APPLICATION);
export const cancelSaveApplication = createThunk(CANCEL_SAVE_APPLICATION);
export const deleteApplication = createThunk(DELETE_APPLICATION);
export const testApplication = createThunk(TEST_APPLICATION);
export const cancelTestApplication = createThunk(CANCEL_TEST_APPLICATION);
export const setApplicationValue = createAction(SET_APPLICATION_VALUE, (payload) => {
return {
section,
...payload
};
});
export const setApplicationFieldValue = createAction(SET_APPLICATION_FIELD_VALUE, (payload) => {
return {
section,
...payload
};
});
//
// Details
export default {
//
// State
defaultState: {
isFetching: false,
isPopulated: false,
error: null,
isSchemaFetching: false,
isSchemaPopulated: false,
schemaError: null,
schema: [],
selectedSchema: {},
isSaving: false,
saveError: null,
isTesting: false,
items: [],
pendingChanges: {}
},
//
// Action Handlers
actionHandlers: {
[FETCH_APPLICATIONS]: createFetchHandler(section, '/applications'),
[FETCH_APPLICATION_SCHEMA]: createFetchSchemaHandler(section, '/applications/schema'),
[SAVE_APPLICATION]: createSaveProviderHandler(section, '/applications'),
[CANCEL_SAVE_APPLICATION]: createCancelSaveProviderHandler(section),
[DELETE_APPLICATION]: createRemoveItemHandler(section, '/applications'),
[TEST_APPLICATION]: createTestProviderHandler(section, '/applications'),
[CANCEL_TEST_APPLICATION]: createCancelTestProviderHandler(section)
},
//
// Reducers
reducers: {
[SET_APPLICATION_VALUE]: createSetSettingValueReducer(section),
[SET_APPLICATION_FIELD_VALUE]: createSetProviderFieldValueReducer(section),
[SELECT_APPLICATION_SCHEMA]: (state, { payload }) => {
return selectProviderSchema(state, section, payload, (selectedSchema) => {
selectedSchema.onGrab = selectedSchema.supportsOnGrab;
selectedSchema.onDownload = selectedSchema.supportsOnDownload;
selectedSchema.onUpgrade = selectedSchema.supportsOnUpgrade;
selectedSchema.onRename = selectedSchema.supportsOnRename;
return selectedSchema;
});
}
}
};

View File

@@ -1,6 +1,7 @@
import { createAction } from 'redux-actions';
import { handleThunks } from 'Store/thunks';
import createHandleActions from './Creators/createHandleActions';
import applications from './Settings/applications';
import general from './Settings/general';
import indexerFlags from './Settings/indexerFlags';
import indexerOptions from './Settings/indexerOptions';
@@ -13,6 +14,7 @@ export * from './Settings/indexerFlags';
export * from './Settings/indexerOptions';
export * from './Settings/languages';
export * from './Settings/notifications';
export * from './Settings/applications';
export * from './Settings/ui';
//
@@ -31,6 +33,7 @@ export const defaultState = {
indexerOptions: indexerOptions.defaultState,
languages: languages.defaultState,
notifications: notifications.defaultState,
applications: applications.defaultState,
ui: ui.defaultState
};
@@ -57,6 +60,7 @@ export const actionHandlers = handleThunks({
...indexerOptions.actionHandlers,
...languages.actionHandlers,
...notifications.actionHandlers,
...applications.actionHandlers,
...ui.actionHandlers
});
@@ -74,6 +78,7 @@ export const reducers = createHandleActions({
...indexerOptions.reducers,
...languages.reducers,
...notifications.reducers,
...applications.reducers,
...ui.reducers
}, defaultState, section);