-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): ✨ Add file upload input
- Loading branch information
1 parent
d4c52d4
commit 75365a0
Showing
48 changed files
with
1,021 additions
and
586 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
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
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
12 changes: 12 additions & 0 deletions
12
...er/components/shared/Graph/Nodes/BlockNode/BlockNodeContent/contents/FileInputContent.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,12 @@ | ||
import { Text } from '@chakra-ui/react' | ||
import { FileInputOptions } from 'models' | ||
|
||
type Props = { | ||
options: FileInputOptions | ||
} | ||
|
||
export const FileInputContent = ({ options: { isMultipleAllowed } }: Props) => ( | ||
<Text noOfLines={0} pr="6"> | ||
Collect {isMultipleAllowed ? 'files' : 'file'} | ||
</Text> | ||
) |
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
64 changes: 64 additions & 0 deletions
64
...mponents/shared/Graph/Nodes/BlockNode/SettingsPopoverContent/bodies/FileInputSettings.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,64 @@ | ||
import { FormLabel, Stack } from '@chakra-ui/react' | ||
import { CodeEditor } from 'components/shared/CodeEditor' | ||
import { SwitchWithLabel } from 'components/shared/SwitchWithLabel' | ||
import { Input } from 'components/shared/Textbox' | ||
import { VariableSearchInput } from 'components/shared/VariableSearchInput' | ||
import { FileInputOptions, Variable } from 'models' | ||
import React from 'react' | ||
|
||
type Props = { | ||
options: FileInputOptions | ||
onOptionsChange: (options: FileInputOptions) => void | ||
} | ||
|
||
export const FileInputSettings = ({ options, onOptionsChange }: Props) => { | ||
const handleButtonLabelChange = (button: string) => | ||
onOptionsChange({ ...options, labels: { ...options.labels, button } }) | ||
const handlePlaceholderLabelChange = (placeholder: string) => | ||
onOptionsChange({ ...options, labels: { ...options.labels, placeholder } }) | ||
const handleLongChange = (isMultipleAllowed: boolean) => | ||
onOptionsChange({ ...options, isMultipleAllowed }) | ||
const handleVariableChange = (variable?: Variable) => | ||
onOptionsChange({ ...options, variableId: variable?.id }) | ||
|
||
return ( | ||
<Stack spacing={4}> | ||
<SwitchWithLabel | ||
id="switch" | ||
label="Allow multiple files?" | ||
initialValue={options.isMultipleAllowed} | ||
onCheckChange={handleLongChange} | ||
/> | ||
<Stack> | ||
<FormLabel mb="0">Placeholder:</FormLabel> | ||
<CodeEditor | ||
lang="html" | ||
onChange={handlePlaceholderLabelChange} | ||
value={options.labels.placeholder} | ||
height={'100px'} | ||
withVariableButton={false} | ||
/> | ||
</Stack> | ||
<Stack> | ||
<FormLabel mb="0" htmlFor="button"> | ||
Button label: | ||
</FormLabel> | ||
<Input | ||
id="button" | ||
defaultValue={options.labels.button} | ||
onChange={handleButtonLabelChange} | ||
withVariableButton={false} | ||
/> | ||
</Stack> | ||
<Stack> | ||
<FormLabel mb="0" htmlFor="variable"> | ||
Save upload URL{options.isMultipleAllowed ? 's' : ''} in a variable: | ||
</FormLabel> | ||
<VariableSearchInput | ||
initialVariableId={options.variableId} | ||
onSelectVariable={handleVariableChange} | ||
/> | ||
</Stack> | ||
</Stack> | ||
) | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import test, { expect } from '@playwright/test' | ||
import { | ||
createTypebots, | ||
parseDefaultGroupWithBlock, | ||
} from '../../services/database' | ||
import { defaultFileInputOptions, InputBlockType } from 'models' | ||
import { typebotViewer } from '../../services/selectorUtils' | ||
import cuid from 'cuid' | ||
import path from 'path' | ||
|
||
test('options should work', async ({ page }) => { | ||
const typebotId = cuid() | ||
await createTypebots([ | ||
{ | ||
id: typebotId, | ||
...parseDefaultGroupWithBlock({ | ||
type: InputBlockType.FILE, | ||
options: defaultFileInputOptions, | ||
}), | ||
}, | ||
]) | ||
|
||
await page.goto(`/typebots/${typebotId}/edit`) | ||
|
||
await page.click('text=Preview') | ||
await expect( | ||
typebotViewer(page).locator(`text=Click to upload`) | ||
).toBeVisible() | ||
await typebotViewer(page) | ||
.locator(`input[type="file"]`) | ||
.setInputFiles([path.join(__dirname, '../../fixtures/avatar.jpg')]) | ||
await expect(typebotViewer(page).locator(`text=File uploaded`)).toBeVisible() | ||
await page.click('text="Collect file"') | ||
await page.click('text="Allow multiple files?"') | ||
await page.fill('div[contenteditable=true]', '<strong>Upload now!!</strong>') | ||
await page.fill('[value="Upload"]', 'Go') | ||
await page.click('text="Restart"') | ||
await expect(typebotViewer(page).locator(`text="Upload now!!"`)).toBeVisible() | ||
await typebotViewer(page) | ||
.locator(`input[type="file"]`) | ||
.setInputFiles([ | ||
path.join(__dirname, '../../fixtures/avatar.jpg'), | ||
path.join(__dirname, '../../fixtures/avatar.jpg'), | ||
path.join(__dirname, '../../fixtures/avatar.jpg'), | ||
]) | ||
await expect(typebotViewer(page).locator(`text="3"`)).toBeVisible() | ||
await typebotViewer(page).locator('text="Go 3 files"').click() | ||
await expect( | ||
typebotViewer(page).locator(`text="3 files uploaded"`) | ||
).toBeVisible() | ||
}) |
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
Oops, something went wrong.