Add option to select full day time range

This commit is contained in:
Guntis Smaukstelis
2023-07-04 00:20:13 +03:00
parent c5b84727a6
commit cf57669830
6 changed files with 93 additions and 5 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ export const SelectField: Component<{
}> = (props) => { }> = (props) => {
return ( return (
<div> <div>
<h3>Select field</h3> <h4>Select field</h4>
<select onChange={(e) => props.setField(e.target.value)}> <select onChange={(e) => props.setField(e.target.value)}>
{ weatherField.map(field => { weatherField.map(field =>
<option <option
+1 -1
View File
@@ -8,7 +8,7 @@ export const SelectGranularity: Component<{
}> = ({ getGranularity, setGranularity }) => { }> = ({ getGranularity, setGranularity }) => {
return ( return (
<div> <div>
<h3>Select granularity</h3> <h4>Select granularity</h4>
<select onChange={(e) => setGranularity(e.target.value)}> <select onChange={(e) => setGranularity(e.target.value)}>
{ aggregateGranularity.map(granularity => { aggregateGranularity.map(granularity =>
<option <option
+1 -1
View File
@@ -8,7 +8,7 @@ export const SelectKey: Component<{
}> = (props) => { }> = (props) => {
return ( return (
<div> <div>
<h3>Select key</h3> <h4>Select key</h4>
<ul> <ul>
{ aggregateKey.map(key => { aggregateKey.map(key =>
<label><li><input <label><li><input
+74 -2
View File
@@ -1,18 +1,90 @@
import moment from 'moment'; import moment from 'moment';
import { Accessor, Component, Setter } from "solid-js"; import { Accessor, batch, Component, createSignal, Setter } from "solid-js";
import "../css/aggregator.css"
export const SelectTimeRange: Component<{ export const SelectTimeRange: Component<{
getStart: Accessor<Date>, getStart: Accessor<Date>,
setStart: Setter<Date>, setStart: Setter<Date>,
getEnd: Accessor<Date>, getEnd: Accessor<Date>,
setEnd: Setter<Date>, setEnd: Setter<Date>,
}> = (props) => {
// true: dateTime, false: date
const [getDateTimeMode, setDateTimeMode] = createSignal(true);
function handleClick() {
const currentMode = getDateTimeMode();
if (currentMode) {
const startDate = moment().subtract(1, "days").startOf("day");
const endDate = moment().subtract(1, "days").endOf("day");
batch(() => {
props.setStart(startDate.toDate());
props.setEnd(endDate.toDate());
});
}
setDateTimeMode(!currentMode);
}
return (
<div>
<div class="timeRangeTitle">
<h4>Time range</h4>
<div><input
type="checkbox"
onClick={handleClick}
checked={getDateTimeMode()}
/> date+time</div>
</div>
{ getDateTimeMode() && <DateTimeRange {...props} /> }
{ !getDateTimeMode() && <DateRange {...props} /> }
</div>
);
}
const DateRange: Component<{
getStart: Accessor<Date>,
setStart: Setter<Date>,
getEnd: Accessor<Date>,
setEnd: Setter<Date>,
}> = (props) => {
const startStr = () => moment(props.getStart()).format("YYYY-MM-DD");
const endStr = () => moment(props.getEnd()).format("YYYY-MM-DD");
return (
<div>
<p>
<input
type="date"
value={startStr()}
onChange={e => props.setStart(
moment(new Date(e.target.value)).startOf("day").toDate()
)}
/> start
</p>
<p>
<input
type="date"
value={endStr()}
onChange={e => props.setEnd(
moment(new Date(e.target.value)).endOf("day").toDate()
)}
/> end
</p>
</div>
);
}
const DateTimeRange: Component<{
getStart: Accessor<Date>,
setStart: Setter<Date>,
getEnd: Accessor<Date>,
setEnd: Setter<Date>,
}> = (props) => { }> = (props) => {
const startStr = () => moment(props.getStart()).format("YYYY-MM-DDTHH:mm"); const startStr = () => moment(props.getStart()).format("YYYY-MM-DDTHH:mm");
const endStr = () => moment(props.getEnd()).format("YYYY-MM-DDTHH:mm"); const endStr = () => moment(props.getEnd()).format("YYYY-MM-DDTHH:mm");
return ( return (
<div> <div>
<h3>Select time range</h3>
<p> <p>
<input <input
type="datetime-local" type="datetime-local"
+2
View File
@@ -14,9 +14,11 @@
.column:nth-child(2) { .column:nth-child(2) {
flex-basis: 15%; flex-basis: 15%;
background-color: #f2f2f2; background-color: #f2f2f2;
min-width: 200px;
} }
.column:nth-child(3) { .column:nth-child(3) {
flex-basis: 70%; flex-basis: 70%;
background-color: #e6e6e6; background-color: #e6e6e6;
min-width: 680px;
} }
+14
View File
@@ -0,0 +1,14 @@
.timeRangeTitle {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 0;
}
.timeRangeTitle h4 {
margin: 0;
}
.timeRangeTitle div {
font-size: 11px;
}