Skip to content

Commit

Permalink
#178 Progress on preview UI, Swapping out server state into react-query
Browse files Browse the repository at this point in the history
-  Better error and load states for preview
- Remove Zustand for server specific state and move it into react-query.
  • Loading branch information
Nospamas committed Feb 13, 2024
1 parent 367da68 commit a51b224
Show file tree
Hide file tree
Showing 41 changed files with 757 additions and 848 deletions.
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.5.0",
"private": true,
"dependencies": {
"@tanstack/react-query": "^5.20.2",
"axios": "^0.27.2",
"bootstrap": "^5.1.3",
"chroma-js": "^2.4.2",
Expand Down Expand Up @@ -40,6 +41,7 @@
"zustand": "^4.4.7"
},
"devDependencies": {
"@tanstack/react-query-devtools": "^5.20.2",
"husky": "^8.0.3",
"jest-each": "^28.1.1",
"lint-staged": "^15.2.0",
Expand Down
129 changes: 0 additions & 129 deletions src/api/metadata.js

This file was deleted.

12 changes: 7 additions & 5 deletions src/components/controls/StationFilters/StationFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import DateSelector from "../../selectors/DateSelector";
import OnlyWithClimatologyControl from "../../controls/OnlyWithClimatologyControl";
import { commonSelectorStyles } from "../../selectors/styles";
import { usePairedImmerByKey } from "../../../hooks";
import { useNetworks } from "../../../state/query-hooks/use-networks";
import { useVariables } from "../../../state/query-hooks/use-variables";
import { useFrequencies } from "../../../state/query-hooks/use-frequencies";

export const useStationFiltering = () => {
const { normal, transitional, isPending, setState } = usePairedImmerByKey({
Expand All @@ -58,13 +61,12 @@ export const useStationFiltering = () => {
function StationFilters({
state,
setState,
metadata: {
networks: allNetworks,
variables: allVariables,
frequencies: allFrequencies,
},
rowClasses = { className: "mb-3" },
}) {
const { data: allNetworks } = useNetworks();
const { data: allVariables } = useVariables();
const { data: allFrequencies } = useFrequencies();

return (
<React.Fragment>
<Row {...rowClasses}>
Expand Down
31 changes: 17 additions & 14 deletions src/components/daterange/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ const getFormattedIntervals = (
const formattedBlockedDates = blockedDates
.sort((a, b) => a.start - b.start)
.map((interval, index) => {
let { start, end, type } = interval;
let { start, end, type, color } = interval;

if (isBefore(start, startTime)) start = startTime;
if (isAfter(end, endTime)) end = endTime;

const source = getConfig(start);
const target = getConfig(end);

return { id: `${classPrefix}-${index}`, source, target, type };
return { id: `${classPrefix}-${index}`, source, target, type, color };
});

console.log("### formattedBlockedDates", formattedBlockedDates);
Expand Down Expand Up @@ -258,18 +258,21 @@ class DateRange extends React.Component {
<Tracks left={false} right={false}>
{({ getTrackProps }) => (
<>
{dataIntervals.map(({ id, source, target, type }, index) => (
<DataTrack
key={id}
source={source}
target={target}
getTrackProps={getTrackProps}
count={dataIntervals.length}
index={index}
type={type}
disabled
/>
))}
{dataIntervals.map(
({ id, source, target, type, color }, index) => (
<DataTrack
key={id}
source={source}
target={target}
getTrackProps={getTrackProps}
count={dataIntervals.length}
index={index}
type={type}
color={color}
disabled
/>
),
)}
</>
)}
</Tracks>
Expand Down
2 changes: 0 additions & 2 deletions src/components/daterange/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ $react-time-range--track--disabled: repeating-linear-gradient(
z-index: 2;
&__observation {
@extend .react_time_range__data_track;
background-color: red;
}
&__climatology {
@extend .react_time_range__data_track;
background-color: green;
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/components/daterange/sub/DataTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,33 @@ const baseHeight = 50;
* @param {Object} params.index the index of this data track
* @returns {Object} basicStyle
**/
const getTrackStyle = ({ source, target, count, index }) => {
const getTrackStyle = ({ source, target, count, index, color }) => {
const height = baseHeight / count / 2;
const topPosition = -22 + (baseHeight / count) * index + height / 2;
console.log("### getTrackStyle", source, target, count, index, color);
const basicStyle = {
top: `${topPosition}px`,
height: `${height}px`,
left: `${source.percent}%`,
width: `calc(${target.percent - source.percent}% - 1px)`,
backgroundColor: color,
};

return basicStyle;
};

const DataTrack = ({ source, target, getTrackProps, count, index, type }) => (
const DataTrack = ({
source,
target,
getTrackProps,
count,
index,
type,
color,
}) => (
<div
className={`react_time_range__data_track${type ? "__" + type : ""}`}
style={getTrackStyle({ source, target, count, index })}
style={getTrackStyle({ source, target, count, index, color })}
{...getTrackProps()}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/info/Disclaimer/Disclaimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React, { useState } from "react";
import { Button, Modal } from "react-bootstrap";
import "./Disclaimer.css";
import { useStore } from "../../../state/state-store";
import { useConfig } from "../../../state/query-hooks/use-config";

function Disclaimer() {
const config = useStore((state) => state.config);
const { data: config } = useConfig();
const [acknowledged, setAcknowledged] = useState(!config.disclaimer.enabled);
const acknowledge = () => setAcknowledged(true);

Expand Down
Loading

0 comments on commit a51b224

Please sign in to comment.