|
|
@ -1,69 +1,51 @@ |
|
|
|
import React, { createContext, useEffect, useState } from 'react' |
|
|
|
import React, { createContext, useEffect, useState } from 'react' |
|
|
|
import { Profile } from '../customTypes' |
|
|
|
import { Profile, TileLabel } from '../customTypes' |
|
|
|
import { RemixAppManager, RemixEngine, _Paq } from '../types' |
|
|
|
import { RemixAppManager, RemixEngine, _Paq } from '../types' |
|
|
|
import RootView from './components/rootView' |
|
|
|
import RootView from './components/rootView' |
|
|
|
import './remix-ui-plugin-manager.css' |
|
|
|
import './remix-ui-plugin-manager.css' |
|
|
|
|
|
|
|
|
|
|
|
/* eslint-disable-next-line */ |
|
|
|
/* eslint-disable-next-line */ |
|
|
|
export interface RemixUiPluginManagerProps { |
|
|
|
export interface PluginManagerContextProviderProps { |
|
|
|
appManager: RemixAppManager |
|
|
|
appManager: RemixAppManager |
|
|
|
engine: RemixEngine |
|
|
|
engine: RemixEngine |
|
|
|
_paq: _Paq |
|
|
|
_paq: _Paq |
|
|
|
filter: string |
|
|
|
filter: string |
|
|
|
|
|
|
|
actives: Profile[] |
|
|
|
|
|
|
|
inactives: Profile[] |
|
|
|
activatePlugin: (name: string) => void |
|
|
|
activatePlugin: (name: string) => void |
|
|
|
deActivatePlugin: (name: string) => void |
|
|
|
deActivatePlugin: (name: string) => void |
|
|
|
isActive: (name: string) => void |
|
|
|
isActive: (name: string) => any |
|
|
|
openLocalPlugin: () => Promise<void> |
|
|
|
openLocalPlugin: () => Promise<void> |
|
|
|
filterPlugins: () => void |
|
|
|
filterPlugins: () => void |
|
|
|
profile: Profile |
|
|
|
profile: Profile |
|
|
|
|
|
|
|
tileLabel: TileLabel |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const PluginManagerContext = createContext({}) |
|
|
|
export interface RemixUiPluginManagerProps { |
|
|
|
|
|
|
|
appManager: RemixAppManager |
|
|
|
function PluginManagerContextProvider ({ children }) { |
|
|
|
engine: RemixEngine |
|
|
|
const [globalState] = useState<RemixUiPluginManagerProps>({} as RemixUiPluginManagerProps) |
|
|
|
_paq: _Paq |
|
|
|
return ( |
|
|
|
filter: string |
|
|
|
<PluginManagerContext.Provider value={globalState}> |
|
|
|
actives: Profile[] |
|
|
|
{children} |
|
|
|
inactives: Profile[] |
|
|
|
</PluginManagerContext.Provider> |
|
|
|
activatePlugin: (name: string) => void |
|
|
|
) |
|
|
|
deActivatePlugin: (name: string) => void |
|
|
|
|
|
|
|
isActive: (name: string) => any |
|
|
|
|
|
|
|
openLocalPlugin: () => Promise<void> |
|
|
|
|
|
|
|
filterPlugins: () => void |
|
|
|
|
|
|
|
profile: Profile |
|
|
|
|
|
|
|
tileLabel: TileLabel |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// // Filtering helpers
|
|
|
|
export const PluginManagerContext = createContext<Partial<PluginManagerContextProviderProps>>({}) |
|
|
|
// const isFiltered = (profile) => (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(this.filter)
|
|
|
|
|
|
|
|
// const isNotRequired = (profile) => !this.appManager.isRequired(profile.name)
|
|
|
|
|
|
|
|
// const isNotDependent = (profile) => !this.appManager.isDependent(profile.name)
|
|
|
|
|
|
|
|
// const isNotHome = (profile) => profile.name !== 'home'
|
|
|
|
|
|
|
|
// const sortByName = (profileA, profileB) => {
|
|
|
|
|
|
|
|
// const nameA = ((profileA.displayName) ? profileA.displayName : profileA.name).toUpperCase()
|
|
|
|
|
|
|
|
// const nameB = ((profileB.displayName) ? profileB.displayName : profileB.name).toUpperCase()
|
|
|
|
|
|
|
|
// return (nameA < nameB) ? -1 : (nameA > nameB) ? 1 : 0
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Filter all active and inactive modules that are not required
|
|
|
|
|
|
|
|
// const { actives, inactives } = this.appManager.getAll()
|
|
|
|
|
|
|
|
// .filter(isFiltered)
|
|
|
|
|
|
|
|
// .filter(isNotRequired)
|
|
|
|
|
|
|
|
// .filter(isNotDependent)
|
|
|
|
|
|
|
|
// .filter(isNotHome)
|
|
|
|
|
|
|
|
// .sort(sortByName)
|
|
|
|
|
|
|
|
// .reduce(({ actives, inactives }, profile) => {
|
|
|
|
|
|
|
|
// return this.isActive(profile.name)
|
|
|
|
|
|
|
|
// ? { actives: [...actives, profile], inactives }
|
|
|
|
|
|
|
|
// : { inactives: [...inactives, profile], actives }
|
|
|
|
|
|
|
|
// }, { actives: [], inactives: [] })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const RemixUiPluginManager = (props: RemixUiPluginManagerProps) => { |
|
|
|
function PluginManagerContextProvider ({ children, props }) { |
|
|
|
const [isFiltered] = useState((profile) => |
|
|
|
const [isFiltered] = useState((profile) => |
|
|
|
(profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(props.filter)) |
|
|
|
(profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(props.filter)) |
|
|
|
const [isNotRequired, setIsNotRequired] = useState<boolean>(false) |
|
|
|
const [isNotRequired, setIsNotRequired] = useState<any>() |
|
|
|
const [isNotDependent, setIsNotDependent] = useState((profile) => !props.appManager.isDependent(profile.name)) |
|
|
|
const [isNotDependent, setIsNotDependent] = useState<any>() |
|
|
|
const [isNotHome, setIsNotHome] = useState((profile) => profile.name !== 'home') |
|
|
|
const [isNotHome, setIsNotHome] = useState<any>() |
|
|
|
const [sortByName, setSortByName] = useState<1 | -1 | 0>((profileA, profileB) => { |
|
|
|
const [sortByName, setSortByName] = useState<any>() |
|
|
|
const nameA = ((profileA.displayName) ? profileA.displayName : profileA.name).toUpperCase() |
|
|
|
|
|
|
|
const nameB = ((profileB.displayName) ? profileB.displayName : profileB.name).toUpperCase() |
|
|
|
|
|
|
|
return (nameA < nameB) ? -1 : (nameA > nameB) ? 1 : 0 |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
const { actives, inactives } = props.appManager.getAll() |
|
|
|
const { actives, inactives } = props.appManager.getAll() |
|
|
|
.filter(isFiltered) |
|
|
|
.filter(isFiltered) |
|
|
|
.filter(isNotRequired) |
|
|
|
.filter(isNotRequired) |
|
|
@ -71,21 +53,38 @@ export const RemixUiPluginManager = (props: RemixUiPluginManagerProps) => { |
|
|
|
.filter(isNotHome) |
|
|
|
.filter(isNotHome) |
|
|
|
.sort(sortByName) |
|
|
|
.sort(sortByName) |
|
|
|
.reduce(({ actives, inactives }, profile) => { |
|
|
|
.reduce(({ actives, inactives }, profile) => { |
|
|
|
return this.isActive(profile.name) |
|
|
|
return props.isActive(profile.name) |
|
|
|
? { actives: [...actives, profile], inactives } |
|
|
|
? { actives: [...actives, profile], inactives } |
|
|
|
: { inactives: [...inactives, profile], actives } |
|
|
|
: { inactives: [...inactives, profile], actives } |
|
|
|
}, { actives: [], inactives: [] }) |
|
|
|
}, { actives: [], inactives: [] }) |
|
|
|
|
|
|
|
props.actives = actives |
|
|
|
|
|
|
|
props.inactives = inactives |
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const notRequired = (profile: Profile) => !props.appManager.isRequired(profile.name) |
|
|
|
const notRequired = (profile: Profile) => !props.appManager.isRequired(profile.name) |
|
|
|
|
|
|
|
const notDependent = (profile) => !props.appManager.isDependent(profile.name) |
|
|
|
|
|
|
|
const notHome = (profile) => profile.name !== 'home' |
|
|
|
|
|
|
|
const sortedByName = (profileA: Profile, profileB: Profile) => { |
|
|
|
|
|
|
|
const nameA = ((profileA.displayName) ? profileA.displayName : profileA.name).toUpperCase() |
|
|
|
|
|
|
|
const nameB = ((profileB.displayName) ? profileB.displayName : profileB.name).toUpperCase() |
|
|
|
|
|
|
|
return (nameA < nameB) ? -1 : (nameA > nameB) ? 1 : 0 |
|
|
|
|
|
|
|
} |
|
|
|
setIsNotRequired(notRequired(props.profile)) |
|
|
|
setIsNotRequired(notRequired(props.profile)) |
|
|
|
}) |
|
|
|
setIsNotDependent(notDependent(notDependent)) |
|
|
|
|
|
|
|
setIsNotHome(notHome) |
|
|
|
|
|
|
|
setSortByName(sortedByName) |
|
|
|
|
|
|
|
}, [props.appManager, props.profile]) |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<PluginManagerContext.Provider value={...props}> |
|
|
|
|
|
|
|
{children} |
|
|
|
|
|
|
|
</PluginManagerContext.Provider> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const RemixUiPluginManager = (props: RemixUiPluginManagerProps) => { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<PluginManagerContextProvider> |
|
|
|
<PluginManagerContextProvider props> |
|
|
|
<RootView |
|
|
|
<RootView |
|
|
|
openLocalPlugins={props.openLocalPlugin} |
|
|
|
localPluginButtonText="Connect to a Local Plugin" |
|
|
|
filterPlugins={props.filterPlugins} |
|
|
|
|
|
|
|
activeProfiles |
|
|
|
|
|
|
|
/> |
|
|
|
/> |
|
|
|
</PluginManagerContextProvider> |
|
|
|
</PluginManagerContextProvider> |
|
|
|
) |
|
|
|
) |
|
|
|