-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟🔧 Remove top level state for unfinished flows in connector form (#20135
- Loading branch information
Joe Reuter
committed
Dec 13, 2022
1 parent
9dae098
commit 75dcf82
Showing
7 changed files
with
125 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 0 additions & 71 deletions
71
airbyte-webapp/src/views/Connector/ConnectorForm/components/Property/ConfirmationControl.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...c/views/Connector/ConnectorForm/components/Property/SecretConfirmationControl.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@use "scss/variables"; | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: top; | ||
gap: variables.$spacing-sm; | ||
} |
108 changes: 108 additions & 0 deletions
108
...ebapp/src/views/Connector/ConnectorForm/components/Property/SecretConfirmationControl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { useField, useFormikContext } from "formik"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import { Button } from "components/ui/Button"; | ||
import { Input } from "components/ui/Input"; | ||
import { SecretTextArea } from "components/ui/SecretTextArea"; | ||
|
||
import styles from "./SecretConfirmationControl.module.scss"; | ||
|
||
interface SecretConfirmationControlProps { | ||
showButtons?: boolean; | ||
name: string; | ||
multiline: boolean; | ||
disabled?: boolean; | ||
error?: boolean; | ||
} | ||
|
||
const SecretConfirmationControl: React.FC<SecretConfirmationControlProps> = ({ | ||
showButtons, | ||
disabled, | ||
multiline, | ||
name, | ||
error, | ||
}) => { | ||
const [field, , helpers] = useField(name); | ||
const [previousValue, setPreviousValue] = useState<unknown>(undefined); | ||
const isEditInProgress = Boolean(previousValue); | ||
const controlRef = useRef<HTMLInputElement>(null); | ||
|
||
const { dirty, touched } = useFormikContext(); | ||
|
||
const component = | ||
multiline && (isEditInProgress || !showButtons) ? ( | ||
<SecretTextArea | ||
{...field} | ||
autoComplete="off" | ||
value={field.value ?? ""} | ||
rows={3} | ||
error={error} | ||
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
autoFocus={showButtons && isEditInProgress} | ||
disabled={(showButtons && !isEditInProgress) || disabled} | ||
/> | ||
) : ( | ||
<Input | ||
{...field} | ||
autoComplete="off" | ||
value={field.value ?? ""} | ||
type="password" | ||
error={error} | ||
ref={controlRef} | ||
disabled={(showButtons && !isEditInProgress) || disabled} | ||
/> | ||
); | ||
|
||
useEffect(() => { | ||
if (!dirty && !touched && previousValue) { | ||
setPreviousValue(undefined); | ||
} | ||
}, [dirty, helpers, previousValue, touched]); | ||
|
||
if (!showButtons) { | ||
return <>{component}</>; | ||
} | ||
|
||
const handleStartEdit = () => { | ||
if (controlRef && controlRef.current) { | ||
controlRef.current?.removeAttribute?.("disabled"); | ||
controlRef.current?.focus?.(); | ||
} | ||
setPreviousValue(field.value); | ||
helpers.setValue(""); | ||
}; | ||
|
||
const onDone = () => { | ||
setPreviousValue(undefined); | ||
}; | ||
|
||
const onCancel = () => { | ||
if (previousValue) { | ||
helpers.setValue(previousValue); | ||
} | ||
setPreviousValue(undefined); | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
{component} | ||
{isEditInProgress ? ( | ||
<> | ||
<Button size="xs" onClick={onDone} type="button" disabled={disabled}> | ||
<FormattedMessage id="form.done" /> | ||
</Button> | ||
<Button size="xs" onClick={onCancel} type="button" variant="secondary" disabled={disabled}> | ||
<FormattedMessage id="form.cancel" /> | ||
</Button> | ||
</> | ||
) : ( | ||
<Button size="xs" onClick={handleStartEdit} type="button" disabled={disabled}> | ||
<FormattedMessage id="form.edit" /> | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SecretConfirmationControl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters