Project task subsets (#2774)
* Added task project subsets * Added components list key * Added subset field resetting and subset header * Added CHANGELOG and increased npm package version * Added replacing camelcase to snakemain
parent
98388f5a46
commit
e43707d779
@ -0,0 +1,83 @@
|
|||||||
|
// Copyright (C) 2019-2021 Intel Corporation
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import Autocomplete from 'antd/lib/auto-complete';
|
||||||
|
|
||||||
|
import consts from 'consts';
|
||||||
|
import getCore from 'cvat-core-wrapper';
|
||||||
|
|
||||||
|
const core = getCore();
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
projectId: number;
|
||||||
|
projectSubsets?: Array<string>;
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProjectPartialWithSubsets {
|
||||||
|
id: number;
|
||||||
|
subsets: Array<string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ProjectSubsetField(props: Props): JSX.Element {
|
||||||
|
const {
|
||||||
|
projectId, projectSubsets, value, onChange,
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const [internalValue, setInternalValue] = useState('');
|
||||||
|
const [internalSubsets, setInternalSubsets] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!projectSubsets?.length && projectId) {
|
||||||
|
core.projects.get({ id: projectId, withoutTasks: true }).then((response: ProjectPartialWithSubsets[]) => {
|
||||||
|
if (response.length) {
|
||||||
|
const [project] = response;
|
||||||
|
setInternalSubsets(
|
||||||
|
new Set([
|
||||||
|
...(internalValue ? [internalValue] : []),
|
||||||
|
...consts.DEFAULT_PROJECT_SUBSETS,
|
||||||
|
...project.subsets,
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setInternalSubsets(
|
||||||
|
new Set([
|
||||||
|
...(internalValue ? [internalValue] : []),
|
||||||
|
...consts.DEFAULT_PROJECT_SUBSETS,
|
||||||
|
...(projectSubsets || []),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [projectId, projectSubsets]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setInternalValue(value);
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Autocomplete
|
||||||
|
value={internalValue}
|
||||||
|
placeholder='Input subset'
|
||||||
|
className='cvat-project-search-field'
|
||||||
|
onSearch={(_value) => setInternalValue(_value)}
|
||||||
|
onSelect={(_value) => {
|
||||||
|
if (_value !== internalValue) {
|
||||||
|
onChange(_value);
|
||||||
|
}
|
||||||
|
setInternalValue(_value);
|
||||||
|
}}
|
||||||
|
onBlur={() => onChange(internalValue)}
|
||||||
|
options={Array.from(new Set([...(internalValue ? [internalValue] : []), ...internalSubsets])).map(
|
||||||
|
(subset) => ({
|
||||||
|
value: subset,
|
||||||
|
label: subset,
|
||||||
|
}),
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.1 on 2021-01-29 11:21
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('engine', '0036_auto_20201216_0943'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='task',
|
||||||
|
name='subset',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=64),
|
||||||
|
),
|
||||||
|
]
|
||||||
Loading…
Reference in New Issue