Filter Timezones by cities (#7118)
* Filter Timezones by cities * Update yarn.lock * Removes large endpoint from batching * Adds caching for large response * Updates test snapshots --------- Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: zomars <[email protected]>
This commit is contained in:
9 files changed
+151
-8
No files matched your search
@@ -17,7 +17,7 @@ export function TimezoneDropdown({
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="dark:focus-within:bg-darkgray-200 dark:bg-darkgray-100 dark:hover:bg-darkgray-200 -mx-[2px] !mt-3 flex w-fit items-center rounded-[4px] px-1 py-[2px] text-sm font-medium focus-within:bg-gray-200 hover:bg-gray-100 [&_svg]:focus-within:text-gray-900 dark:[&_svg]:focus-within:text-white [&_p]:focus-within:text-gray-900 dark:[&_p]:focus-within:text-white">
|
||||
<div className="dark:focus-within:bg-darkgray-200 dark:bg-darkgray-100 dark:hover:bg-darkgray-200 -mx-[2px] !mt-3 flex w-fit max-w-[20rem] items-center rounded-[4px] px-1 py-[2px] text-sm font-medium focus-within:bg-gray-200 hover:bg-gray-100 lg:max-w-[12rem] [&_svg]:focus-within:text-gray-900 dark:[&_svg]:focus-within:text-white [&_p]:focus-within:text-gray-900 dark:[&_p]:focus-within:text-white">
|
||||
<FiGlobe className="dark:text-darkgray-600 flex h-4 w-4 text-gray-600 ltr:mr-[2px] rtl:ml-[2px]" />
|
||||
<TimeOptions onSelectTimeZone={handleSelectTimeZone} />
|
||||
</div>
|
||||
|
||||
@@ -65,6 +65,7 @@ export default trpcNext.createNextApiHandler({
|
||||
"viewer.public.i18n": `no-cache`,
|
||||
// Revalidation time here should be 1 second, per https://github.com/calcom/cal.com/pull/6823#issuecomment-1423215321
|
||||
"viewer.public.slots.getSchedule": `no-cache`, // FIXME
|
||||
"viewer.public.cityTimezones": `max-age=${ONE_DAY_IN_SECONDS}, stale-while-revalidate`,
|
||||
} as const;
|
||||
|
||||
// Find which element above is an exact match for this group of paths
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { expect, it } from "@jest/globals";
|
||||
|
||||
import { filterByCities, addCitiesToDropdown, handleOptionLabel } from "@calcom/lib/timezone";
|
||||
|
||||
const cityData = [
|
||||
{
|
||||
city: "San Francisco",
|
||||
timezone: "America/Argentina/Cordoba",
|
||||
},
|
||||
{
|
||||
city: "Sao Francisco do Sul",
|
||||
timezone: "America/Sao_Paulo",
|
||||
},
|
||||
{
|
||||
city: "San Francisco de Macoris",
|
||||
timezone: "America/Santo_Domingo",
|
||||
},
|
||||
{
|
||||
city: "San Francisco Gotera",
|
||||
timezone: "America/El_Salvador",
|
||||
},
|
||||
{
|
||||
city: "San Francisco",
|
||||
timezone: "America/Los_Angeles",
|
||||
},
|
||||
];
|
||||
|
||||
const option = {
|
||||
value: "America/Los_Angeles",
|
||||
label: "(GMT-8:00) San Francisco",
|
||||
offset: -8,
|
||||
abbrev: "PST",
|
||||
altName: "Pacific Standard Time",
|
||||
};
|
||||
|
||||
it("should return empty array for an empty string", () => {
|
||||
expect(filterByCities("", cityData)).toMatchInlineSnapshot(`Array []`);
|
||||
});
|
||||
|
||||
it("should filter cities for a valid city name", () => {
|
||||
expect(filterByCities("San Francisco", cityData)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"city": "San Francisco",
|
||||
"timezone": "America/Argentina/Cordoba",
|
||||
},
|
||||
Object {
|
||||
"city": "San Francisco de Macoris",
|
||||
"timezone": "America/Santo_Domingo",
|
||||
},
|
||||
Object {
|
||||
"city": "San Francisco Gotera",
|
||||
"timezone": "America/El_Salvador",
|
||||
},
|
||||
Object {
|
||||
"city": "San Francisco",
|
||||
"timezone": "America/Los_Angeles",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("should return appropriate timezone(s) for a given city name array", () => {
|
||||
expect(addCitiesToDropdown(cityData)).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"America/Los_Angeles": "San Francisco",
|
||||
"America/Sao_Paulo": "Sao Francisco do Sul",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it("should render city name as option label if cityData is not empty", () => {
|
||||
expect(handleOptionLabel(option, cityData)).toMatchInlineSnapshot(`"San Francisco GMT -8:00"`);
|
||||
});
|
||||
|
||||
it("should return timezone as option label if cityData is empty", () => {
|
||||
expect(handleOptionLabel(option, [])).toMatchInlineSnapshot(`"America/Los_Angeles GMT -8:00"`);
|
||||
});
|
||||
Reference in new issue
Block a user