/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ import { DownloadOutlined, LoadingOutlined, PlusOutlined, } from '@ant-design/icons'; import {Alert, Button} from 'antd'; import {DownloadablePluginDetails} from 'flipper-common'; import React, {useMemo} from 'react'; import {useCallback} from 'react'; import {useDispatch, useSelector} from 'react-redux'; import {PluginDefinition} from '../plugin'; import {startPluginDownload} from '../reducers/pluginDownloads'; import {switchPlugin} from '../reducers/pluginManager'; import { getActiveClient, getPluginDownloadStatusMap, } from '../selectors/connections'; import {Layout} from '../ui'; import {ActivePluginListItem} from '../utils/pluginUtils'; export function PluginActions({ activePlugin, type, }: { activePlugin: ActivePluginListItem; type: 'link' | 'primary'; }) { switch (activePlugin.status) { case 'disabled': { return ; } case 'uninstalled': { return ; } case 'unavailable': { return type === 'primary' ? ( ) : null; } default: return null; } } function EnableButton({ plugin, type, }: { plugin: PluginDefinition; type: 'link' | 'primary'; }) { const dispatch = useDispatch(); const client = useSelector(getActiveClient); const enableOrDisablePlugin = useCallback(() => { dispatch(switchPlugin({plugin, selectedApp: client?.query?.app})); }, [dispatch, plugin, client]); return ( ); } function UnavailabilityAlert({reason}: {reason: string}) { return ( ); } function InstallButton({ plugin, type = 'primary', }: { plugin: DownloadablePluginDetails; type: 'link' | 'primary'; }) { const dispatch = useDispatch(); const installPlugin = useCallback(() => { dispatch(startPluginDownload({plugin, startedByUser: true})); }, [plugin, dispatch]); const downloads = useSelector(getPluginDownloadStatusMap); const downloadStatus = useMemo( () => downloads.get(plugin.id), [downloads, plugin], ); return ( ); }