-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add creating directory through context menu in navigation tree #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
06fc124
feat: add creating directory through context menu in navigation tree
walborn f539859
fix: move 'Create directory' to a separate section in context menu
walborn fe8fc7a
fix: after review create directory
walborn f3ccb99
fix: after review create directory - update previous
walborn 27b8dce
fix: create directory by Enter
walborn 2e163d1
fix: add validation for create directory modal
walborn c330c09
fix: disable apply button whet invalid input
walborn d17e6d0
fix: create directory with dump component
walborn e25d158
fix: make createDirectoryDialog smarter
walborn 48d712e
fix: code-review
Raubzeug c94568e
fix: code-review
Raubzeug 8078842
fix: code-review
Raubzeug 064ac63
fix: code-review
Raubzeug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
14 changes: 14 additions & 0 deletions
14
src/containers/Tenant/Schema/CreateDirectoryDialog/CreateDirectoryDialog.scss
This file contains hidden or 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,14 @@ | ||
.ydb-schema-create-directory-dialog { | ||
&__label { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
margin-bottom: 8px; | ||
} | ||
&__description { | ||
color: var(--g-color-text-secondary); | ||
} | ||
&__input-wrapper { | ||
min-height: 48px; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/containers/Tenant/Schema/CreateDirectoryDialog/CreateDirectoryDialog.tsx
This file contains hidden or 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,115 @@ | ||
import React from 'react'; | ||
|
||
import {Dialog, TextInput} from '@gravity-ui/uikit'; | ||
|
||
import {ResponseError} from '../../../../components/Errors/ResponseError'; | ||
import {schemaApi} from '../../../../store/reducers/schema/schema'; | ||
import {cn} from '../../../../utils/cn'; | ||
import i18n from '../../i18n'; | ||
|
||
import './CreateDirectoryDialog.scss'; | ||
|
||
const b = cn('ydb-schema-create-directory-dialog'); | ||
|
||
const relativePathInputId = 'relativePath'; | ||
|
||
interface SchemaTreeProps { | ||
open: boolean; | ||
onClose: VoidFunction; | ||
parentPath: string; | ||
onSuccess: (value: string) => void; | ||
} | ||
|
||
function validateRelativePath(value: string) { | ||
if (value && /\s/.test(value)) { | ||
return i18n('schema.tree.dialog.whitespace'); | ||
} | ||
return ''; | ||
} | ||
|
||
export function CreateDirectoryDialog({open, onClose, parentPath, onSuccess}: SchemaTreeProps) { | ||
const [validationError, setValidationError] = React.useState(''); | ||
const [relativePath, setRelativePath] = React.useState(''); | ||
const [create, response] = schemaApi.useCreateDirectoryMutation(); | ||
|
||
const resetErrors = () => { | ||
setValidationError(''); | ||
response.reset(); | ||
}; | ||
|
||
const handleUpdate = (updated: string) => { | ||
setRelativePath(updated); | ||
resetErrors(); | ||
}; | ||
|
||
const handleClose = () => { | ||
onClose(); | ||
setRelativePath(''); | ||
resetErrors(); | ||
}; | ||
|
||
const handleSubmit = () => { | ||
const path = `${parentPath}/${relativePath}`; | ||
create({ | ||
database: parentPath, | ||
path, | ||
}) | ||
.unwrap() | ||
.then(() => { | ||
handleClose(); | ||
onSuccess(relativePath); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Dialog open={open} onClose={handleClose} size="s"> | ||
<Dialog.Header caption={i18n('schema.tree.dialog.header')} /> | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
const validationError = validateRelativePath(relativePath); | ||
setValidationError(validationError); | ||
if (!validationError) { | ||
handleSubmit(); | ||
} | ||
}} | ||
> | ||
<Dialog.Body> | ||
<label htmlFor={relativePathInputId} className={b('label')}> | ||
<span className={b('description')}> | ||
{i18n('schema.tree.dialog.description')} | ||
</span> | ||
{`${parentPath}/`} | ||
</label> | ||
<div className={b('input-wrapper')}> | ||
<TextInput | ||
placeholder={i18n('schema.tree.dialog.placeholder')} | ||
value={relativePath} | ||
onUpdate={handleUpdate} | ||
autoFocus | ||
hasClear | ||
autoComplete={false} | ||
disabled={response.isLoading} | ||
validationState={validationError ? 'invalid' : undefined} | ||
id={relativePathInputId} | ||
errorMessage={validationError} | ||
/> | ||
</div> | ||
{response.isError && ( | ||
<ResponseError | ||
error={response.error} | ||
defaultMessage={i18n('schema.tree.dialog.invalid')} | ||
/> | ||
)} | ||
</Dialog.Body> | ||
<Dialog.Footer | ||
loading={response.isLoading} | ||
textButtonApply={i18n('schema.tree.dialog.buttonApply')} | ||
textButtonCancel={i18n('schema.tree.dialog.buttonCancel')} | ||
onClickButtonCancel={handleClose} | ||
propsButtonApply={{type: 'submit'}} | ||
/> | ||
</form> | ||
</Dialog> | ||
); | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// todo: tableTree is very smart, so it is impossible to update it without re-render | ||
// It is need change NavigationTree to dump component and pass props from parent component | ||
// In this case we can store state of tree - uploaded entities, opened nodes, selected entity and so on | ||
import React from 'react'; | ||
|
||
import {NavigationTree} from 'ydb-ui-components'; | ||
|
@@ -8,6 +11,7 @@ import {useQueryModes, useTypedDispatch} from '../../../../utils/hooks'; | |
import {isChildlessPathType, mapPathTypeToNavigationTreeType} from '../../utils/schema'; | ||
import {getActions} from '../../utils/schemaActions'; | ||
import {getControls} from '../../utils/schemaControls'; | ||
import {CreateDirectoryDialog} from '../CreateDirectoryDialog/CreateDirectoryDialog'; | ||
|
||
interface SchemaTreeProps { | ||
rootPath: string; | ||
|
@@ -19,10 +23,12 @@ interface SchemaTreeProps { | |
|
||
export function SchemaTree(props: SchemaTreeProps) { | ||
const {rootPath, rootName, rootType, currentPath, onActivePathUpdate} = props; | ||
|
||
const dispatch = useTypedDispatch(); | ||
|
||
const [_, setQueryMode] = useQueryModes(); | ||
const [createDirectoryOpen, setCreateDirectoryOpen] = React.useState(false); | ||
const [parentPath, setParentPath] = React.useState(''); | ||
const [schemaTreeKey, setSchemaTreeKey] = React.useState(''); | ||
|
||
const fetchPath = async (path: string) => { | ||
const promise = dispatch( | ||
|
@@ -49,34 +55,57 @@ export function SchemaTree(props: SchemaTreeProps) { | |
|
||
return childItems; | ||
}; | ||
|
||
React.useEffect(() => { | ||
// if the cached path is not in the current tree, show root | ||
if (!currentPath?.startsWith(rootPath)) { | ||
onActivePathUpdate(rootPath); | ||
} | ||
}, [currentPath, onActivePathUpdate, rootPath]); | ||
|
||
const handleSuccessSubmit = (relativePath: string) => { | ||
const newPath = `${parentPath}/${relativePath}`; | ||
onActivePathUpdate(newPath); | ||
setSchemaTreeKey(newPath); | ||
}; | ||
|
||
const handleCloseDialog = () => { | ||
setCreateDirectoryOpen(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. I would set some |
||
}; | ||
|
||
const handleOpenCreateDirectoryDialog = (value: string) => { | ||
setParentPath(value); | ||
setCreateDirectoryOpen(true); | ||
}; | ||
return ( | ||
<NavigationTree | ||
rootState={{ | ||
path: rootPath, | ||
name: rootName, | ||
type: mapPathTypeToNavigationTreeType(rootType), | ||
collapsed: false, | ||
}} | ||
fetchPath={fetchPath} | ||
getActions={getActions(dispatch, { | ||
setActivePath: onActivePathUpdate, | ||
setQueryMode, | ||
})} | ||
renderAdditionalNodeElements={getControls(dispatch, { | ||
setActivePath: onActivePathUpdate, | ||
})} | ||
activePath={currentPath} | ||
onActivePathUpdate={onActivePathUpdate} | ||
cache={false} | ||
virtualize | ||
/> | ||
<React.Fragment> | ||
<CreateDirectoryDialog | ||
onClose={handleCloseDialog} | ||
open={createDirectoryOpen} | ||
parentPath={parentPath} | ||
onSuccess={handleSuccessSubmit} | ||
/> | ||
<NavigationTree | ||
key={schemaTreeKey} | ||
rootState={{ | ||
path: rootPath, | ||
name: rootName, | ||
type: mapPathTypeToNavigationTreeType(rootType), | ||
collapsed: false, | ||
}} | ||
fetchPath={fetchPath} | ||
getActions={getActions(dispatch, { | ||
setActivePath: onActivePathUpdate, | ||
setQueryMode, | ||
showCreateDirectoryDialog: handleOpenCreateDirectoryDialog, | ||
})} | ||
renderAdditionalNodeElements={getControls(dispatch, { | ||
setActivePath: onActivePathUpdate, | ||
})} | ||
activePath={currentPath} | ||
onActivePathUpdate={onActivePathUpdate} | ||
cache={false} | ||
virtualize | ||
/> | ||
</React.Fragment> | ||
); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.