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) => {
return (
<div>
<h3>Select field</h3>
<h4>Select field</h4>
<select onChange={(e) => props.setField(e.target.value)}>
{ weatherField.map(field =>
<option
+1 -1
View File
@@ -8,7 +8,7 @@ export const SelectGranularity: Component<{
}> = ({ getGranularity, setGranularity }) => {
return (
<div>
<h3>Select granularity</h3>
<h4>Select granularity</h4>
<select onChange={(e) => setGranularity(e.target.value)}>
{ aggregateGranularity.map(granularity =>
<option
+1 -1
View File
@@ -8,7 +8,7 @@ export const SelectKey: Component<{
}> = (props) => {
return (
<div>
<h3>Select key</h3>
<h4>Select key</h4>
<ul>
{ aggregateKey.map(key =>
<label><li><input
+74 -2
View File
@@ -1,18 +1,90 @@
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<{
getStart: Accessor<Date>,
setStart: Setter<Date>,
getEnd: Accessor<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) => {
const startStr = () => moment(props.getStart()).format("YYYY-MM-DDTHH:mm");
const endStr = () => moment(props.getEnd()).format("YYYY-MM-DDTHH:mm");
return (
<div>
<h3>Select time range</h3>
<p>
<input
type="datetime-local"
+2
View File
@@ -14,9 +14,11 @@
.column:nth-child(2) {
flex-basis: 15%;
background-color: #f2f2f2;
min-width: 200px;
}
.column:nth-child(3) {
flex-basis: 70%;
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;
}