2024-06-04 10:57:52 +02:00
|
|
|
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';
|
2024-06-15 11:00:21 +02:00
|
|
|
import { View, ViewStyle } from 'react-native';
|
2024-06-04 10:57:52 +02:00
|
|
|
import { _ } from '@joplin/lib/locale';
|
|
|
|
import { PluginCallback } from '../utils/usePluginCallbacks';
|
2024-06-15 11:00:21 +02:00
|
|
|
import PluginChip from './PluginChip';
|
2024-06-04 10:57:52 +02:00
|
|
|
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> = props => {
|
|
|
|
const item = props.item;
|
|
|
|
|
|
|
|
const theme = themeStyle(props.themeId);
|
|
|
|
|
|
|
|
const renderErrorsChip = () => {
|
|
|
|
if (!props.hasErrors) return null;
|
|
|
|
|
|
|
|
return (
|
2024-06-15 11:00:21 +02:00
|
|
|
<PluginChip
|
|
|
|
color={theme.colorError2}
|
2024-06-04 10:57:52 +02:00
|
|
|
icon='alert'
|
|
|
|
onPress={() => props.onShowPluginLog({ item })}
|
|
|
|
>
|
|
|
|
{_('Error')}
|
2024-06-15 11:00:21 +02:00
|
|
|
</PluginChip>
|
2024-06-04 10:57:52 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderBuiltInChip = () => {
|
|
|
|
if (!props.item.builtIn) {
|
|
|
|
return null;
|
|
|
|
}
|
2024-06-15 11:00:21 +02:00
|
|
|
return <PluginChip icon='code-tags-check'>{_('Built-in')}</PluginChip>;
|
2024-06-04 10:57:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const renderIncompatibleChip = () => {
|
|
|
|
if (props.isCompatible) return null;
|
|
|
|
return (
|
2024-06-15 11:00:21 +02:00
|
|
|
<PluginChip
|
|
|
|
color={theme.color3}
|
2024-06-04 10:57:52 +02:00
|
|
|
icon='alert'
|
|
|
|
onPress={() => {
|
|
|
|
void shim.showMessageBox(
|
|
|
|
PluginService.instance().describeIncompatibility(props.item.manifest),
|
|
|
|
{ buttons: [_('OK')] },
|
|
|
|
);
|
|
|
|
}}
|
2024-06-15 11:00:21 +02:00
|
|
|
>{_('Incompatible')}</PluginChip>
|
2024-06-04 10:57:52 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderUpdatableChip = () => {
|
|
|
|
if (!props.isCompatible || !props.canUpdate) return null;
|
|
|
|
|
|
|
|
return (
|
2024-06-15 11:00:21 +02:00
|
|
|
<PluginChip>{_('Update available')}</PluginChip>
|
2024-06-04 10:57:52 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderDisabledChip = () => {
|
|
|
|
if (props.item.enabled || !props.item.installed) {
|
|
|
|
return null;
|
|
|
|
}
|
2024-06-15 11:00:21 +02:00
|
|
|
return <PluginChip faded={true}>{_('Disabled')}</PluginChip>;
|
2024-06-04 10:57:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const renderInstalledChip = () => {
|
|
|
|
if (!props.showInstalledChip) {
|
|
|
|
return null;
|
|
|
|
}
|
2024-06-15 11:00:21 +02:00
|
|
|
return <PluginChip faded={true}>{_('Installed')}</PluginChip>;
|
2024-06-04 10:57:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return <View style={containerStyle}>
|
|
|
|
{renderIncompatibleChip()}
|
|
|
|
{renderInstalledChip()}
|
|
|
|
{renderErrorsChip()}
|
|
|
|
{renderBuiltInChip()}
|
|
|
|
{renderUpdatableChip()}
|
|
|
|
{renderDisabledChip()}
|
|
|
|
</View>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PluginChips;
|