Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 509405d

Browse files
Merge pull request #1914 from iamfaran/feat/1820-guiquery-filter
[Feat]: #1820 add search filter/sorting for columns gui query
2 parents 145819a + 27b31d5 commit 509405d

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed
Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { DispatchType } from "lowcoder-core";
22
import { ControlPlacement } from "../../controls/controlParams";
3-
import React, { useContext } from "react";
3+
import React, { useContext,useState,useEffect } from "react";
44
import { Dropdown, OptionsType } from "lowcoder-design";
55
import { isEmpty, values } from "lodash";
66
import { useSelector } from "react-redux";
77
import { getDataSourceStructures } from "../../../redux/selectors/datasourceSelectors";
88
import { changeValueAction } from "lowcoder-core";
99
import { QueryContext } from "../../../util/context/QueryContext";
1010

11+
const COLUMN_SORT_KEY = "lowcoder_column_sort";
12+
1113
export const ColumnNameDropdown = (props: {
1214
table: string;
1315
value: string;
@@ -18,13 +20,27 @@ export const ColumnNameDropdown = (props: {
1820
}) => {
1921
const context = useContext(QueryContext);
2022
const datasourceId = context?.datasourceId ?? "";
21-
const columns: OptionsType =
22-
values(useSelector(getDataSourceStructures)[datasourceId])
23-
?.find((t) => t.name === props.table)
24-
?.columns.map((column) => ({
25-
label: column.name,
26-
value: column.name,
27-
})) ?? [];
23+
24+
// Simple sort preference from localStorage
25+
const [sortColumns, setSortColumns] = useState(() => {
26+
return localStorage.getItem(COLUMN_SORT_KEY) === 'true';
27+
});
28+
29+
useEffect(() => {
30+
localStorage.setItem(COLUMN_SORT_KEY, sortColumns.toString());
31+
}, [sortColumns]);
32+
33+
const rawColumns = values(useSelector(getDataSourceStructures)[datasourceId])
34+
?.find((t) => t.name === props.table)
35+
?.columns.map((column) => ({
36+
label: column.name,
37+
value: column.name,
38+
})) ?? [];
39+
40+
const columns: OptionsType = sortColumns
41+
? [...rawColumns].sort((a, b) => a.label.localeCompare(b.label))
42+
: rawColumns;
43+
2844
return (
2945
<Dropdown
3046
options={columns}
@@ -34,6 +50,20 @@ export const ColumnNameDropdown = (props: {
3450
allowClear={true}
3551
placement={props.placement}
3652
label={props.label}
53+
showSearch={true}
54+
preNode={() => (
55+
<div style={{ padding: '4px 8px', borderBottom: '1px solid #f0f0f0' }}>
56+
<label style={{ fontSize: '12px', cursor: 'pointer', userSelect: 'none' }}>
57+
<input
58+
type="checkbox"
59+
checked={sortColumns}
60+
onChange={(e) => setSortColumns(e.target.checked)}
61+
style={{ marginRight: '6px' }}
62+
/>
63+
Sort A-Z
64+
</label>
65+
</div>
66+
)}
3767
/>
3868
);
3969
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /