1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
| import { getRoot, types } from "mobx-state-tree";
| import { observer } from "mobx-react";
| import { Collapse } from "antd";
|
| import Registry from "../../core/Registry";
| import Types from "../../core/Types";
| import Tree from "../../core/Tree";
| import { AnnotationMixin } from "../../mixins/AnnotationMixin";
| import ProcessAttrsMixin from "../../mixins/ProcessAttrs";
| import { isSelfServe } from "../../utils/billing";
| import { FF_BULK_ANNOTATION, isFF } from "../../utils/feature-flags";
| import { guidGenerator } from "../../utils/unique";
|
| const { Panel } = Collapse;
|
| /**
| * Collapse tag, a content area which can be collapsed and expanded.
| * @example
| * <Collapse>
| * <Panel value="Panel Header">
| * <View><Header value="Hello world" /></View>
| * </Panel>
| * </Collapse>
| * @name Collapse
| * @param {boolean} [accordion=true] - Works as an accordion
| * @param {string} [bordered=false] - Shows border
| * @param {boolean} [open=false] - Sets default collapsed state
| */
| const PanelModel = types
| .model({
| type: "panel",
|
| _value: types.optional(types.string, ""),
| value: types.optional(types.string, ""),
|
| open: types.maybeNull(types.boolean),
|
| children: Types.unionArray([
| "view",
| "header",
| "labels",
| "label",
| "table",
| "taxonomy",
| "choices",
| "choice",
| "collapse",
| "datetime",
| "number",
| "rating",
| "ranker",
| "rectangle",
| "ellipse",
| "polygon",
| "keypoint",
| "brush",
| "bitmask",
| "magicwand",
| "rectanglelabels",
| "bitmasklabels",
| "ellipselabels",
| "polygonlabels",
| "vector",
| "vectorlabels",
| "keypointlabels",
| "brushlabels",
| "hypertextlabels",
| "text",
| "audio",
| "image",
| "hypertext",
| "audioplus",
| "list",
| "dialog",
| "textarea",
| "pairwise",
| "style",
| "label",
| "relations",
| "filter",
| "timeseries",
| "timeserieslabels",
| "paragraphs",
| "paragraphlabels",
| "pdf",
| "video",
| "videorectangle",
| "timelinelabels",
| "custominterface",
| ...Registry.customTags.map((t) => t.tag.toLowerCase()),
| ]),
| })
| .views((self) => ({
| // Indicates that it could exist without information about objects, taskData and regions
| get isIndependent() {
| // if value starts with $ it's related to the data but in case of Panel it's just affect title
| // we may still want to show it even if there is no data
| // if (self.value && self.value[0] === "$") return false;
|
| // In other cases Panel can exist independent if it has some independent children
| return !!self.children?.some((c) => {
| return c.isIndependent === true;
| });
| },
| }));
|
| const Model = types
| .model({
| id: types.optional(types.identifier, guidGenerator),
| type: "collapse",
|
| size: types.optional(types.string, "4"),
| style: types.maybeNull(types.string),
|
| _value: types.optional(types.string, ""),
| value: types.optional(types.string, ""),
|
| bordered: types.optional(types.boolean, false),
| accordion: types.optional(types.boolean, true),
| open: types.maybeNull(types.boolean),
|
| children: Types.unionArray(["panel"]),
| })
| .views((self) => ({
| get store() {
| return getRoot(self);
| },
| // Indicates that it could exist without information about objects, taskData and regions
| get isIndependent() {
| // It is independent if some panels in it are so
| return !!self.children?.some((c) => {
| return c.isIndependent === true;
| });
| },
| }));
|
| const CollapseModel = types.compose("CollapseModel", AnnotationMixin, Model, ProcessAttrsMixin);
|
| const HtxCollapse = observer(({ item }) => {
| const isBulkMode = isFF(FF_BULK_ANNOTATION) && !isSelfServe() && item.store.hasInterface("annotation:bulk");
| const visibleChildren = item.children.filter((i) => i.type === "panel" && (!isBulkMode || i.isIndependent));
|
| // Get default active keys based on both Collapse-level and Panel-level open properties
| // Global open sets the base state for all panels
| // Local open can override the global state for individual panels
| const defaultActiveKeys = visibleChildren.filter((panel) => panel.open ?? item.open).map((c) => `panel-${c.value}`);
|
| // For accordion mode, only the first active key should be used
| const finalActiveKeys = item.accordion
| ? defaultActiveKeys.length > 0
| ? [defaultActiveKeys[0]]
| : []
| : defaultActiveKeys;
|
| return (
| <Collapse bordered={item.bordered} accordion={item.accordion} defaultActiveKey={finalActiveKeys}>
| {visibleChildren.map((c, index) => (
| <Panel key={`panel-${c.value}`} header={c._value || c.value || `Panel ${index + 1}`} forceRender>
| {Tree.renderChildren(c, item.annotation)}
| </Panel>
| ))}
| </Collapse>
| );
| });
|
| Registry.addTag("panel", types.compose("PanelModel", PanelModel, ProcessAttrsMixin), () => {});
| Registry.addTag("collapse", CollapseModel, HtxCollapse);
|
| export { HtxCollapse, CollapseModel };
|
|