1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

add selectable timezone (#2911)

Signed-off-by: andreas-unleash <andreas@getunleash.ai>

1st Iteration = Show the user the timezone and UTC offset
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multipl
![Screenshot 2023-01-27 at 09 46
27](https://user-images.githubusercontent.com/104830839/215034585-d6abe3be-7a13-414c-ada4-b06231ab05a7.png)
e? -->
Closes #
[issue
1-568](https://linear.app/unleash/issue/1-568/show-the-timezone-for-the-currenttime-constraint)

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
This commit is contained in:
andreas-unleash 2023-01-30 16:36:42 +02:00 committed by GitHub
parent 812604902b
commit 751b714642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 150 additions and 95 deletions

View File

@ -106,7 +106,9 @@
"vite-plugin-svgr": "2.4.0",
"vite-tsconfig-paths": "4.0.3",
"vitest": "0.27.1",
"whatwg-fetch": "3.6.2"
"whatwg-fetch": "3.6.2",
"countries-and-timezones": "^3.4.0",
"date-fns-tz": "^1.3.7"
},
"optionalDependencies": {
"orval": "^6.10.3"

View File

@ -1,22 +1,15 @@
import { makeStyles } from 'tss-react/mui';
import React from 'react';
import { styled } from '@mui/material';
const useStyles = makeStyles()(theme => ({
header: {
fontSize: theme.fontSizes.bodySize,
fontWeight: 'normal',
marginTop: '1rem',
marginBottom: '0.25rem',
},
const StyledHeader = styled('h3')(({ theme }) => ({
fontSize: theme.fontSizes.bodySize,
fontWeight: theme.typography.fontWeightMedium,
marginTop: theme.spacing(2),
marginBottom: theme.spacing(0.5),
}));
export const ConstraintFormHeader: React.FC<
React.HTMLAttributes<HTMLDivElement>
> = ({ children, ...rest }) => {
const { classes: styles } = useStyles();
return (
<h3 {...rest} className={styles.header}>
{children}
</h3>
);
return <StyledHeader {...rest}>{children}</StyledHeader>;
};

View File

@ -1,6 +1,11 @@
import { ConstraintFormHeader } from '../ConstraintFormHeader/ConstraintFormHeader';
import Input from 'component/common/Input/Input';
import { parseDateValue, parseValidDate } from 'component/common/util';
import { useMemo, useState } from 'react';
import { styled } from '@mui/material';
import TimezoneCountries from 'countries-and-timezones';
interface IDateSingleValueProps {
setValue: (value: string) => void;
value?: string;
@ -8,35 +13,67 @@ interface IDateSingleValueProps {
setError: React.Dispatch<React.SetStateAction<string>>;
}
const StyledWrapper = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'row',
marginBottom: theme.spacing(1),
alignItems: 'center',
gap: theme.spacing(1),
}));
export const DateSingleValue = ({
setValue,
value,
error,
setError,
}: IDateSingleValueProps) => {
const timezones = Object.values(
TimezoneCountries.getAllTimezones({ deprecated: false })
).map(timezone => ({
key: timezone.name,
label: `${timezone.name}`,
utcOffset: timezone.utcOffsetStr,
}));
const { timeZone: localTimezoneName } =
Intl.DateTimeFormat().resolvedOptions();
const [pickedDate, setPickedDate] = useState(value || '');
const timezoneText = useMemo<string>(() => {
const localTimezone = timezones.find(t => t.key === localTimezoneName);
if (localTimezone != null) {
return `${localTimezone.key} (UTC ${localTimezone.utcOffset})`;
} else {
return 'The time shown is in your local time zone according to your browser.';
}
}, [timezones, localTimezoneName]);
if (!value) return null;
return (
<>
<ConstraintFormHeader>Select a date</ConstraintFormHeader>
<Input
id="date"
label="Date"
type="datetime-local"
value={parseDateValue(value)}
onChange={e => {
setError('');
const parsedDate = parseValidDate(e.target.value);
const dateString = parsedDate?.toISOString();
dateString && setValue(dateString);
}}
InputLabelProps={{
shrink: true,
}}
error={Boolean(error)}
errorText={error}
required
/>
<StyledWrapper>
<Input
id="date"
label="Date"
type="datetime-local"
value={parseDateValue(pickedDate)}
onChange={e => {
setError('');
const parsedDate = parseValidDate(e.target.value);
const dateString = parsedDate?.toISOString();
dateString && setPickedDate(dateString);
dateString && setValue(dateString);
}}
InputLabelProps={{
shrink: true,
}}
error={Boolean(error)}
errorText={error}
required
/>
<p>{timezoneText}</p>
</StyledWrapper>
</>
);
};

View File

@ -16,10 +16,9 @@ interface IInputProps extends Omit<OutlinedTextFieldProps, 'variant'> {
rows?: number;
}
const StyledDiv = styled('div')(({ theme }) => ({
width: '100%',
const StyledDiv = styled('div')({
position: 'relative',
}));
});
const Input = ({
label,

View File

@ -2246,7 +2246,7 @@
"@svgr/hast-util-to-babel-ast" "^6.5.1"
svg-parser "^2.0.4"
"@testing-library/dom@8.19.1", "@testing-library/dom@^8.0.0":
"@testing-library/dom@8.19.1":
version "8.19.1"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.19.1.tgz#0e2dafd281dedb930bb235eac1045470b4129d0e"
integrity sha512-P6iIPyYQ+qH8CvGauAqanhVnjrnRe0IZFSYCeGkSRW9q3u8bdVn2NPI+lasFyVsEQn1J/IFmp5Aax41+dAP9wg==
@ -2260,6 +2260,20 @@
lz-string "^1.4.4"
pretty-format "^27.0.2"
"@testing-library/dom@^8.0.0":
version "8.20.0"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.20.0.tgz#914aa862cef0f5e89b98cc48e3445c4c921010f6"
integrity sha512-d9ULIT+a4EXLX3UU8FBjauG9NnsZHkHztXoIcTsOKoOw030fyjheN9svkTULjJxtYag9DZz5Jz5qkWZDPxTFwA==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/runtime" "^7.12.5"
"@types/aria-query" "^5.0.1"
aria-query "^5.0.0"
chalk "^4.1.0"
dom-accessibility-api "^0.5.9"
lz-string "^1.4.4"
pretty-format "^27.0.2"
"@testing-library/jest-dom@5.16.5":
version "5.16.5"
resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-5.16.5.tgz#3912846af19a29b2dbf32a6ae9c31ef52580074e"
@ -2632,13 +2646,13 @@
"@types/node" "*"
"@typescript-eslint/eslint-plugin@^5.5.0":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.48.1.tgz#deee67e399f2cb6b4608c935777110e509d8018c"
integrity sha512-9nY5K1Rp2ppmpb9s9S2aBiF3xo5uExCehMDmYmmFqqyxgenbHJ3qbarcLt4ITgaD6r/2ypdlcFRdcuVPnks+fQ==
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.48.2.tgz#112e6ae1e23a1dc8333ce82bb9c65c2608b4d8a3"
integrity sha512-sR0Gja9Ky1teIq4qJOl0nC+Tk64/uYdX+mi+5iB//MH8gwyx8e3SOyhEzeLZEFEEfCaLf8KJq+Bd/6je1t+CAg==
dependencies:
"@typescript-eslint/scope-manager" "5.48.1"
"@typescript-eslint/type-utils" "5.48.1"
"@typescript-eslint/utils" "5.48.1"
"@typescript-eslint/scope-manager" "5.48.2"
"@typescript-eslint/type-utils" "5.48.2"
"@typescript-eslint/utils" "5.48.2"
debug "^4.3.4"
ignore "^5.2.0"
natural-compare-lite "^1.4.0"
@ -2647,78 +2661,78 @@
tsutils "^3.21.0"
"@typescript-eslint/experimental-utils@^5.0.0":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.48.1.tgz#5951c0b7ef4b0838ea95f25d53385de0e366e0b8"
integrity sha512-8OoIZZuOeqsm5cxn2f01qHWtVC3M4iixSsfZXPiQUg4Sl4LiU+b5epcJFwxNfqeoLl+SGncELyi3x99zI6C0ng==
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.48.2.tgz#04057cd6e96d225a6ed10e6881086add6c230781"
integrity sha512-Iwx8De8dwl6qPaPZWIaEfP1feN/YFlA5FlCxF3zUIm+2AG92C5Tefkugj2L9ytOFrmTYkTE/CqvJFZbYoVZQMg==
dependencies:
"@typescript-eslint/utils" "5.48.1"
"@typescript-eslint/utils" "5.48.2"
"@typescript-eslint/parser@^5.5.0":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.48.1.tgz#d0125792dab7e232035434ab8ef0658154db2f10"
integrity sha512-4yg+FJR/V1M9Xoq56SF9Iygqm+r5LMXvheo6DQ7/yUWynQ4YfCRnsKuRgqH4EQ5Ya76rVwlEpw4Xu+TgWQUcdA==
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.48.2.tgz#c9edef2a0922d26a37dba03be20c5fff378313b3"
integrity sha512-38zMsKsG2sIuM5Oi/olurGwYJXzmtdsHhn5mI/pQogP+BjYVkK5iRazCQ8RGS0V+YLk282uWElN70zAAUmaYHw==
dependencies:
"@typescript-eslint/scope-manager" "5.48.1"
"@typescript-eslint/types" "5.48.1"
"@typescript-eslint/typescript-estree" "5.48.1"
"@typescript-eslint/scope-manager" "5.48.2"
"@typescript-eslint/types" "5.48.2"
"@typescript-eslint/typescript-estree" "5.48.2"
debug "^4.3.4"
"@typescript-eslint/scope-manager@5.48.1":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.48.1.tgz#39c71e4de639f5fe08b988005beaaf6d79f9d64d"
integrity sha512-S035ueRrbxRMKvSTv9vJKIWgr86BD8s3RqoRZmsSh/s8HhIs90g6UlK8ZabUSjUZQkhVxt7nmZ63VJ9dcZhtDQ==
"@typescript-eslint/scope-manager@5.48.2":
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.48.2.tgz#bb7676cb78f1e94921eaab637a4b5d596f838abc"
integrity sha512-zEUFfonQid5KRDKoI3O+uP1GnrFd4tIHlvs+sTJXiWuypUWMuDaottkJuR612wQfOkjYbsaskSIURV9xo4f+Fw==
dependencies:
"@typescript-eslint/types" "5.48.1"
"@typescript-eslint/visitor-keys" "5.48.1"
"@typescript-eslint/types" "5.48.2"
"@typescript-eslint/visitor-keys" "5.48.2"
"@typescript-eslint/type-utils@5.48.1":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.48.1.tgz#5d94ac0c269a81a91ad77c03407cea2caf481412"
integrity sha512-Hyr8HU8Alcuva1ppmqSYtM/Gp0q4JOp1F+/JH5D1IZm/bUBrV0edoewQZiEc1r6I8L4JL21broddxK8HAcZiqQ==
"@typescript-eslint/type-utils@5.48.2":
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.48.2.tgz#7d3aeca9fa37a7ab7e3d9056a99b42f342c48ad7"
integrity sha512-QVWx7J5sPMRiOMJp5dYshPxABRoZV1xbRirqSk8yuIIsu0nvMTZesKErEA3Oix1k+uvsk8Cs8TGJ6kQ0ndAcew==
dependencies:
"@typescript-eslint/typescript-estree" "5.48.1"
"@typescript-eslint/utils" "5.48.1"
"@typescript-eslint/typescript-estree" "5.48.2"
"@typescript-eslint/utils" "5.48.2"
debug "^4.3.4"
tsutils "^3.21.0"
"@typescript-eslint/types@5.48.1":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.48.1.tgz#efd1913a9aaf67caf8a6e6779fd53e14e8587e14"
integrity sha512-xHyDLU6MSuEEdIlzrrAerCGS3T7AA/L8Hggd0RCYBi0w3JMvGYxlLlXHeg50JI9Tfg5MrtsfuNxbS/3zF1/ATg==
"@typescript-eslint/types@5.48.2":
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.48.2.tgz#635706abb1ec164137f92148f06f794438c97b8e"
integrity sha512-hE7dA77xxu7ByBc6KCzikgfRyBCTst6dZQpwaTy25iMYOnbNljDT4hjhrGEJJ0QoMjrfqrx+j1l1B9/LtKeuqA==
"@typescript-eslint/typescript-estree@5.48.1":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.48.1.tgz#9efa8ee2aa471c6ab62e649f6e64d8d121bc2056"
integrity sha512-Hut+Osk5FYr+sgFh8J/FHjqX6HFcDzTlWLrFqGoK5kVUN3VBHF/QzZmAsIXCQ8T/W9nQNBTqalxi1P3LSqWnRA==
"@typescript-eslint/typescript-estree@5.48.2":
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.48.2.tgz#6e206b462942b32383582a6c9251c05021cc21b0"
integrity sha512-bibvD3z6ilnoVxUBFEgkO0k0aFvUc4Cttt0dAreEr+nrAHhWzkO83PEVVuieK3DqcgL6VAK5dkzK8XUVja5Zcg==
dependencies:
"@typescript-eslint/types" "5.48.1"
"@typescript-eslint/visitor-keys" "5.48.1"
"@typescript-eslint/types" "5.48.2"
"@typescript-eslint/visitor-keys" "5.48.2"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
semver "^7.3.7"
tsutils "^3.21.0"
"@typescript-eslint/utils@5.48.1", "@typescript-eslint/utils@^5.13.0":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.48.1.tgz#20f2f4e88e9e2a0961cbebcb47a1f0f7da7ba7f9"
integrity sha512-SmQuSrCGUOdmGMwivW14Z0Lj8dxG1mOFZ7soeJ0TQZEJcs3n5Ndgkg0A4bcMFzBELqLJ6GTHnEU+iIoaD6hFGA==
"@typescript-eslint/utils@5.48.2", "@typescript-eslint/utils@^5.13.0":
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.48.2.tgz#3777a91dcb22b8499a25519e06eef2e9569295a3"
integrity sha512-2h18c0d7jgkw6tdKTlNaM7wyopbLRBiit8oAxoP89YnuBOzCZ8g8aBCaCqq7h208qUTroL7Whgzam7UY3HVLow==
dependencies:
"@types/json-schema" "^7.0.9"
"@types/semver" "^7.3.12"
"@typescript-eslint/scope-manager" "5.48.1"
"@typescript-eslint/types" "5.48.1"
"@typescript-eslint/typescript-estree" "5.48.1"
"@typescript-eslint/scope-manager" "5.48.2"
"@typescript-eslint/types" "5.48.2"
"@typescript-eslint/typescript-estree" "5.48.2"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"
semver "^7.3.7"
"@typescript-eslint/visitor-keys@5.48.1":
version "5.48.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.48.1.tgz#79fd4fb9996023ef86849bf6f904f33eb6c8fccb"
integrity sha512-Ns0XBwmfuX7ZknznfXozgnydyR8F6ev/KEGePP4i74uL3ArsKbEhJ7raeKr1JSa997DBDwol/4a0Y+At82c9dA==
"@typescript-eslint/visitor-keys@5.48.2":
version "5.48.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.48.2.tgz#c247582a0bcce467461d7b696513bf9455000060"
integrity sha512-z9njZLSkwmjFWUelGEwEbdf4NwKvfHxvGC0OcGN1Hp/XNDIcJ7D5DpPNPv6x6/mFvc1tQHsaWmpD/a4gOvvCJQ==
dependencies:
"@typescript-eslint/types" "5.48.1"
"@typescript-eslint/types" "5.48.2"
eslint-visitor-keys "^3.3.0"
"@uiw/codemirror-extensions-basic-setup@4.19.6":
@ -2964,7 +2978,7 @@ array.prototype.flat@^1.3.1:
es-abstract "^1.20.4"
es-shim-unscopables "^1.0.0"
array.prototype.flatmap@^1.3.0, array.prototype.flatmap@^1.3.1:
array.prototype.flatmap@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/array.prototype.flatmap/-/array.prototype.flatmap-1.3.1.tgz#1aae7903c2100433cb8261cd4ed310aab5c4a183"
integrity sha512-8UGn9O1FDVvMNB0UlLv4voxRMze7+FpHyF5mSMRjWHUMlpoDViniy05870VlxhfgTnLbpuwTzvD76MTtWxB/mQ==
@ -3599,6 +3613,11 @@ cosmiconfig@^7.0.0, cosmiconfig@^7.0.1:
path-type "^4.0.0"
yaml "^1.10.0"
countries-and-timezones@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/countries-and-timezones/-/countries-and-timezones-3.4.0.tgz#7b3510f8cae9418a225795d9f0f78a3f656e8c6e"
integrity sha512-E4YrEFSUKM8JWJB2VAIHJGp3tSCQPfG9xX6glKmr+LUObPnosmPwbsFizdNIewl+MGXTqbR2c3BKGL0HNpVGMQ==
crelt@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/crelt/-/crelt-1.0.5.tgz#57c0d52af8c859e354bace1883eb2e1eb182bb94"
@ -3976,6 +3995,11 @@ data-urls@^3.0.2:
whatwg-mimetype "^3.0.0"
whatwg-url "^11.0.0"
date-fns-tz@^1.3.7:
version "1.3.7"
resolved "https://registry.yarnpkg.com/date-fns-tz/-/date-fns-tz-1.3.7.tgz#e8e9d2aaceba5f1cc0e677631563081fdcb0e69a"
integrity sha512-1t1b8zyJo+UI8aR+g3iqr5fkUHWpd58VBx8J/ZSQ+w7YrGlw80Ag4sA86qkfCXRBLmMc4I2US+aPMd4uKvwj5g==
date-fns@2.29.3:
version "2.29.3"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"
@ -4566,13 +4590,13 @@ eslint-plugin-flowtype@^8.0.3:
string-natural-compare "^3.0.1"
eslint-plugin-import@^2.25.3:
version "2.27.4"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.27.4.tgz#319c2f6f6580e1678d674a258ee5e981c10cc25b"
integrity sha512-Z1jVt1EGKia1X9CnBCkpAOhWy8FgQ7OmJ/IblEkT82yrFU/xJaxwujaTzLWqigewwynRQ9mmHfX9MtAfhxm0sA==
version "2.27.5"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz#876a6d03f52608a3e5bb439c2550588e51dd6c65"
integrity sha512-LmEt3GVofgiGuiE+ORpnvP+kAm3h6MLZJ4Q5HCyHADofsb4VzXFsRiWj3c0OFiV+3DWFh0qg3v9gcPlfc3zRow==
dependencies:
array-includes "^3.1.6"
array.prototype.flat "^1.3.1"
array.prototype.flatmap "^1.3.0"
array.prototype.flatmap "^1.3.1"
debug "^3.2.7"
doctrine "^2.1.0"
eslint-import-resolver-node "^0.3.7"
@ -4621,9 +4645,9 @@ eslint-plugin-react-hooks@^4.3.0:
integrity sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==
eslint-plugin-react@^7.27.1:
version "7.32.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.32.0.tgz#d80f794a638c5770f952ba2ae793f0a516be7c09"
integrity sha512-vSBi1+SrPiLZCGvxpiZIa28fMEUaMjXtCplrvxcIxGzmFiYdsXQDwInEjuv5/i/2CTTxbkS87tE8lsQ0Qxinbw==
version "7.32.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.32.1.tgz#88cdeb4065da8ca0b64e1274404f53a0f9890200"
integrity sha512-vOjdgyd0ZHBXNsmvU+785xY8Bfe57EFbTYYk8XrROzWpr9QBvpjITvAXt9xqcE6+8cjR/g1+mfumPToxsl1www==
dependencies:
array-includes "^3.1.6"
array.prototype.flatmap "^1.3.1"