Skip to content

Commit

Permalink
Merge branch 'bugfix/ARTESCA-12101-incorrect-system-behavior-when-cre…
Browse files Browse the repository at this point in the history
…ating-a-folder' into q/3.0
  • Loading branch information
bert-e committed Jul 5, 2024
2 parents ce6e64c + 261daca commit 85338de
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/react/databrowser/objects/FolderCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const FolderCreate = ({ bucketName, prefixWithSlash }: Props) => {
setFolderName(e.target.value);
};

const isFolderNameValid = folderName && !folderName.startsWith('/');
const folderNameInvalidMsg = 'The folder name is not valid.';
return (
<Modal
close={cancel}
Expand All @@ -70,10 +72,11 @@ const FolderCreate = ({ bucketName, prefixWithSlash }: Props) => {
/>
<Button
id="folder-create-save-button"
disabled={loading || !folderName}
disabled={loading || !isFolderNameValid}
variant="secondary"
onClick={save}
label="Save"
tooltip={!isFolderNameValid && { overlay: folderNameInvalidMsg }}
/>
</Stack>
</Wrap>
Expand All @@ -91,14 +94,20 @@ const FolderCreate = ({ bucketName, prefixWithSlash }: Props) => {
setTimeout(() => input.focus());
}
}}
error={!isFolderNameValid && folderNameInvalidMsg}
onChange={handleChange}
/>
<Description>
<InfoMessage
title="Creating a folder"
content='When you create a folder, Data Browser creates an object with the
above name appended by suffix "/" and that object is
displayed as a folder in the Data Browser.'
content={
<>
Ensure the folder name does not begin with a slash. <br />
When you create a folder, Data Browser creates an object with the
above name appended by suffix "/" and that object is displayed as
a folder in the Data Browser.
</>
}
/>
</Description>
</Modal>
Expand Down
15 changes: 15 additions & 0 deletions src/react/databrowser/objects/__tests__/FolderCreate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,19 @@ describe('FolderCreate', () => {
);
expect(createFolderMock).toHaveBeenCalledTimes(1);
});

it('should disable the save button if the folder name is invalid', async () => {
renderWithRouterMatch(
<FolderCreate bucketName={BUCKET_NAME} prefixWithSlash="" />,
undefined,
{
uiObjects: {
showFolderCreate: true,
},
},
);

await userEvent.type(screen.getByRole('textbox'), '/' + FILE_NAME);
expect(screen.getByRole('button', { name: /save/i })).toBeDisabled();
});
});

0 comments on commit 85338de

Please sign in to comment.