|
|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import { AnyAction, Dispatch, ActionCreator } from 'redux';
|
|
|
|
|
import { ThunkAction } from 'redux-thunk';
|
|
|
|
|
import { ActionUnion, createAction, ThunkAction } from 'utils/redux';
|
|
|
|
|
import { SupportedPlugins } from 'reducers/interfaces';
|
|
|
|
|
import PluginChecker from 'utils/plugin-checker';
|
|
|
|
|
|
|
|
|
|
@ -8,49 +7,45 @@ export enum PluginsActionTypes {
|
|
|
|
|
CHECKED_ALL_PLUGINS = 'CHECKED_ALL_PLUGINS'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface PluginObjects {
|
|
|
|
|
[plugin: string]: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkPlugins(): AnyAction {
|
|
|
|
|
const action = {
|
|
|
|
|
type: PluginsActionTypes.CHECK_PLUGINS,
|
|
|
|
|
payload: {},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return action;
|
|
|
|
|
}
|
|
|
|
|
type PluginObjects = Record<SupportedPlugins, boolean>;
|
|
|
|
|
|
|
|
|
|
function checkedAllPlugins(list: PluginObjects): AnyAction {
|
|
|
|
|
const action = {
|
|
|
|
|
type: PluginsActionTypes.CHECKED_ALL_PLUGINS,
|
|
|
|
|
payload: {
|
|
|
|
|
const pluginActions = {
|
|
|
|
|
checkPlugins: () => createAction(PluginsActionTypes.CHECK_PLUGINS),
|
|
|
|
|
checkedAllPlugins: (list: PluginObjects) => (
|
|
|
|
|
createAction(PluginsActionTypes.CHECKED_ALL_PLUGINS, {
|
|
|
|
|
list,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function checkPluginsAsync():
|
|
|
|
|
ThunkAction<Promise<void>, {}, {}, AnyAction> {
|
|
|
|
|
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
|
|
|
|
|
dispatch(checkPlugins());
|
|
|
|
|
const plugins: PluginObjects = {};
|
|
|
|
|
|
|
|
|
|
const promises: Promise<boolean>[] = [];
|
|
|
|
|
const keys = Object.keys(SupportedPlugins);
|
|
|
|
|
for (const key of keys) {
|
|
|
|
|
const plugin = SupportedPlugins[key as any];
|
|
|
|
|
promises.push(PluginChecker.check(plugin as SupportedPlugins));
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type PluginActions = ActionUnion<typeof pluginActions>;
|
|
|
|
|
|
|
|
|
|
export function checkPluginsAsync(): ThunkAction {
|
|
|
|
|
return async (dispatch): Promise<void> => {
|
|
|
|
|
dispatch(pluginActions.checkPlugins());
|
|
|
|
|
const plugins: PluginObjects = {
|
|
|
|
|
ANALYTICS: false,
|
|
|
|
|
AUTO_ANNOTATION: false,
|
|
|
|
|
GIT_INTEGRATION: false,
|
|
|
|
|
TF_ANNOTATION: false,
|
|
|
|
|
TF_SEGMENTATION: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const promises: Promise<boolean>[] = [
|
|
|
|
|
PluginChecker.check(SupportedPlugins.ANALYTICS),
|
|
|
|
|
PluginChecker.check(SupportedPlugins.AUTO_ANNOTATION),
|
|
|
|
|
PluginChecker.check(SupportedPlugins.GIT_INTEGRATION),
|
|
|
|
|
PluginChecker.check(SupportedPlugins.TF_ANNOTATION),
|
|
|
|
|
PluginChecker.check(SupportedPlugins.TF_SEGMENTATION),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const values = await Promise.all(promises);
|
|
|
|
|
let i = 0;
|
|
|
|
|
for (const key of keys) {
|
|
|
|
|
plugins[key] = values[i++];
|
|
|
|
|
}
|
|
|
|
|
[plugins.ANALYTICS] = values;
|
|
|
|
|
[, plugins.AUTO_ANNOTATION] = values;
|
|
|
|
|
[,, plugins.GIT_INTEGRATION] = values;
|
|
|
|
|
[,,, plugins.TF_ANNOTATION] = values;
|
|
|
|
|
[,,,, plugins.TF_SEGMENTATION] = values;
|
|
|
|
|
|
|
|
|
|
dispatch(checkedAllPlugins(plugins));
|
|
|
|
|
dispatch(pluginActions.checkedAllPlugins(plugins));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|