Skip to content
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

Merged
merged 6 commits into from
Feb 25, 2022
Merged

Conversation

PMazarovich
Copy link
Contributor

@PMazarovich PMazarovich commented Nov 9, 2021

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

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT

Comment on lines 602 to 618
@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This is PATCH request, not POST. We do not create any new resources.
  2. 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")
Copy link
Member

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?

Comment on lines 45 to 49
cvat.server.changeRepo.implementation = async (taskId, type, value) => {
const result = await serverProxy.server.changeRepo(taskId, type, value)
return result
}

Copy link
Member

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

Comment on lines 14 to 18
import { Typography } from 'antd';
import { Select } from 'antd';
import { Checkbox } from 'antd';
const { Option } = Select;
const { Paragraph } = Typography;
Copy link
Member

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: [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dumpers: [];
dumpers: any[];

return (
!!repository && (
!!repository && user.isStaff && (
Copy link
Member

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}>
Copy link
Member

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: [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dumpers: [];
dumpers: any[];


onChangeLFSValue = (value): void => {
const { taskInstance } = this.props
this.setState({lfs: value.target.checked});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.setState({lfs: value.target.checked});
this.setState({ lfs: value.target.checked });


onChangeFormatValue = (value: string): void => {
const { taskInstance } = this.props
this.setState({format:value});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.setState({format:value});
this.setState({ format: value });

@bsekachev
Copy link
Member

Hi, thank you for the contribution. Please, look at linter issues.

@PMazarovich
Copy link
Contributor Author

@bsekachev , Hello, I'll try to fix these problems approx, from 6th December

@PMazarovich PMazarovich force-pushed the editable_git branch 7 times, most recently from 3bd8d16 to a72c087 Compare December 6, 2021 16:05
@PMazarovich
Copy link
Contributor Author

@bsekachev , hello, PR fixed as you have suggested.

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}>
Copy link
Member

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:

Suggested change
<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,
Copy link
Member

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 });
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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

@bsekachev
Copy link
Member

bsekachev commented Jan 10, 2022

Could you please merge develop, provide a screenshot to the PR body, and update CHANGELOG.md?

@bsekachev
Copy link
Member

Current UI looks quite ugly, do not you think so?

Screenshot_35

I would propose some changes to do it like this:
Screenshot_36

My changes are

cvat-ui/src/components/task-page/details.tsx

private renderDatasetRepository(): JSX.Element | boolean {
        const { taskInstance, dumpers } = this.props;
        const {
            repository, repositoryStatus, format, lfs,
        } = this.state;
        return (
            !!repository && (
                <Row>
                    <Col className='cvat-dataset-repository-url'>
                        <Text strong className='cvat-text-color'>
                            Dataset Repository
                        </Text>
                        <Paragraph>
                            <Text editable={{ onChange: this.onChangeRepoValue }}>
                                {repository}
                            </Text>
                            {repositoryStatus === 'sync' && (
                                <Tag color='blue'>
                                    <CheckCircleOutlined />
                                    Synchronized
                                </Tag>
                            )}
                            {repositoryStatus === 'merged' && (
                                <Tag color='green'>
                                    <CheckCircleOutlined />
                                    Merged
                                </Tag>
                            )}
                            {repositoryStatus === 'syncing' && (
                                <Tag color='purple'>
                                    <LoadingOutlined />
                                    Syncing
                                </Tag>
                            )}
                            {repositoryStatus === '!sync' && (
                                <Tag
                                    color='red'
                                    onClick={(): void => {
                                        this.setState({
                                            repositoryStatus: 'syncing',
                                        });

                                        syncRepos(taskInstance.id)
                                            .then((): void => {
                                                if (this.mounted) {
                                                    this.setState({
                                                        repositoryStatus: 'sync',
                                                    });
                                                }
                                            })
                                            .catch((error): void => {
                                                if (this.mounted) {
                                                    Modal.error({
                                                        width: 800,
                                                        title: 'Could not synchronize the repository',
                                                        content: error.toString(),
                                                    });

                                                    this.setState({
                                                        repositoryStatus: '!sync',
                                                    });
                                                }
                                            });
                                    }}
                                >
                                    <WarningOutlined />
                                    Synchronize
                                </Tag>
                            )}
                        </Paragraph>
                        <Text strong className='cvat-text-color'>Using format: </Text>
                        <Space>
                            <Select onChange={this.onChangeFormatValue} className='cvat-repository-format-select' value={format}>
                                {
                                    dumpers.map((dumper: any) => (
                                        <Option key={dumper.name} value={dumper.name}>{dumper.name}</Option>
                                    ))
                                }
                            </Select>
                            <Checkbox onChange={this.onChangeLFSValue} checked={lfs}>
                                Large file support
                            </Checkbox>
                        </Space>
                    </Col>
                </Row>
            )
        );
    }

cvat-ui/src/components/task-page/styles.scss

.cvat-dataset-repository-url {
    > a {
        margin-right: $grid-unit-size;
    }

    > .ant-typography {
        > .ant-tag {
            margin-left: $grid-unit-size;

            > span[role='img'] {
                margin-right: $grid-unit-size;
            }
        }

        > .ant-tag-red {
            user-select: none;
            opacity: 0.4;

            &:hover {
                opacity: 0.8;
            }

            &:active {
                opacity: 1;
            }
        }
    }
}

@nmanovic
Copy link
Contributor

@PMazarovich , thanks for all your time and contribution. Will you be able to continue improving the PR?

@PMazarovich
Copy link
Contributor Author

@nmanovic , yes, I'll continue approximately next week

@PMazarovich PMazarovich force-pushed the editable_git branch 2 times, most recently from 49e1596 to a36ba44 Compare January 31, 2022 14:09
@PMazarovich
Copy link
Contributor Author

@bsekachev PR fixed as you have suggested.
Screenshot from 2022-01-31 17-49-48

cvat-ui/src/components/task-page/details.tsx Outdated Show resolved Hide resolved
cvat-ui/src/containers/task-page/details.tsx Outdated Show resolved Hide resolved
cvat-ui/src/utils/git-utils.ts Outdated Show resolved Hide resolved
cvat-ui/src/components/task-page/details.tsx Outdated Show resolved Hide resolved
bsekachev
bsekachev previously approved these changes Feb 4, 2022
Copy link
Member

@bsekachev bsekachev left a 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!

@bsekachev
Copy link
Member

@nmanovic

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'],
Copy link
Contributor

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.

Copy link
Contributor

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.

@nmanovic
Copy link
Contributor

Create an issue to improve the feature: #4386

@nmanovic
Copy link
Contributor

@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!

Copy link
Contributor

@nmanovic nmanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nmanovic nmanovic merged commit cca2586 into cvat-ai:develop Feb 25, 2022
@nmanovic
Copy link
Contributor

@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.

@TOsmanov
Copy link
Contributor

@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.

@nmanovic , yes, sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants