From e85a6a2fb6d6e6c2a6c95626a763231aa79856b4 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 28 Mar 2024 04:47:10 -0700 Subject: [PATCH] make sure at least one Plugin is selected Summary: Selecting no plugins during Flipper file / link export would continue the export process but yield meaningless export files. Added validation something is selected See https://fb.workplace.com/groups/flippersupport/permalink/1805444636602853/ Reviewed By: LukeDefeo Differential Revision: D55467979 fbshipit-source-id: 331c70fc80817bc193bace44f16a0d29259a250b --- desktop/flipper-plugin/src/ui/Dialog.tsx | 3 +++ desktop/flipper-ui/src/chrome/ExportDataPluginSheet.tsx | 2 +- desktop/flipper-ui/src/utils/exportData.tsx | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/desktop/flipper-plugin/src/ui/Dialog.tsx b/desktop/flipper-plugin/src/ui/Dialog.tsx index 7882efc22b7..33bbce2194b 100644 --- a/desktop/flipper-plugin/src/ui/Dialog.tsx +++ b/desktop/flipper-plugin/src/ui/Dialog.tsx @@ -242,6 +242,7 @@ export const Dialog = { select({ defaultValue, renderer, + onValidate, ...rest }: { defaultValue: T; @@ -250,10 +251,12 @@ export const Dialog = { onChange: (newValue: T) => void, onCancel: () => void, ) => React.ReactElement; + onValidate?: (value: T) => string; } & BaseDialogOptions): DialogResult { const handle = Dialog.show({ ...rest, defaultValue, + onValidate, children: (currentValue, setValue): React.ReactElement => renderer(currentValue, setValue, () => handle.close()), }); diff --git a/desktop/flipper-ui/src/chrome/ExportDataPluginSheet.tsx b/desktop/flipper-ui/src/chrome/ExportDataPluginSheet.tsx index 8d2b109c5ce..09bbac53c81 100644 --- a/desktop/flipper-ui/src/chrome/ExportDataPluginSheet.tsx +++ b/desktop/flipper-ui/src/chrome/ExportDataPluginSheet.tsx @@ -37,7 +37,7 @@ class ExportDataPluginSheet extends Component { { this.props.setSelectedPlugins(selectedArray); diff --git a/desktop/flipper-ui/src/utils/exportData.tsx b/desktop/flipper-ui/src/utils/exportData.tsx index 381d7d97841..a6fd8eadde3 100644 --- a/desktop/flipper-ui/src/utils/exportData.tsx +++ b/desktop/flipper-ui/src/utils/exportData.tsx @@ -772,6 +772,8 @@ async function selectPlugins() { return await Dialog.select({ title: 'Select plugins to export', defaultValue: [], + onValidate: (plugins) => + plugins.length === 0 ? 'Please select at least one plugin.' : '', renderer: (value, onChange, onCancel) => (