Skip to content

Commit

Permalink
Calendar updates
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Dec 31, 2024
1 parent b00dd92 commit 10fca7d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react"
import React, { useEffect, useState } from "react"
import styled from "styled-components"
import {
metricDurations,
Expand Down Expand Up @@ -86,20 +86,36 @@ const DatePickerItem = ({
max,
name,
label,
dateFrom,
dateTo,
onChange,
}: {
min: Date
max: Date
name: string
label: string
dateFrom: string
dateTo: string
onChange: (date: string[]) => void
}) => {
const { getValues, setValue } = useFormContext()
const { setValue } = useFormContext()

const values = getValues()
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = durationTokenToDate(e.target.value)
if (value === "Invalid date") {
return
}
if (name === "dateFrom") {
onChange([value, dateTo])
} else if (name === "dateTo") {
onChange([dateFrom, value])
}
}

return (
<Form.Item name={name} label={label}>
<Box gap="0.5rem" align="center">
<Form.Input name={name} />
<Form.Input name={name} onChange={handleChange} />
<Popover
trigger={
<Button skin="secondary">
Expand All @@ -122,8 +138,8 @@ const DatePickerItem = ({
})
}}
value={[
new Date(durationTokenToDate(values.dateFrom)),
new Date(durationTokenToDate(values.dateTo)),
new Date(durationTokenToDate(dateFrom)),
new Date(durationTokenToDate(dateTo)),
]}
selectRange={true}
/>
Expand All @@ -149,6 +165,8 @@ export const DateTimePicker = ({
onDateFromToChange: (dateFrom: string, dateTo: string) => void
}) => {
const [mainOpen, setMainOpen] = useState(false)
const [currentDateFrom, setCurrentDateFrom] = useState(dateFrom)
const [currentDateTo, setCurrentDateTo] = useState(dateTo)

const handleSubmit = async (values: FormValues) => {
if (values.dateFrom && values.dateTo) {
Expand Down Expand Up @@ -206,6 +224,22 @@ export const DateTimePicker = ({
}),
})

const datePickerProps = {
min,
max,
dateFrom: currentDateFrom,
dateTo: currentDateTo,
onChange: ([from, to]: string[]) => {
setCurrentDateFrom(from)
setCurrentDateTo(to)
},
}

useEffect(() => {
setCurrentDateFrom(dateFrom)
setCurrentDateTo(dateTo)
}, [dateFrom, dateTo])

return (
<Popover
open={mainOpen}
Expand Down Expand Up @@ -237,10 +271,9 @@ export const DateTimePicker = ({
<DatePickerItem
name="dateFrom"
label="From"
min={min}
max={max}
{...datePickerProps}
/>
<DatePickerItem name="dateTo" label="To" min={min} max={max} />
<DatePickerItem name="dateTo" label="To" {...datePickerProps} />
<Form.Submit>Apply</Form.Submit>
</Box>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { utcToLocal } from "./../../../utils/dateTime"
import { useContext } from "react"
import { ThemeContext } from "styled-components"
import uPlot from "uplot"
import { durationTokenToDate } from "./utils"
import { durationTokenToDate, DATETIME_FORMAT } from "./utils"

type Params = {
data: uPlot.AlignedData
Expand Down Expand Up @@ -32,7 +32,7 @@ const valuePlugin = (
if ([y, x].every((v) => v !== null)) {
timeRef.current!.textContent = utcToLocal(
x as number,
"dd/MM/yyyy HH:mm:ss",
DATETIME_FORMAT,
) as string
valueRef.current!.textContent = mapYValue(y as number)
} else {
Expand Down
10 changes: 8 additions & 2 deletions packages/web-console/src/styles/lib/_react-calendar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@
text-decoration: underline;
}

.react-calendar__tile--active {
.react-calendar__tile--active,
.react-calendar__tile--range,
.react-calendar__tile--hasActive{
background: #b93d64;
color: #fff;
}

.react-calendar__tile--active:enabled:hover,
.react-calendar__tile--active:enabled:focus {
.react-calendar__tile--active:enabled:focus,
.react-calendar__tile--range:enabled:hover,
.react-calendar__tile--range:enabled:focus,
.react-calendar__tile--hasActive:enabled:hover,
.react-calendar__tile--hasActive:enabled:focus {
background: #b93d64;
}

0 comments on commit 10fca7d

Please sign in to comment.