From 5324f4c176b800780574795933e38a0d989a5c00 Mon Sep 17 00:00:00 2001 From: Guntis Smaukstelis Date: Mon, 25 Dec 2023 12:09:58 +0200 Subject: [PATCH] Select weather fields for country view --- web/src/App.tsx | 2 +- web/src/cities/SelectCity.tsx | 4 +-- web/src/consts.ts | 2 ++ web/src/country/Country.tsx | 11 +++--- web/src/country/MultiSelectField.tsx | 54 ++++++++++++++++++++++++++++ web/src/css/index.css | 9 +++++ 6 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 web/src/country/MultiSelectField.tsx diff --git a/web/src/App.tsx b/web/src/App.tsx index bd96d31..0efd565 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -11,7 +11,7 @@ console.log("api host:", import.meta.env.VITE_API_HOST); type Section = "cities" | "country" | "database"; const App: Component = () => { - const [getSection, setSection] = createSignal
("country"); + const [getSection, setSection] = createSignal
("cities"); const section = () => { switch(getSection()) { diff --git a/web/src/cities/SelectCity.tsx b/web/src/cities/SelectCity.tsx index 665aad3..8320404 100644 --- a/web/src/cities/SelectCity.tsx +++ b/web/src/cities/SelectCity.tsx @@ -33,8 +33,8 @@ export const SelectCity: Component<{ onClick={selectAll} />
    {cityList.map(city => - )}
diff --git a/web/src/consts.ts b/web/src/consts.ts index bb3a60d..c19d377 100644 --- a/web/src/consts.ts +++ b/web/src/consts.ts @@ -4,6 +4,8 @@ export const cityList = ["Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva export const weatherField = ["tempMax", "tempMin", "tempAvg", "precipitation", "windAvg", "windMax", "visibilityMin", "visibilityAvg", "snowAvg", "atmPressire", "dewPoint", "humidity", "sunDuration", "phenomena"]; +export const weatherFieldNumeric = weatherField.filter(f => f !== "phenomena"); + export const aggregateKey = ["min", "max", "avg", "sum", "list", "distinct"]; export const aggregateGranularity = ["hour", "day", "month", "year"]; diff --git a/web/src/country/Country.tsx b/web/src/country/Country.tsx index 83636bd..4bc30de 100644 --- a/web/src/country/Country.tsx +++ b/web/src/country/Country.tsx @@ -1,15 +1,15 @@ +import moment from "moment"; import { createSignal } from "solid-js"; import { QueryResult } from "./result/QueryResult"; import { SelectTimeRange } from "../components/SelectTimeRange"; -import moment from "moment"; -import { weatherField } from "../consts"; +import { weatherFieldNumeric } from "../consts"; +import { MultiSelectField } from "./MultiSelectField"; const nowRounded = new Date(new Date().setMinutes(30)); const dayAgo = moment(nowRounded).subtract(1, "days").subtract(30, "minutes").toDate(); export function Country() { - const weatherFieldNumeric = weatherField.filter(f => f !== "phenomena"); const [getStart, setStart] = createSignal(dayAgo); const [getEnd, setEnd] = createSignal(nowRounded); const [getFields, setFields] = createSignal(weatherFieldNumeric); @@ -19,7 +19,10 @@ export function Country() {

Latvia

- column1 +
, + setFields: Setter, +}> = ({ getFields, setFields }) => { + + function handleSelect(fieldName: string) { + const fields = [...getFields()]; + if (fields.includes(fieldName)) { + const removeIndex = fields.indexOf(fieldName); + fields.splice(removeIndex, 1); + } + else fields.push(fieldName); + + setFields(fields); + } + + function selectAll(e: MouseEvent) { + if (!e.target) return; + const target = e.target as HTMLInputElement; + const selectedFields = target.checked + ? [...weatherFieldNumeric] + : []; + + setFields(selectedFields); + } + + return ( + <> + Select all +
    + {weatherFieldNumeric.map(fieldName => +
  • + +
  • + )} +
+ + ); +} \ No newline at end of file diff --git a/web/src/css/index.css b/web/src/css/index.css index 64d6cf3..996329a 100644 --- a/web/src/css/index.css +++ b/web/src/css/index.css @@ -14,6 +14,15 @@ code { monospace; } +ul { + list-style-type: none; + padding-inline-start: 15px; +} + +thead { + font-weight: bold; +} + @font-face { font-family: 'Rubik'; src: url('../assets/Rubik-Medium.ttf') format('truetype');