import { PluginItem } from '@joplin/lib/components/shared/config/plugins/types'; import PluginService from '@joplin/lib/services/plugins/PluginService'; import shim from '@joplin/lib/shim'; import * as React from 'react'; import { View, ViewStyle } from 'react-native'; import { _ } from '@joplin/lib/locale'; import { PluginCallback } from '../utils/usePluginCallbacks'; import PluginChip from './PluginChip'; import { themeStyle } from '../../../../global-style'; interface Props { themeId: number; item: PluginItem; hasErrors: boolean; isCompatible: boolean; canUpdate: boolean; showInstalledChip: boolean; onShowPluginLog?: PluginCallback; } const containerStyle: ViewStyle = { flexDirection: 'row', gap: 4, // Smaller than default chip size transform: [{ scale: 0.84 }], transformOrigin: 'left', }; const PluginChips: React.FC = props => { const item = props.item; const theme = themeStyle(props.themeId); const renderErrorsChip = () => { if (!props.hasErrors) return null; return ( props.onShowPluginLog({ item })} > {_('Error')} ); }; const renderBuiltInChip = () => { if (!props.item.builtIn) { return null; } return {_('Built-in')}; }; const renderIncompatibleChip = () => { if (props.isCompatible) return null; return ( { void shim.showMessageBox( PluginService.instance().describeIncompatibility(props.item.manifest), { buttons: [_('OK')] }, ); }} >{_('Incompatible')} ); }; const renderUpdatableChip = () => { if (!props.isCompatible || !props.canUpdate) return null; return ( {_('Update available')} ); }; const renderDisabledChip = () => { if (props.item.enabled || !props.item.installed) { return null; } return {_('Disabled')}; }; const renderInstalledChip = () => { if (!props.showInstalledChip) { return null; } return {_('Installed')}; }; return {renderIncompatibleChip()} {renderInstalledChip()} {renderErrorsChip()} {renderBuiltInChip()} {renderUpdatableChip()} {renderDisabledChip()} ; }; export default PluginChips;