-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Git flexibility after task creation #3886
Conversation
cvat/apps/engine/views.py
Outdated
@action(detail=True, methods=['POST'], serializer_class=None, url_path='updateGitData') | ||
def update_git_repo(self, request, pk): | ||
data = request.data | ||
gitDataObj = drm.GitData.objects.filter(task_id=pk)[0] | ||
if data.get("type") == "url": | ||
gitDataObj.url = request.data.get('value') | ||
gitDataObj.save(update_fields=["url"]) | ||
elif data.get("type") == "lfs": | ||
gitDataObj.lfs = bool(request.data.get('value')) | ||
gitDataObj.save(update_fields=["lfs"]) | ||
elif data.get("type") == "format": | ||
gitDataObj.format = request.data.get('value') | ||
gitDataObj.save(update_fields=["format"]) | ||
django_response = HttpResponse( | ||
status=http.HTTPStatus.OK, | ||
) | ||
return django_response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This is PATCH request, not POST. We do not create any new resources.
- It should not be an action for a task. I believe
PATCH /api/v1/git/repository/<id>
is a nice way. PATCH /api/v1/git/repository//patch is also applicable for dataset_repo app (according to its current API).
slogger.task[self._tid].info("Local repository initialization..") | ||
shutil.rmtree(self._cwd, True) | ||
self._clone() | ||
#raise git.exc.GitError("Actual and saved repository URLs aren't match") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this comment now?
cvat-core/src/api-implementation.js
Outdated
cvat.server.changeRepo.implementation = async (taskId, type, value) => { | ||
const result = await serverProxy.server.changeRepo(taskId, type, value) | ||
return result | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, try to avoid adding new methods to cvat-core. All the logic related with creating new repositories are in /cvat/cvat-ui/src/utils/git-utils.ts
and, patching, I believe, should be the same place. You can add new redux actions if they are nesassary from your opinion
import { Typography } from 'antd'; | ||
import { Select } from 'antd'; | ||
import { Checkbox } from 'antd'; | ||
const { Option } = Select; | ||
const { Paragraph } = Typography; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, consider:
import Paragraph from 'antd/lib/typography/Paragraph';
import Checkbox from 'antd/lib/checkbox';
import Select from 'antd/lib/select';
@@ -32,6 +40,8 @@ interface Props { | |||
projectSubsets: string[]; | |||
cancelAutoAnnotation(): void; | |||
onTaskUpdate: (taskInstance: any) => void; | |||
dumpers: []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dumpers: []; | |
dumpers: any[]; |
return ( | ||
!!repository && ( | ||
!!repository && user.isStaff && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only staff can do it? Why not a task owner or smbd else?
</p> | ||
<Paragraph editable={{ onChange: this.onChangeRepoValue }}>{this.state.changedRepo}</Paragraph> | ||
<Text strong className='cvat-text-color'>Using format</Text> | ||
<Select onChange={this.onChangeFormatValue} style={{ width: '100%' }} initialValue={format} defaultValue={format}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, put static styles to .scss files.
@@ -18,6 +18,8 @@ interface StateToProps { | |||
activeInference: ActiveInference | null; | |||
installedGit: boolean; | |||
projectSubsets: string[]; | |||
dumpers: []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dumpers: []; | |
dumpers: any[]; |
|
||
onChangeLFSValue = (value): void => { | ||
const { taskInstance } = this.props | ||
this.setState({lfs: value.target.checked}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.setState({lfs: value.target.checked}); | |
this.setState({ lfs: value.target.checked }); |
|
||
onChangeFormatValue = (value: string): void => { | ||
const { taskInstance } = this.props | ||
this.setState({format:value}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.setState({format:value}); | |
this.setState({ format: value }); |
Hi, thank you for the contribution. Please, look at linter issues. |
@bsekachev , Hello, I'll try to fix these problems approx, from 6th December |
3bd8d16
to
a72c087
Compare
@bsekachev , hello, PR fixed as you have suggested. |
a72c087
to
86e6c30
Compare
return ( | ||
!!repository && ( | ||
<Row> | ||
<Col className='cvat-dataset-repository-url'> | ||
<Text strong className='cvat-text-color'> | ||
Dataset Repository | ||
</Text> | ||
<Paragraph editable={{ onChange: this.onChangeRepoValue }}>{changedRepo}</Paragraph> | ||
<Text strong className='cvat-text-color'>Using format</Text> | ||
<Select onChange={this.onChangeFormatValue} className='cvat-repository-format-select' initialValue={format} defaultValue={format}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do this component managed this way:
<Select onChange={this.onChangeFormatValue} className='cvat-repository-format-select' initialValue={format} defaultValue={format}> | |
<Select onChange={this.onChangeFormatValue} className='cvat-repository-format-select' value={format}> |
@@ -102,7 +111,9 @@ export default class DetailsComponent extends React.PureComponent<Props, State> | |||
|
|||
this.setState({ | |||
repository: data.url, | |||
changedRepo: data.url, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need one more field to store changed repository?
@@ -130,6 +141,26 @@ export default class DetailsComponent extends React.PureComponent<Props, State> | |||
this.mounted = false; | |||
} | |||
|
|||
private onChangeRepoValue = (value: string): void => { | |||
const { taskInstance } = this.props; | |||
this.setState({ changedRepo: value }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First we can get the current state value of repository
state and keep it in memory.
Then do setState with the new repository
value. At the same time I would add repositoryUpdating
flag (to the state). When the flag is true, I would show a loading icon near the field, and disable all the repository fields (Because updating can take long time)
Finally we need to start server request.
In then/catch
set appropriate state for repository
and updatingRepository
. For example in catch
you can revert the previous repository
value (request failed)
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bsekachev , the thing is, that according to current logic, there is no immediate initialization.
Initialization happens only after other events like get/push etc. changeRepo request triggers only changes of appropriate rows in DB. That is why there is no long-run jobs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't catch your idea. There is no long-run server jobs, but there is a server request and its routing/handling can take time (quite long btw for highly loaded servers like cvat.org, for example), so while this processing a user should see an updated field I believe (just strange to see unedited value after a user finishes editing, do not you think?). And better if a user saw some loading
status to understand that there changes weren't actually applied yet.
What is more, the request may be failed, in this case we should revert fiels (otherwise the user sees data which are not real, I mean they are not saved on the sever), it is why I suggested to handle with catch
additionally.
}; | ||
|
||
private onChangeLFSValue = (value): void => { | ||
const { taskInstance } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same comment like above for other change callbacks
}; | ||
|
||
private onChangeFormatValue = (value: string): void => { | ||
const { taskInstance } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same comment like above for other change callbacks
Could you please merge develop, provide a screenshot to the PR body, and update CHANGELOG.md? |
@PMazarovich , thanks for all your time and contribution. Will you be able to continue improving the PR? |
@nmanovic , yes, I'll continue approximately next week |
49e1596
to
a36ba44
Compare
a36ba44
to
3351dfd
Compare
@bsekachev PR fixed as you have suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank your patience and the contribution, works like a charm!
Conflict has been resolved. |
@@ -85,6 +86,35 @@ def get_repository(request, tid): | |||
|
|||
return HttpResponseBadRequest(str(ex)) | |||
|
|||
@login_required | |||
@permission_required(perm=['engine.task.access'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PMazarovich , the file doesn't follow the new permission system. I will merge it as is and create an issue to update the app in accordance with IAM in the PR: #3788.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PMazarovich , please let us know if you can help us to update the Django app.
Create an issue to improve the feature: #4386 |
@PMazarovich , after I change the format, it is impossible to sync repo immediately. Need to change some annotations to do that. In any case I will merge the PR because it works in general. I hope you will help us to improve the feature. Thanks for the contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@TOsmanov , could you please document changes in the PR? Now it is possible to specify the dataset format for dataset repository and update it on the task page. |
Motivation and context
It is necessary sometimes to be able to change git repository data for the task not only during task creation.
With this changes it is possible to change LFS, format and repository URL from task page after task creation.
How has this been tested?
It was tested manually
Checklist
develop
branchcvat-core, cvat-data and cvat-ui)
License
Feel free to contact the maintainers if that's a concern.