Projekt

Obecné

Profil

« Předchozí | Další » 

Revize dee53692

Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)

Disabling tag buttons when adding new tag occurrence

Zobrazit rozdíly:

webapp/components/annotation/SubTagItem.tsx
3 3
import { Button } from 'antd';
4 4
import { useContext } from 'react';
5 5
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
6
import { AnnotationContext } from '../../contexts/AnnotationContext';
6 7

  
7 8
/**
8 9
 * Creates a single tag item in a tag panel.
......
15 16
     */
16 17
    const { selectTag } = useContext(TagCategoryContext);
17 18

  
19
    /**
20
     * Annotation context
21
     */
22
    const { submitting } = useContext(AnnotationContext);
23

  
18 24
    /**
19 25
     * Selects the sub tag.
20 26
     */
......
25 31
    return (
26 32
        <Container>
27 33
            <Row>
28
                <Button onClick={onSelectSubTag} className="w-100 text-start rounded">
34
                <Button
35
                    onClick={onSelectSubTag}
36
                    className="w-100 text-start rounded"
37
                    disabled={submitting}
38
                >
29 39
                    {props.subTag.name}
30 40
                </Button>
31 41
            </Row>
webapp/components/annotation/TagItem.tsx
5 5
import React, { useContext, useState } from 'react';
6 6
import { SubTagItem } from './SubTagItem';
7 7
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
8
import { AnnotationContext } from '../../contexts/AnnotationContext';
8 9

  
9 10
/**
10 11
 * Creates a single tag item in a tag panel.
......
22 23
     */
23 24
    const { selectTag } = useContext(TagCategoryContext);
24 25

  
26
    /**
27
     * Annotation context
28
     */
29
    const { submitting } = useContext(AnnotationContext);
30

  
25 31
    /**
26 32
     * Button icon.
27 33
     */
......
55 61
                        icon={buttonIcon}
56 62
                        onClick={changeSubTagsVisibility}
57 63
                        className="w-100 text-start rounded"
64
                        disabled={submitting}
58 65
                    >
59 66
                        {props.tag.name}
60 67
                        <TagOutlined style={{ color: props.tag.color ?? 'black' }} />
61 68
                    </Button>
62 69
                )}
63 70
                {!hasSubTags && (
64
                    <Button onClick={onSelectTag} className="w-100 text-start rounded">
71
                    <Button
72
                        onClick={onSelectTag}
73
                        className="w-100 text-start rounded"
74
                        disabled={submitting}
75
                    >
65 76
                        {props.tag.name}
66 77
                        <TagOutlined style={{ color: props.tag.color ?? 'black' }} />
67 78
                    </Button>
webapp/contexts/AnnotationContext.tsx
1 1
import React, { createContext, useEffect, useState } from 'react';
2 2
import { AnnotationInfo, ETagType, SubTagInfo, TagInfo, TagInstanceInfo } from '../api';
3 3
import { Tag } from '../components/types/tag';
4
import { annotationController } from '../controllers';
4
import { annotationController, userController } from '../controllers';
5 5
import { GetSelectionInfo } from '../utils/selectionUtils';
6
import { ShowConfirmDelete, ShowToast } from '../utils/alerts';
6 7

  
7 8
/**
8 9
 * Interface of an annotation context provider.
......
13 14
     */
14 15
    tags: TagInstanceInfo[] | null;
15 16

  
17
    /**
18
     * Submitting boolean
19
     */
20
    submitting: boolean;
21

  
16 22
    /**
17 23
     * Sets new tags.
18 24
     * @param newTags An array of new tags.
......
71 77
     */
72 78
    tags: null,
73 79

  
80
    /**
81
     * Submitting boolean
82
     */
83
    submitting: false,
84

  
74 85
    /**
75 86
     * Default implementation of setTags method.
76 87
     * @param v Array of new tags.
......
150 161

  
151 162
    const [mappedTags, setMappedTags] = useState<Tag[] | null>(null);
152 163

  
164
    const [submitting, setSubmitting] = useState(false);
165

  
153 166
    async function markSelectedText(
154 167
        tagId: string,
155 168
        subtagId: string | null,
156 169
        instanceId: string | null
157 170
    ) {
171
        setSubmitting(true);
158 172
        if (!annotation) {
159 173
            console.log('annotation not found');
160 174
            return;
......
170 184

  
171 185
        const id = subtagId ?? tagId;
172 186
        const type: ETagType = subtagId == null ? ETagType.Tag : ETagType.Subtag;
173

  
174
        const res = await annotationController.annotationAnnotationIdPost(
175
            props.annotationId,
176
            {
187
        const res = await annotationController
188
            .annotationAnnotationIdPost(props.annotationId, {
177 189
                id: id,
178 190
                instanceId,
179 191
                type,
180 192
                position: selectionInfo.startPositionOriginalDocument,
181 193
                length: selectionInfo.selectionLengthOriginalDocument,
182
            }
183
        );
194
            })
195
            .catch((e) => ShowToast('Duplicitní výskyt anotace!', 'warning'));
184 196

  
185 197
        await refreshAnnotation();
186 198
    }
......
211 223
            return;
212 224
        }
213 225

  
214
        const deleteRes =
215
            await annotationController.annotationAnnotationIdOccurenceIdDelete(
216
                props.annotationId,
217
                occurrence.occurenceId
218
            );
219

  
220
        await refreshAnnotation();
226
        ShowConfirmDelete(() => {
227
            annotationController
228
                .annotationAnnotationIdOccurenceIdDelete(
229
                    props.annotationId,
230
                    occurrence.occurenceId ?? ''
231
                )
232
                .then(() => refreshAnnotation());
233
        }, 'značku');
221 234
    };
222 235

  
223 236
    /**
......
268 281

  
269 282
        remapAnnotations(data.data);
270 283
        setAnnotation(data.data ?? null);
284
        setSubmitting(false);
271 285
    }
272 286

  
273 287
    /**
......
281 295
        <AnnotationContext.Provider
282 296
            value={{
283 297
                tags,
298
                submitting,
284 299
                setTags,
285 300
                addOccurrence,
286 301
                changeVisibility,

Také k dispozici: Unified diff