Skip to content

Commit 1c89464

Browse files
krowvinCopilot
andauthored
1622 data query tool should have a refresh button (#1635)
- Fixes env var naming - Adds a refresh button - adds new menu icon - Enable / Disable Cache (state / browser) - Set asc/desc order - make settings menu icon red when something is disabled (cache) - Change table to desc by default - Disable the auto complete default input box features to ensure they do not get in the way of the smart input items (combobox items) Various snippets: <img width="1419" height="1055" alt="image" src="https://github.com/user-attachments/assets/3dfe6a13-42c7-4ed4-a620-19293437783f" /> <img width="879" height="262" alt="image" src="https://github.com/user-attachments/assets/d030e616-eb33-46c3-886b-b30b898802d7" /> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8834a47 commit 1c89464

14 files changed

Lines changed: 209 additions & 33 deletions

cda-gui/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CDA_API_ROOT=https://water.dev.cwbi.us/cwms-data
1+
VITE_CDA_API_ROOT=https://water.dev.cwbi.us/cwms-data

cda-gui/.env.production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CDA_API_ROOT=https://cwms-data.usace.army.mil/cwms-data
1+
VITE_CDA_API_ROOT=https://cwms-data.usace.army.mil/cwms-data

cda-gui/.env.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CDA_API_ROOT=https://cwms-data-test.cwbi.us/cwms-data
1+
VITE_CDA_API_ROOT=https://cwms-data-test.cwbi.us/cwms-data

cda-gui/src/pages/data-query/components/DataTabs.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default function DataTabs({
1313
timeseriesParams,
1414
begin,
1515
end,
16+
sortAscending,
1617
}) {
1718
if (!tsids || !tsids.length) return null;
1819
if (isLoading) return <Skeleton type="card" className="w-full h-[500px]" />;
@@ -38,7 +39,7 @@ export default function DataTabs({
3839
dateFormat="YYYY-MM-DD HH:mm:ss"
3940
interval="5"
4041
missingString="---"
41-
sortAscending
42+
sortAscending={sortAscending}
4243
trim
4344
pageSize={1000000}
4445
tableOptions={{
@@ -116,4 +117,5 @@ DataTabs.propTypes = {
116117
timeseriesParams: PropTypes.array,
117118
begin: PropTypes.object.isRequired,
118119
end: PropTypes.object.isRequired,
120+
sortAscending: PropTypes.bool.isRequired,
119121
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { forwardRef } from "react";
2+
import PropTypes from "prop-types";
3+
import { FiSettings } from "react-icons/fi";
4+
5+
const SettingsGearButton = forwardRef(function SettingsGearButton(
6+
{ active = false, className = "", ...props },
7+
ref,
8+
) {
9+
const activeClassName = active
10+
? "border-red-200 bg-red-50 text-red-600 hover:bg-red-100"
11+
: "border-slate-300 bg-white text-slate-700 hover:bg-slate-50";
12+
13+
return (
14+
<button
15+
{...props}
16+
ref={ref}
17+
type="button"
18+
className={`inline-flex items-center justify-center gap-2 rounded border px-3 py-2 shadow-sm transition ${activeClassName} ${className}`.trim()}
19+
>
20+
<span className="text-sm font-medium">Query Settings</span>
21+
<FiSettings className="h-5 w-5" aria-hidden="true" />
22+
<span className="sr-only">Open query settings</span>
23+
</button>
24+
);
25+
});
26+
27+
SettingsGearButton.propTypes = {
28+
active: PropTypes.bool,
29+
className: PropTypes.string,
30+
};
31+
32+
export default SettingsGearButton;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
2+
import PropTypes from "prop-types";
3+
import Toggle from "./Toggle";
4+
import SettingsGearButton from "./SettingsGearButton";
5+
6+
export default function SettingsMenu({
7+
cacheEnabled,
8+
setCacheEnabled,
9+
sortAscending,
10+
setSortAscending,
11+
active,
12+
}) {
13+
return (
14+
<Menu as="div" className="relative inline-block text-left">
15+
<MenuButton as={SettingsGearButton} active={active} />
16+
<MenuItems className="absolute right-0 z-10 mt-2 w-72 rounded-md border border-slate-200 bg-white p-4 shadow-lg focus:outline-none">
17+
<MenuItem>
18+
<div className="flex items-start justify-between gap-4">
19+
<div>
20+
<div className="text-sm font-semibold text-slate-900">Enable cache</div>
21+
<p className="text-xs text-slate-600">
22+
Use browser cache for repeated requests. Disable to force fresh fetches.
23+
</p>
24+
</div>
25+
<Toggle
26+
checked={cacheEnabled}
27+
onChange={setCacheEnabled}
28+
className="ml-0"
29+
/>
30+
</div>
31+
</MenuItem>
32+
<MenuItem>
33+
<div className="mt-4 flex items-start justify-between gap-4">
34+
<div>
35+
<div className="text-sm font-semibold text-slate-900">
36+
Descending table order
37+
</div>
38+
<p className="text-xs text-slate-600">
39+
Keep newest timestamps first. Disable to switch to oldest rows first.
40+
</p>
41+
</div>
42+
<Toggle
43+
checked={!sortAscending}
44+
onChange={(checked) => setSortAscending(!checked)}
45+
className="ml-0"
46+
/>
47+
</div>
48+
</MenuItem>
49+
</MenuItems>
50+
</Menu>
51+
);
52+
}
53+
54+
SettingsMenu.propTypes = {
55+
active: PropTypes.bool,
56+
cacheEnabled: PropTypes.bool.isRequired,
57+
setCacheEnabled: PropTypes.func.isRequired,
58+
setSortAscending: PropTypes.func.isRequired,
59+
sortAscending: PropTypes.bool.isRequired,
60+
};

cda-gui/src/pages/data-query/components/TimeSeriesDropdown.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useDebounce } from "use-debounce";
1414
// Catalog client
1515
const catalogApi = new CatalogApi(
1616
new Configuration({
17-
basePath: import.meta.env.CDA_URL,
17+
basePath: import.meta.env.VITE_CDA_API_ROOT,
1818
headers: { accept: "application/json;version=2" },
1919
}),
2020
);
@@ -76,6 +76,11 @@ export default function TimeSeriesDropdown({ office, tsids, setTsids }) {
7676
onChange={(event) => setSearchTerm(event.target.value)}
7777
className="px-3 py-2 border rounded w-full"
7878
placeholder="Search TSID (e.g. Location.Elev.Inst.1Hour.0.Version)"
79+
autoComplete="off"
80+
autoCorrect="off"
81+
autoCapitalize="none"
82+
spellCheck={false}
83+
name="tsid-search"
7984
/>
8085
<ComboboxOptions className="bg-white border mt-1 max-h-60 overflow-auto">
8186
{loading ? (

cda-gui/src/pages/data-query/hooks/useAliases.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { CatalogApi, Configuration } from "cwmsjs";
33

4-
const CDA_URL = import.meta.env.CDA_URL;
4+
const CDA_URL = import.meta.env.VITE_CDA_API_ROOT;
55
const config = new Configuration({
66
basePath: CDA_URL,
77
});

cda-gui/src/pages/data-query/hooks/useConfigList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { BlobApi, Configuration } from "cwmsjs";
33

4-
const CDA_URL = import.meta.env.CDA_URL;
4+
const CDA_URL = import.meta.env.VITE_CDA_API_ROOT;
55
const config = new Configuration({
66
basePath: CDA_URL,
77
});

cda-gui/src/pages/data-query/hooks/useDescriptors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
22
import { Configuration, CatalogApi } from "cwmsjs";
33

44
const config = new Configuration({
5-
basePath: import.meta.env.CDA_URL,
5+
basePath: import.meta.env.VITE_CDA_API_ROOT,
66
});
77
const cataApi = new CatalogApi(config);
88

0 commit comments

Comments
 (0)