-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create reaction from the scratch/import from the file (#227)
* Implement upload and empty reaction creation * Rename scss file * Renamed file, updated dataset file limit * Add redirect after successful reaction import --------- Co-authored-by: Daniil Sloboda <[email protected]>
- Loading branch information
1 parent
640fac5
commit 86823f3
Showing
15 changed files
with
302 additions
and
29 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
18 changes: 18 additions & 0 deletions
18
...ReactionList/CreateReactionMenu/CreateReactionFromFile/CreateReactionFromFile.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,18 @@ | ||
/* | ||
* Copyright 2024 Open Reaction Database Project Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
.fileInput { | ||
margin: 30px 0 40px; | ||
} |
69 changes: 69 additions & 0 deletions
69
...setPage/ReactionList/CreateReactionMenu/CreateReactionFromFile/CreateReactionFromFile.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,69 @@ | ||
/* | ||
* Copyright 2024 Open Reaction Database Project Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { useCallback } from 'react'; | ||
import { FileInput } from '@mantine/core'; | ||
import { useForm, yupResolver } from '@mantine/form'; | ||
import { FormModal } from 'common/components/FormModal/FormModal'; | ||
import { importReactionFromFile } from 'store/reactions/reactions.thunks'; | ||
import { useAppDispatch } from 'store/useAppDispatch'; | ||
import { type CreateReactionFromFileFormValues, createReactionFromFileSchema } from './createReactionFromFile.schema'; | ||
import { type ImportReactionFromFilePayload } from 'store/reactions/reactions.types'; | ||
import classes from './CreateReactionFromFile.module.scss'; | ||
|
||
interface CreateReactionFromFileProps { | ||
onClose: () => void; | ||
} | ||
|
||
export function CreateReactionFromFile({ onClose }: Readonly<CreateReactionFromFileProps>) { | ||
const dispatch = useAppDispatch(); | ||
|
||
const form = useForm< | ||
CreateReactionFromFileFormValues, | ||
(values: CreateReactionFromFileFormValues) => ImportReactionFromFilePayload | ||
>({ | ||
mode: 'controlled', | ||
transformValues: values => ({ | ||
file: values.file as File, | ||
}), | ||
validate: yupResolver(createReactionFromFileSchema), | ||
}); | ||
|
||
const onSubmit = useCallback( | ||
(values: ImportReactionFromFilePayload) => { | ||
dispatch(importReactionFromFile(values)); | ||
}, | ||
[dispatch], | ||
); | ||
|
||
return ( | ||
<FormModal | ||
onClose={onClose} | ||
onSubmit={form.onSubmit(onSubmit)} | ||
title="Import Reaction from File" | ||
submitTitle="Save" | ||
> | ||
<FileInput | ||
className={classes.fileInput} | ||
withAsterisk | ||
label="Reaction file" | ||
accept=".pb,.binpb,.txtpb,.pbtxt,application/json" | ||
description=".pb, .binpb, .txtpb, .pbtxt or .json" | ||
placeholder="Attach file" | ||
{...form.getInputProps('file')} | ||
/> | ||
</FormModal> | ||
); | ||
} |
36 changes: 36 additions & 0 deletions
36
...e/ReactionList/CreateReactionMenu/CreateReactionFromFile/createReactionFromFile.schema.ts
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,36 @@ | ||
/* | ||
* Copyright 2024 Open Reaction Database Project Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import * as yup from 'yup'; | ||
|
||
const MAX_FILE_SIZE = 1024 * 1024 * 15; | ||
|
||
const MAX_FILE_SIZE_MB = (MAX_FILE_SIZE / 1024 / 1024).toFixed(2); | ||
|
||
export const createReactionFromFileSchema = yup.object({ | ||
file: yup | ||
.mixed() | ||
.required('Reaction file is required') | ||
.label('File') | ||
.test({ | ||
message: `Filesize cannot exceed ${MAX_FILE_SIZE_MB} MB`, | ||
test: value => { | ||
const file = value as File; | ||
return file?.size < MAX_FILE_SIZE; | ||
}, | ||
}), | ||
}); | ||
|
||
export type CreateReactionFromFileFormValues = yup.InferType<typeof createReactionFromFileSchema>; |
58 changes: 58 additions & 0 deletions
58
ui/src/pages/DatasetPage/ReactionList/CreateReactionMenu/CreateReactionMenu.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,58 @@ | ||
/* | ||
* Copyright 2024 Open Reaction Database Project Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { useCallback } from 'react'; | ||
import { Button, Menu } from '@mantine/core'; | ||
import { useDisclosure } from '@mantine/hooks'; | ||
import { createEmptyReaction } from 'store/reactions/reactions.thunks'; | ||
import { useAppDispatch } from 'store/useAppDispatch'; | ||
import { AddCircleIcon, ChevronDownIcon } from 'common/icons'; | ||
import { CreateReactionFromFile } from './CreateReactionFromFile/CreateReactionFromFile'; | ||
import classes from './createReactionMenu.module.scss'; | ||
|
||
export function CreateReactionMenu() { | ||
const dispatch = useAppDispatch(); | ||
const [importFromFileOpened, { open: openImportFromFile, close: closeImportFromFile }] = useDisclosure(false); | ||
|
||
const handleReactionCreate = useCallback(() => dispatch(createEmptyReaction()), [dispatch]); | ||
|
||
return ( | ||
<> | ||
<Menu | ||
classNames={{ | ||
dropdown: classes.dropdown, | ||
item: classes.menuItem, | ||
itemSection: classes.menuItemSection, | ||
}} | ||
> | ||
<Menu.Target> | ||
<Button | ||
classNames={{ root: classes.buttonRoot, inner: classes.buttonInner }} | ||
leftSection={<AddCircleIcon />} | ||
rightSection={<ChevronDownIcon />} | ||
> | ||
Reaction | ||
</Button> | ||
</Menu.Target> | ||
<Menu.Dropdown> | ||
<Menu.Item onClick={handleReactionCreate}>From Scratch</Menu.Item> | ||
<Menu.Item onClick={openImportFromFile}>Import from File</Menu.Item> | ||
</Menu.Dropdown> | ||
</Menu> | ||
|
||
{importFromFileOpened && <CreateReactionFromFile onClose={closeImportFromFile} />} | ||
</> | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
ui/src/pages/DatasetPage/ReactionList/CreateReactionMenu/createReactionMenu.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,42 @@ | ||
/* | ||
* Copyright 2024 Open Reaction Database Project Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
.dropdown { | ||
width: 135px; | ||
border: none; | ||
box-shadow: 0 4px 24px 0 #00000014; | ||
} | ||
|
||
.menuItem { | ||
padding: 10px 12px; | ||
border-radius: 8px; | ||
} | ||
|
||
.buttonRoot { | ||
border-radius: 8px; | ||
|
||
&:active { | ||
transform: none; | ||
} | ||
|
||
&[data-expanded='true'] { | ||
outline: 3px solid #3c78d899; | ||
} | ||
} | ||
|
||
.buttonInner { | ||
gap: 6px; | ||
font-weight: 400; | ||
} |
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
Oops, something went wrong.