mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Disable the file tree "create file" name input while a request is in flight (#18001)
GitOrigin-RevId: ef505220e8cff1dce4c84483edacd96cc87bb1aa
This commit is contained in:
parent
2e634e665d
commit
a697f9e7b0
6 changed files with 38 additions and 7 deletions
|
@ -21,6 +21,7 @@ export default function FileTreeCreateNameInput({
|
||||||
classes = {},
|
classes = {},
|
||||||
placeholder,
|
placeholder,
|
||||||
error,
|
error,
|
||||||
|
inFlight,
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ export default function FileTreeCreateNameInput({
|
||||||
value={name}
|
value={name}
|
||||||
onChange={event => setName(event.target.value)}
|
onChange={event => setName(event.target.value)}
|
||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
|
disabled={inFlight}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormControl.Feedback />
|
<FormControl.Feedback />
|
||||||
|
@ -74,6 +76,7 @@ FileTreeCreateNameInput.propTypes = {
|
||||||
}),
|
}),
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
error: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
error: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
||||||
|
inFlight: PropTypes.bool.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
function ErrorMessage({ error }) {
|
function ErrorMessage({ error }) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import ErrorMessage from '../error-message'
|
||||||
export default function FileTreeCreateNewDoc() {
|
export default function FileTreeCreateNewDoc() {
|
||||||
const { name, validName } = useFileTreeCreateName()
|
const { name, validName } = useFileTreeCreateName()
|
||||||
const { setValid } = useFileTreeCreateForm()
|
const { setValid } = useFileTreeCreateForm()
|
||||||
const { error, finishCreatingDoc } = useFileTreeActionable()
|
const { error, finishCreatingDoc, inFlight } = useFileTreeActionable()
|
||||||
|
|
||||||
// form validation: name is valid
|
// form validation: name is valid
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -32,7 +32,7 @@ export default function FileTreeCreateNewDoc() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form noValidate id="create-file" onSubmit={handleSubmit}>
|
<form noValidate id="create-file" onSubmit={handleSubmit}>
|
||||||
<FileTreeCreateNameInput focusName error={error} />
|
<FileTreeCreateNameInput focusName error={error} inFlight={inFlight} />
|
||||||
|
|
||||||
{error && <ErrorMessage error={error} />}
|
{error && <ErrorMessage error={error} />}
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -31,7 +31,7 @@ export default function FileTreeImportFromProject() {
|
||||||
|
|
||||||
const { name, setName, validName } = useFileTreeCreateName()
|
const { name, setName, validName } = useFileTreeCreateName()
|
||||||
const { setValid } = useFileTreeCreateForm()
|
const { setValid } = useFileTreeCreateForm()
|
||||||
const { error, finishCreatingLinkedFile } = useFileTreeActionable()
|
const { error, finishCreatingLinkedFile, inFlight } = useFileTreeActionable()
|
||||||
|
|
||||||
const [selectedProject, setSelectedProject] = useState<Project>()
|
const [selectedProject, setSelectedProject] = useState<Project>()
|
||||||
const [selectedProjectEntity, setSelectedProjectEntity] = useState<Entity>()
|
const [selectedProjectEntity, setSelectedProjectEntity] = useState<Entity>()
|
||||||
|
@ -168,6 +168,7 @@ export default function FileTreeImportFromProject() {
|
||||||
}}
|
}}
|
||||||
placeholder="example.tex"
|
placeholder="example.tex"
|
||||||
error={error}
|
error={error}
|
||||||
|
inFlight={inFlight}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{error && <ErrorMessage error={error} />}
|
{error && <ErrorMessage error={error} />}
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default function FileTreeImportFromUrl() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { name, setName, validName } = useFileTreeCreateName()
|
const { name, setName, validName } = useFileTreeCreateName()
|
||||||
const { setValid } = useFileTreeCreateForm()
|
const { setValid } = useFileTreeCreateForm()
|
||||||
const { finishCreatingLinkedFile, error } = useFileTreeActionable()
|
const { finishCreatingLinkedFile, error, inFlight } = useFileTreeActionable()
|
||||||
|
|
||||||
const [url, setUrl] = useState('')
|
const [url, setUrl] = useState('')
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ export default function FileTreeImportFromUrl() {
|
||||||
label={t('file_name_in_this_project')}
|
label={t('file_name_in_this_project')}
|
||||||
placeholder="my_file"
|
placeholder="my_file"
|
||||||
error={error}
|
error={error}
|
||||||
|
inFlight={inFlight}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{error && <ErrorMessage error={error} />}
|
{error && <ErrorMessage error={error} />}
|
||||||
|
|
|
@ -61,4 +61,7 @@ export default {
|
||||||
title: 'Editor / Modals / Create File / File Name Input',
|
title: 'Editor / Modals / Create File / File Name Input',
|
||||||
component: FileTreeCreateNameInput,
|
component: FileTreeCreateNameInput,
|
||||||
decorators: [ModalBodyDecorator, ModalContentDecorator],
|
decorators: [ModalBodyDecorator, ModalContentDecorator],
|
||||||
|
args: {
|
||||||
|
inFlight: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ describe('<FileTreeCreateNameInput/>', function () {
|
||||||
it('renders an empty input', function () {
|
it('renders an empty input', function () {
|
||||||
cy.mount(
|
cy.mount(
|
||||||
<FileTreeCreateNameProvider>
|
<FileTreeCreateNameProvider>
|
||||||
<FileTreeCreateNameInput />
|
<FileTreeCreateNameInput inFlight={false} />
|
||||||
</FileTreeCreateNameProvider>
|
</FileTreeCreateNameProvider>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ describe('<FileTreeCreateNameInput/>', function () {
|
||||||
<FileTreeCreateNameInput
|
<FileTreeCreateNameInput
|
||||||
label="File name in this project"
|
label="File name in this project"
|
||||||
placeholder="Enter a file name…"
|
placeholder="Enter a file name…"
|
||||||
|
inFlight={false}
|
||||||
/>
|
/>
|
||||||
</FileTreeCreateNameProvider>
|
</FileTreeCreateNameProvider>
|
||||||
)
|
)
|
||||||
|
@ -30,7 +31,7 @@ describe('<FileTreeCreateNameInput/>', function () {
|
||||||
it('uses an initial name', function () {
|
it('uses an initial name', function () {
|
||||||
cy.mount(
|
cy.mount(
|
||||||
<FileTreeCreateNameProvider initialName="test.tex">
|
<FileTreeCreateNameProvider initialName="test.tex">
|
||||||
<FileTreeCreateNameInput />
|
<FileTreeCreateNameInput inFlight={false} />
|
||||||
</FileTreeCreateNameProvider>
|
</FileTreeCreateNameProvider>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ describe('<FileTreeCreateNameInput/>', function () {
|
||||||
|
|
||||||
cy.mount(
|
cy.mount(
|
||||||
<FileTreeCreateNameProvider initialName="test.tex">
|
<FileTreeCreateNameProvider initialName="test.tex">
|
||||||
<FileTreeCreateNameInput focusName />
|
<FileTreeCreateNameInput focusName inFlight={false} />
|
||||||
</FileTreeCreateNameProvider>
|
</FileTreeCreateNameProvider>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,4 +67,26 @@ describe('<FileTreeCreateNameInput/>', function () {
|
||||||
expect(element.get(0).selectionEnd).to.equal(4)
|
expect(element.get(0).selectionEnd).to.equal(4)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('disables the input when in flight', function () {
|
||||||
|
cy.mount(
|
||||||
|
<FileTreeCreateNameProvider initialName="test.tex">
|
||||||
|
<FileTreeCreateNameInput inFlight={false} />
|
||||||
|
</FileTreeCreateNameProvider>
|
||||||
|
).then(({ rerender }) => {
|
||||||
|
cy.findByLabelText('File Name').should('not.be.disabled')
|
||||||
|
rerender(
|
||||||
|
<FileTreeCreateNameProvider initialName="test.tex">
|
||||||
|
<FileTreeCreateNameInput inFlight />
|
||||||
|
</FileTreeCreateNameProvider>
|
||||||
|
)
|
||||||
|
cy.findByLabelText('File Name').should('be.disabled')
|
||||||
|
rerender(
|
||||||
|
<FileTreeCreateNameProvider initialName="test.tex">
|
||||||
|
<FileTreeCreateNameInput inFlight={false} />
|
||||||
|
</FileTreeCreateNameProvider>
|
||||||
|
)
|
||||||
|
cy.findByLabelText('File Name').should('not.be.disabled')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue