Files
supabase/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ActionBar.tsx
Ivan Vasilov 66ae36e005 feat: Playwright tests (#21083)
* initial commit for testing the github action.

* Improvements to the Github action.

* Add docker caching.

* Fix an issue in the github action.

* Another fix for the action.

* Just delete the db after the tests.

* Add a supabase app to the playwright-tests.

* Delete .env.testing.

* Remove the docker image caching from the Playwright github action.

* Add a README.md.

* Add an example test for the table editor.

* Ignore the generated keys.json.

* Add commands for running and writing tests.

* Remove Auth tests.

* Only show the react-query tool when not in test mode.

* Add data-testids to the buttons and use them in the test.

* Handle a case where SUPABASE_URL isn't defined.

* Fix the button test id.

* Remove some dependency.

* Try setting a timeout for an action.

* Add timeout to another action.

* Add some timeouts before the save button.

* Add some timeout before clicking save.

* Enable the video recording only during local testing.

* Minor fixes.

* Expand the README.
2024-02-19 12:12:54 +01:00

73 lines
1.9 KiB
TypeScript

import { noop } from 'lodash'
import { PropsWithChildren, useState } from 'react'
import { Button } from 'ui'
interface ActionBarProps {
loading?: boolean
disableApply?: boolean
hideApply?: boolean
applyButtonLabel?: string
backButtonLabel?: string
applyFunction?: (resolve: any) => void
closePanel: () => void
formId?: string
}
const ActionBar = ({
loading = false,
disableApply = false,
hideApply = false,
children = undefined,
applyButtonLabel = 'Apply',
backButtonLabel = 'Back',
applyFunction = undefined,
closePanel = noop,
formId,
}: PropsWithChildren<ActionBarProps>) => {
const [isRunning, setIsRunning] = useState(false)
// @ts-ignore
const applyCallback = () => new Promise((resolve) => applyFunction(resolve))
const onSelectApply = async () => {
setIsRunning(true)
await applyCallback()
setIsRunning(false)
}
return (
<div className="flex w-full justify-end space-x-3 border-t border-default px-3 py-4">
<Button type="default" htmlType="button" onClick={closePanel} disabled={isRunning || loading}>
{backButtonLabel}
</Button>
{children}
{applyFunction !== undefined ? (
// Old solution, necessary when loading is handled by this component itself
<Button
onClick={onSelectApply}
disabled={disableApply || isRunning || loading}
loading={isRunning || loading}
>
{applyButtonLabel}
</Button>
) : !hideApply ? (
// New solution, when using the Form component, loading is handled by the Form itself
// Does not require applyFunction() callback
<Button
disabled={loading || disableApply}
loading={loading}
data-testid="action-bar-save-row"
htmlType="submit"
form={formId}
>
{applyButtonLabel}
</Button>
) : (
<div />
)}
</div>
)
}
export default ActionBar