From 8e784f2579db7157ea9d1c51fb97c27d6c41bee3 Mon Sep 17 00:00:00 2001 From: Dawid Cieslak Date: Wed, 22 Jun 2022 11:35:10 -0700 Subject: [PATCH] convert plugin 'sandbox's UI to use ant.design MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Bootcamp task: I’m removing the remaining UI components imported from ‘flipper’ and replacing with new ones from ‘antd’. I’m also attempting to polish 🇵🇱 the UI and UX of the plugin: UI: - Selecting one of the listed sandboxes and custom URL lead to the same action -> align all components together UX: - Sometimes loading sandboxes takes time, and it’s not clear for the user what’s happening -> add a loading indicator - At first the input field was a bit confusing to me -> add more labels to explain the purpose of visible components - It’s not always clear what happened after requesting a sandbox change -> the result of all actions is now confirmed with the small 'popup' notification. I don't have any experience with web frontend, so if something is terribly wrong below - don't be afraid to point it out :) Before/After: {F745958473} Reviewed By: mweststrate Differential Revision: D37343946 fbshipit-source-id: 3dbdd213ffd5540dc7a418c1590eb956ef4c6715 --- desktop/plugins/public/sandbox/index.tsx | 143 +++++++++++------------ 1 file changed, 70 insertions(+), 73 deletions(-) diff --git a/desktop/plugins/public/sandbox/index.tsx b/desktop/plugins/public/sandbox/index.tsx index 9bdb1ac4e..137bc70e0 100644 --- a/desktop/plugins/public/sandbox/index.tsx +++ b/desktop/plugins/public/sandbox/index.tsx @@ -7,9 +7,15 @@ * @format */ -import {FlexColumn, ButtonGroup, Button, styled, colors} from 'flipper'; import React, {ChangeEvent} from 'react'; -import {PluginClient, createState, usePlugin, useValue} from 'flipper-plugin'; +import {Button, Input, Typography, Spin, message} from 'antd'; +import { + PluginClient, + createState, + usePlugin, + useValue, + Layout, +} from 'flipper-plugin'; export type Sandbox = { name: string; @@ -23,55 +29,24 @@ type ClientMethods = { type SetSandboxResult = {result: boolean}; -const BigButton = styled(Button)({ - flexGrow: 1, - fontSize: 24, - padding: 20, -}); - -const ButtonContainer = styled(FlexColumn)({ - alignItems: 'center', - padding: 20, -}); - -const TextInput = styled.input({ - border: `1px solid ${colors.light10}`, - fontSize: '1em', - padding: '0 5px', - borderRight: 0, - borderTopLeftRadius: 4, - borderBottomLeftRadius: 4, - flexGrow: 1, -}); - -const FeedbackMessage = styled.span({ - fontSize: '1.2em', - paddingTop: '10px', - color: 'green', -}); - -const TextInputLayout = styled(FlexColumn)({ - float: 'left', - justifyContent: 'center', - flexGrow: 1, - borderRadius: 4, - marginRight: 15, - marginTop: 15, - marginLeft: 15, -}); - export function plugin(client: PluginClient<{}, ClientMethods>) { const sandboxes = createState>([]); const customSandbox = createState(''); - const showFeedback = createState(false); + const isLoadingSandboxes = createState(false); client.onConnect(() => { + isLoadingSandboxes.set(true); client .send('getSandbox', undefined) .then((results: Array) => { sandboxes.set(results); + isLoadingSandboxes.set(false); }) - .catch((e) => console.error('[sandbox] getSandbox call failed:', e)); + .catch((e) => { + console.error('[sandbox] getSandbox call failed:', e); + isLoadingSandboxes.set(false); + displayError(e); + }); }); const onSendSandboxEnvironment = (sandbox: string) => { @@ -80,25 +55,35 @@ export function plugin(client: PluginClient<{}, ClientMethods>) { sandbox, }) .then((result: SetSandboxResult) => { - setTimeout(() => { - showFeedback.set(false); - }, 3000); - showFeedback.set(result.result); + if (result.result) + displaySuccess('Update to ' + sandbox + ' successful'); + else displayError('Update to ' + sandbox + ' failed'); }) - .catch((e) => console.error('[sandbox] setSandbox call failed:', e)); + .catch((e) => { + console.error('[sandbox] setSandbox call failed:', e); + displayError(e); + }); }; const onChangeSandbox = (e: ChangeEvent) => { customSandbox.set(e.target.value); }; + const displaySuccess = (title: string) => { + message.success(title); + }; + + const displayError = (title: string) => { + message.error(title); + }; + return { client, onChangeSandbox, onSendSandboxEnvironment, customSandbox, sandboxes, - showFeedback, + isLoadingSandboxes, }; } @@ -106,16 +91,39 @@ export function Component() { const instance = usePlugin(plugin); const customSandbox = useValue(instance.customSandbox); const sandboxes = useValue(instance.sandboxes); - const showFeedback = useValue(instance.showFeedback); + const isLoadingSandboxes = useValue(instance.isLoadingSandboxes); return ( - - - - + + + Select the environment: + + + {sandboxes.map((sandbox) => ( + + ))} + + Provide custom Sandbox URL + + + { if (event.key === 'Enter') { @@ -124,24 +132,13 @@ export function Component() { }} /> + + + ); }