Skip to content

Commit 454c2ba

Browse files
committed
chore(platform): update style of table-filter
1 parent ff75a14 commit 454c2ba

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed

packages/platform/src/app/components/table-filter/TableFilter.tsx

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isNumber, isUndefined } from 'lodash';
21
import React, { useState } from 'react';
32
import { useTranslation } from 'react-i18next';
43

@@ -11,7 +10,6 @@ export interface AppTableFilterProps extends Omit<React.HTMLAttributes<HTMLDivEl
1110
aFilterList?: { label: string; node: React.ReactElement; isEmpty: boolean }[];
1211
aSearchValue?: string;
1312
aSearchPlaceholder?: string;
14-
aLabelWidth?: string | number;
1513
onSearchValueChange?: (value: string) => void;
1614
onSearchClick?: () => void;
1715
onResetClick?: () => void;
@@ -22,7 +20,6 @@ export function AppTableFilter(props: AppTableFilterProps): JSX.Element | null {
2220
aFilterList,
2321
aSearchValue,
2422
aSearchPlaceholder,
25-
aLabelWidth,
2623
onSearchValueChange,
2724
onSearchClick,
2825
onResetClick,
@@ -34,20 +31,7 @@ export function AppTableFilter(props: AppTableFilterProps): JSX.Element | null {
3431

3532
const [searchValue, changeSearchValue] = useDValue<string>('', aSearchValue, onSearchValueChange);
3633

37-
const [labelWidth, badgeValue] = (() => {
38-
let maxLength = 0;
39-
let badgeValue = 0;
40-
if (aFilterList) {
41-
aFilterList.forEach((item) => {
42-
maxLength = Math.max(item.label.length, maxLength);
43-
if (!item.isEmpty) {
44-
badgeValue += 1;
45-
}
46-
});
47-
}
48-
49-
return [isUndefined(aLabelWidth) ? maxLength + 1 + 'em' : aLabelWidth, badgeValue] as const;
50-
})();
34+
const badgeValue = aFilterList ? aFilterList.filter((item) => !item.isEmpty).length : 0;
5135

5236
const [showAdvancedSearch, setShowAdvancedSearch] = useState(false);
5337

@@ -101,14 +85,8 @@ export function AppTableFilter(props: AppTableFilterProps): JSX.Element | null {
10185
<DSeparator></DSeparator>
10286
{aFilterList.map(({ label, node }) => (
10387
<div key={label} className="app-table-filter__filter">
104-
<label className="app-table-filter__filter-label">
105-
<div className="app-colon" style={{ width: labelWidth }}>
106-
{label}
107-
</div>
108-
</label>
109-
{React.cloneElement(node, {
110-
style: { ...node.props.style, maxWidth: `calc(100% - ${isNumber(labelWidth) ? labelWidth + 'px' : labelWidth})` },
111-
})}
88+
<label className="app-table-filter__filter-label">{label}</label>
89+
{node}
11290
</div>
11391
))}
11492
</>

packages/platform/src/app/routes/list/standard-table/StandardTable.tsx

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,29 @@ const StandardTable = AppRoute(() => {
191191
<AppTableFilter
192192
className="mb-3"
193193
aFilterList={[
194+
{
195+
label: 'Status',
196+
node: (
197+
<DCheckbox.Group
198+
dList={[0, 1, 2].map((n) => ({
199+
label: n === 0 ? 'Normal' : n === 1 ? 'Failure' : 'Alarm',
200+
value: n,
201+
}))}
202+
dModel={deviceQuery.status}
203+
onModelChange={(value) => {
204+
setDeviceQuery((draft) => {
205+
draft.status = value;
206+
});
207+
}}
208+
/>
209+
),
210+
isEmpty: queryEmptyStatus.deviceQuery.status,
211+
},
194212
{
195213
label: 'Model',
196214
node: (
197215
<DSelect
198-
style={{ width: '16em' }}
216+
style={{ width: '16em', maxWidth: '100%' }}
199217
dModel={deviceQuery.model}
200218
dList={modelList ?? []}
201219
dLoading={isUndefined(modelList)}
@@ -211,26 +229,7 @@ const StandardTable = AppRoute(() => {
211229
),
212230
isEmpty: queryEmptyStatus.deviceQuery.model,
213231
},
214-
{
215-
label: 'Status',
216-
node: (
217-
<DCheckbox.Group
218-
dList={[0, 1, 2].map((n) => ({
219-
label: n === 0 ? 'Normal' : n === 1 ? 'Failure' : 'Alarm',
220-
value: n,
221-
}))}
222-
dModel={deviceQuery.status}
223-
onModelChange={(value) => {
224-
setDeviceQuery((draft) => {
225-
draft.status = value;
226-
});
227-
}}
228-
/>
229-
),
230-
isEmpty: queryEmptyStatus.deviceQuery.status,
231-
},
232232
]}
233-
aLabelWidth={72}
234233
aSearchValue={deviceQuery.keyword}
235234
aSearchPlaceholder="ID, Name"
236235
onSearchValueChange={(value) => {

packages/platform/src/styles/components/table-filter.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@
2828
}
2929

3030
@include e(filter) {
31-
display: flex;
32-
3331
& + & {
3432
margin-top: 8px;
3533
}
3634
}
3735

3836
@include e(filter-label) {
39-
display: inline-flex;
40-
align-items: center;
41-
height: var(--#{$rd-prefix}size);
37+
display: block;
38+
margin-bottom: 2px;
39+
font-size: 0.775em;
40+
color: var(--#{$rd-prefix}text-color-sub);
4241
}
4342
}

0 commit comments

Comments
 (0)