Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui/util: convert js files to typescript #4283

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@types/node": "22.10.5",
"@types/prop-types": "15.7.14",
"@types/react": "18.3.1",
"@types/react-big-calendar": "1.16.0",
"@types/react-big-calendar": "1.16.1",
"@types/react-dom": "18.3.1",
"@types/react-transition-group": "4.4.12",
"@types/react-virtualized-auto-sizer": "1.0.4",
Expand Down
60 changes: 0 additions & 60 deletions web/src/app/util/LuxonLocalizer.js

This file was deleted.

100 changes: 100 additions & 0 deletions web/src/app/util/LuxonLocalizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {
DateLocalizer,
DateRange,
DateRangeFormatFunction,
Formats,
} from 'react-big-calendar'
import { DateTime } from 'luxon'

const isSameMonth = (range: DateRange): boolean => {
return (
range.start.getFullYear() === range.end.getFullYear() &&
range.start.getMonth() === range.end.getMonth()
)
}

const dateRangeFormat: DateRangeFormatFunction = (
range,
culture,
localizer,
): string =>
`${localizer?.format(range.start, 'D', culture)} — ${localizer?.format(range.end, 'D', culture)}`

const timeRangeFormat: DateRangeFormatFunction = (
range,
culture,
localizer,
): string =>
`${localizer?.format(range.start, 't', culture)} — ${localizer?.format(range.end, 't', culture)}`

const timeRangeStartFormat: DateRangeFormatFunction = (
range,
culture,
localizer,
): string => `${localizer?.format(range.start, 't', culture)} — `

const timeRangeEndFormat: DateRangeFormatFunction = (
range,
culture,
localizer,
): string => ` — ${localizer?.format(range.end, 't', culture)}`

const weekRangeFormat: DateRangeFormatFunction = (
range,
culture,
localizer,
): string =>
`${localizer?.format(range.start, 'MMMM dd', culture)} — ${localizer?.format(
range.end,
isSameMonth(range) ? 'dd' : 'MMMM dd',
culture,
)}`

export const formats: Formats = {
dateFormat: 'dd',
dayFormat: 'dd EEE',
weekdayFormat: 'ccc',

selectRangeFormat: timeRangeFormat,
eventTimeRangeFormat: timeRangeFormat,
eventTimeRangeStartFormat: timeRangeStartFormat,
eventTimeRangeEndFormat: timeRangeEndFormat,

timeGutterFormat: 't',

monthHeaderFormat: 'MMMM yyyy',
dayHeaderFormat: 'cccc MMM dd',
dayRangeHeaderFormat: weekRangeFormat,
agendaHeaderFormat: dateRangeFormat,

agendaDateFormat: 'ccc MMM dd',
agendaTimeFormat: 't',
agendaTimeRangeFormat: timeRangeFormat,
}

interface LuxonLocalizerOptions {
firstDayOfWeek: number
}

const LuxonLocalizer = (
DateTime: typeof import('luxon').DateTime,
{ firstDayOfWeek }: LuxonLocalizerOptions,
): DateLocalizer => {
const locale = (d: DateTime, c?: string): DateTime =>
c ? d.reconfigure({ locale: c }) : d

return new DateLocalizer({
formats,
firstOfWeek() {
return firstDayOfWeek
},

format(value, format, culture) {
return locale(DateTime.fromJSDate(value as Date), culture).toFormat(
format,
)
},
})
}

export default LuxonLocalizer
21 changes: 0 additions & 21 deletions web/src/app/util/MountWatcher.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gql } from 'urql'
import { print } from 'graphql'
import { DocumentNode, print } from 'graphql'

import {
queryByName,
Expand All @@ -9,7 +9,8 @@ import {
prefixQuery,
} from './graphql'

const expectEqual = (a, b) => expect(print(a)).toBe(print(b))
const expectEqual = (a: DocumentNode, b: DocumentNode): void =>
expect(print(a)).toBe(print(b))

describe('queryByName', () => {
it('should fetch a single query', () => {
Expand All @@ -32,7 +33,12 @@ describe('queryByName', () => {
})

describe('fieldAlias', () => {
const check = (name, arg, query, expected) =>
const check = (
name: string,
arg: string,
query: DocumentNode,
expected: DocumentNode,
): void =>
test(name, () =>
expect(print(fieldAlias(query, arg))).toBe(print(expected)),
)
Expand Down Expand Up @@ -77,14 +83,19 @@ describe('fieldAlias', () => {
})

describe('prefixQuery', () => {
const check = (name, arg, query, expected) =>
const check = (
name: string,
arg: string,
query: DocumentNode,
expected: DocumentNode,
): void =>
test(name, () =>
expect(print(prefixQuery(query, 'q0_'))).toBe(print(expected)),
)

check(
'should prefix query and variables',
{},
'',
gql`
query ($id: ID!, $id2: ID!) {
user(id: $id) {
Expand Down Expand Up @@ -113,7 +124,12 @@ describe('prefixQuery', () => {
})

describe('mapInputVars', () => {
const check = (name, arg, query, expected) =>
const check = (
name: string,
arg: Record<string, string>,
query: DocumentNode,
expected: DocumentNode,
): void =>
test(name, () =>
expect(print(mapInputVars(query, arg))).toBe(print(expected)),
)
Expand Down Expand Up @@ -183,7 +199,12 @@ describe('mapInputVars', () => {
})

describe('mergeFields', () => {
const check = (name, query1, query2, expected) =>
const check = (
name: string,
query1: DocumentNode,
query2: DocumentNode,
expected: DocumentNode,
): void =>
test(name, () =>
expect(print(mergeFields(query1, query2))).toBe(print(expected)),
)
Expand Down
Loading
Loading