Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import { observer } from "mobx-react";
import { cn } from "../../../utils/bem";
import { Button } from "@humansignal/ui";
import { IconClose } from "@humansignal/icons";
import { Tag } from "../../Common/Tag/Tag";
import { FilterDropdown } from "../FilterDropdown";
import "./FilterLine.scss";
import { FilterOperation } from "./FilterOperation";
import { Icon } from "../../Common/Icon/Icon";
 
const Conjunction = observer(({ index, view }) => {
  return (
    <FilterDropdown
      items={[
        { value: "and", label: "And" },
        { value: "or", label: "Or" },
      ]}
      disabled={index > 1}
      value={view.conjunction}
      style={{ textAlign: "right" }}
      onChange={(value) => view.setConjunction(value)}
    />
  );
});
 
export const FilterLine = observer(({ filter, availableFilters, index, view, sidebar, dropdownClassName }) => {
  const childFilter = filter.child_filter;
 
  if (sidebar) {
    // Sidebar layout uses grid structure like main layout
    return (
      <div className={cn("filterLine").mod({ hasChild: !!childFilter })}>
        {/* Main filter row */}
        <div className={cn("filterLine").elem("column").mix("conjunction")}>
          {index === 0 ? (
            <span style={{ fontSize: 12, paddingRight: 5 }}>Where</span>
          ) : (
            <Conjunction index={index} view={view} />
          )}
        </div>
 
        <div className={cn("filterLine").elem("column").mix("field")}>
          <FilterDropdown
            placeholder="Column"
            defaultValue={filter.filter.id}
            items={availableFilters}
            dropdownClassName={dropdownClassName}
            searchFilter={(option, query) => {
              const original = option?.original ?? option;
              const title = original?.field?.title ?? original?.title ?? "";
              const parentTitle = original?.field?.parent?.title ?? "";
              return `${title} ${parentTitle}`.toLowerCase().includes(query.toLowerCase());
            }}
            onChange={(value) => filter.setFilterDelayed(value)}
            optionRender={({ item: { original: filter } }) => (
              <div className={cn("filterLine").elem("selector")}>
                {filter.field.title}
                {filter.field.parent && (
                  <Tag size="small" className="filters-data-tag" color="#1d91e4" style={{ marginLeft: 7 }}>
                    {filter.field.parent.title}
                  </Tag>
                )}
              </div>
            )}
            disabled={filter.field.disabled}
          />
        </div>
 
        <FilterOperation
          filter={filter}
          value={filter.currentValue}
          operator={filter.operator}
          field={filter.field}
          disabled={filter.field.disabled}
        />
 
        {/* Column 5: Remove button - only show if no child filter, otherwise empty space */}
        {!childFilter ? (
          <div className={cn("filterLine").elem("remove")}>
            <Button
              look="string"
              size="small"
              style={{ border: "none" }}
              onClick={(e) => {
                e.stopPropagation();
                filter.delete();
              }}
              icon={<Icon icon={IconClose} size={12} />}
            />
          </div>
        ) : (
          <div className={cn("filterLine").elem("remove")} />
        )}
 
        {/* Child filter row */}
        {childFilter && (
          <>
            {/* Column 1: Conjunction */}
            <div className={cn("filterLine").elem("column").mix("conjunction")}>
              <span style={{ fontSize: 12, paddingRight: 5 }}>and</span>
            </div>
 
            {/* Column 2: Field */}
            <div className={cn("filterLine").elem("column").mix("field child-field")}>
              <FilterDropdown
                placeholder={childFilter.field.title}
                value={childFilter.field.title}
                items={[{ value: childFilter.field.title, label: childFilter.field.title }]}
                disabled={true}
                onChange={() => { }} // No-op since it's disabled
                style={{ minWidth: "80px" }}
              />
            </div>
 
            {/* Column 3 & 4: Operation and Value */}
            <FilterOperation
              filter={childFilter}
              value={childFilter.currentValue}
              operator={childFilter.operator}
              field={childFilter.field}
              disabled={filter.field.disabled}
            />
 
            {/* Column 5: Remove */}
            <div className={cn("filterLine").elem("remove")}>
              <Button
                look="danger"
                size="smaller"
                onClick={(e) => {
                  e.stopPropagation();
                  filter.delete(); // Remove the main filter (which includes child)
                }}
                icon={<Icon icon={IconClose} size={12} />}
              />
            </div>
          </>
        )}
      </div>
    );
  }
 
  // Main layout uses parent grid structure - render children as direct grid items
  return (
    <div className={cn("filterLine").mod({ hasChild: !!childFilter })}>
      <div className={cn("filterLine").elem("column").mix("conjunction")}>
        {index === 0 ? (
          <span style={{ fontSize: 12, paddingRight: 5 }}>Where</span>
        ) : (
          <Conjunction index={index} view={view} />
        )}
      </div>
 
      <div className={cn("filterLine").elem("column").mix("field")}>
        <FilterDropdown
          placeholder="列"
          defaultValue={filter.filter.id}
          items={availableFilters}
          width={80}
          dropdownWidth={120}
          dropdownClassName={dropdownClassName}
          searchFilter={(option, query) => {
            const original = option?.original ?? option;
            const title = original?.field?.title ?? original?.title ?? "";
            const parentTitle = original?.field?.parent?.title ?? "";
            return `${title} ${parentTitle}`.toLowerCase().includes(query.toLowerCase());
          }}
          onChange={(value) => filter.setFilterDelayed(value)}
          optionRender={({ item: { original: filter } }) => (
            <div className={cn("filterLine").elem("selector")}>
              {filter.field.title}
              {filter.field.parent && (
                <Tag size="small" className="filters-data-tag" color="#1d91e4" style={{ marginLeft: 7 }}>
                  {filter.field.parent.title}
                </Tag>
              )}
            </div>
          )}
          disabled={filter.field.disabled}
        />
      </div>
 
      <FilterOperation
        filter={filter}
        value={filter.currentValue}
        operator={filter.operator}
        field={filter.field}
        disabled={filter.field.disabled}
      />
 
      {/* Only show remove button if there's no child filter, or show it on the last column of the main filter */}
      {!childFilter && (
        <div className={cn("filterLine").elem("remove")}>
          <Button
            look="string"
            size="small"
            style={{ border: "none" }}
            onClick={(e) => {
              e.stopPropagation();
              filter.delete();
            }}
            icon={<Icon icon={IconClose} size={12} />}
          />
        </div>
      )}
 
      {/* Render child filters as additional grid items on new row */}
      {childFilter && (
        <>
          {/* Empty column to maintain grid alignment for main filter row */}
          <div className={cn("filterLine").elem("remove")} />
 
          <div className={cn("filterLine").elem("column").mix("conjunction")}>
            <span style={{ fontSize: 12, paddingRight: 5 }}>and</span>
          </div>
 
          <div className={cn("filterLine").elem("column").mix("field child-field")}>
            <FilterDropdown
              placeholder={childFilter.field.title}
              value={childFilter.field.title}
              items={[{ value: childFilter.field.title, label: childFilter.field.title }]}
              disabled={true}
              onChange={() => { }} // No-op since it's disabled
            />
          </div>
 
          <FilterOperation
            filter={childFilter}
            value={childFilter.currentValue}
            operator={childFilter.operator}
            field={childFilter.field}
            disabled={filter.field.disabled}
          />
 
          {/* Show remove button on child filter row - removes the entire filter group */}
          <div className={cn("filterLine").elem("remove")}>
            <Button
              look="string"
              size="small"
              style={{ border: "none" }}
              onClick={(e) => {
                e.stopPropagation();
                filter.delete(); // Remove the main filter (which includes child)
              }}
              icon={<Icon icon={IconClose} size={12} />}
            />
          </div>
        </>
      )}
    </div>
  );
});