Skip to content

Commit

Permalink
fix bunch of problems
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed May 12, 2020
1 parent 120061d commit 5ae7978
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages-premium
26 changes: 11 additions & 15 deletions packages/common/src/DateProfileGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DateMarker, startOfDay, addDays } from './datelib/marker'
import { Duration, createDuration, getWeeksFromInput, asRoughDays, asRoughMs, greatestDurationDenominator } from './datelib/duration'
import { Duration, createDuration, asRoughDays, asRoughMs, greatestDurationDenominator } from './datelib/duration'
import { DateRange, OpenDateRange, constrainMarkerToRange, intersectRanges, rangesIntersect, parseRange, DateRangeInput } from './datelib/date-range'
import { ViewSpec } from './structs/view-spec'
import { DateEnv, DateInput } from './datelib/env'
Expand Down Expand Up @@ -247,25 +247,18 @@ export class DateProfileGenerator { // only publicly used for isHiddenDay :(
// `unit` is the already-computed greatestDurationDenominator unit of duration.
buildRangeFromDuration(date: DateMarker, direction, duration: Duration, unit) {
let { dateEnv, dateAlignment } = this.props
let dateIncrementInput
let dateIncrementDuration
let start: DateMarker
let end: DateMarker
let res

// compute what the alignment should be
if (!dateAlignment) {
dateIncrementInput = this.props.dateIncrement

if (dateIncrementInput) {
dateIncrementDuration = createDuration(dateIncrementInput)
let { dateIncrement } = this.props

if (dateIncrement) {
// use the smaller of the two units
if (asRoughMs(dateIncrementDuration) < asRoughMs(duration)) {
dateAlignment = greatestDurationDenominator(
dateIncrementDuration,
!getWeeksFromInput(dateIncrementInput)
).unit
if (asRoughMs(dateIncrement) < asRoughMs(duration)) {
dateAlignment = greatestDurationDenominator(dateIncrement).unit
} else {
dateAlignment = unit
}
Expand Down Expand Up @@ -356,15 +349,18 @@ export class DateProfileGenerator { // only publicly used for isHiddenDay :(
// Compute the duration value that should be added/substracted to the current date
// when a prev/next operation happens.
buildDateIncrement(fallback): Duration {
let dateIncrementInput = this.props.dateIncrement
let { dateIncrement } = this.props
let customAlignment

if (dateIncrementInput) {
return createDuration(dateIncrementInput)
if (dateIncrement) {
return dateIncrement

} else if ((customAlignment = this.props.dateAlignment)) {
return createDuration(1, customAlignment)

} else if (fallback) {
return fallback

} else {
return createDuration({ days: 1 })
}
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/component/event-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const EVENT_UI_REFINERS = {
constraint: identity as Identity<ConstraintInput>,
overlap: identity as Identity<boolean>,
allow: identity as Identity<AllowFunc>,
className: parseClassNames,
classNames: parseClassNames,
color: String,
backgroundColor: String,
Expand Down Expand Up @@ -61,7 +62,7 @@ export function createEventUi(refined: EventUiRefined, context: CalendarContext)
backgroundColor: refined.backgroundColor || refined.color || '',
borderColor: refined.borderColor || refined.color || '',
textColor: refined.textColor || '',
classNames: refined.classNames || []
classNames: (refined.className || []).concat(refined.classNames || []) // join singular and plural
}
}

Expand Down
27 changes: 15 additions & 12 deletions packages/common/src/datelib/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Duration {
months: number
days: number
milliseconds: number
specifiedWeeks?: boolean
}

const INTERNAL_UNITS = [ 'years', 'months', 'days', 'milliseconds' ]
Expand All @@ -39,9 +40,9 @@ export function createDuration(input: DurationInput, unit?: string): Duration |
if (typeof input === 'string') {
return parseString(input)
} else if (typeof input === 'object' && input) { // non-null object
return normalizeObject(input)
return parseObject(input)
} else if (typeof input === 'number') {
return normalizeObject({ [unit || 'milliseconds']: input })
return parseObject({ [unit || 'milliseconds']: input })
} else {
return null
}
Expand All @@ -66,23 +67,25 @@ function parseString(s: string): Duration {
return null
}

function normalizeObject(obj: DurationObjectInput): Duration {
return {
function parseObject(obj: DurationObjectInput): Duration {
let duration: Duration = {
years: obj.years || obj.year || 0,
months: obj.months || obj.month || 0,
days:
(obj.days || obj.day || 0) +
getWeeksFromInput(obj) * 7,
days: obj.days || obj.day || 0,
milliseconds:
(obj.hours || obj.hour || 0) * 60 * 60 * 1000 + // hours
(obj.minutes || obj.minute || 0) * 60 * 1000 + // minutes
(obj.seconds || obj.second || 0) * 1000 + // seconds
(obj.milliseconds || obj.millisecond || obj.ms || 0) // ms
}
}

export function getWeeksFromInput(input: DurationInput) {
return typeof input === 'object' && (input.weeks || input.week || 0)
let weeks = obj.weeks || obj.week
if (weeks) {
duration.days += weeks * 7
duration.specifiedWeeks = true
}

return duration
}


Expand Down Expand Up @@ -191,7 +194,7 @@ export function wholeDivideDurations(numerator: Duration, denominator: Duration)
return res
}

export function greatestDurationDenominator(dur: Duration, dontReturnWeeks?: boolean) {
export function greatestDurationDenominator(dur: Duration) {
let ms = dur.milliseconds
if (ms) {
if (ms % 1000 !== 0) {
Expand All @@ -208,7 +211,7 @@ export function greatestDurationDenominator(dur: Duration, dontReturnWeeks?: boo
}
}
if (dur.days) {
if (!dontReturnWeeks && dur.days % 7 === 0) {
if (dur.specifiedWeeks && dur.days % 7 === 0) {
return { unit: 'week', value: dur.days / 7 }
}
return { unit: 'day', value: dur.days }
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/datelib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface DateEnvSettings {
calendarSystem: string
locale: Locale
weekNumberCalculation?: WeekNumberCalculation
firstDay?: any,
firstDay?: number, // will override what the locale wants
weekText?: string,
cmdFormatter?: CmdFormatterFunc
defaultSeparator?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export {
} from './render-hook-misc'

export {
BASE_OPTION_DEFAULTS, identity, Identity,
BASE_OPTION_DEFAULTS, BASE_OPTION_REFINERS, identity, Identity,
BaseOptionRefiners, BaseOptionsRefined,
CalendarOptionRefiners, CalendarOptions, CalendarOptionsRefined, GenericObject,
ViewOptionRefiners, ViewOptions, ViewOptionsRefined, RawOptionsFromRefiners, RefinedOptionsFromRefiners, refineProps,
Expand Down
6 changes: 4 additions & 2 deletions packages/common/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ export const BASE_OPTION_REFINERS = {
validRange: identity as Identity<DateRangeInput | ((this: CalendarApi, nowDate: Date) => DateRangeInput)>, // `this` works?
visibleRange: identity as Identity<DateRangeInput | ((this: CalendarApi, currentDate: Date) => DateRangeInput)>, // `this` works?
titleFormat: identity as Identity<FormatterInput>, // DONT parse just yet. we need to inject titleSeparator

// only used by list-view, but languages define the value, so we need it in base options
noEventsText: String
}

type BuiltInBaseOptionRefiners = typeof BASE_OPTION_REFINERS
Expand Down Expand Up @@ -258,8 +261,7 @@ export const BASE_OPTION_DEFAULTS = {
eventDragMinDistance: 5, // only applies to mouse
expandRows: false,
navLinks: false,
selectable: false,
firstDay: 0
selectable: false
}

export type BaseOptionsRefined = DefaultedRefinedOptions<
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/reducers/CalendarDataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ function buildDateEnv(
timeZone: string,
explicitLocale: LocaleSingularArg,
weekNumberCalculation,
firstDay,
firstDay: number | undefined,
weekText,
pluginHooks: PluginHooks,
availableLocaleData: RawLocaleInfo,
Expand Down Expand Up @@ -619,7 +619,7 @@ function buildViewUiProps(calendarContext: CalendarContext) {
startEditable: options.eventStartEditable,
durationEditable: options.eventDurationEditable,
constraint: options.eventConstraint,
// overlap: options.eventOverlap, // validation system uses this directly, b/c might be a func
overlap: typeof options.eventOverlap === 'boolean' ? options.eventOverlap : undefined,
allow: options.eventAllow,
backgroundColor: options.eventBackgroundColor,
borderColor: options.eventBorderColor,
Expand All @@ -630,7 +630,7 @@ function buildViewUiProps(calendarContext: CalendarContext) {

selectionConfig: createEventUi({
constraint: options.selectConstraint,
// overlap: options.selectOverlap, // validation system uses this directly, b/c might be a func
overlap: typeof options.selectOverlap === 'boolean' ? options.selectOverlap : undefined,
allow: options.selectAllow
}, calendarContext)
}
Expand Down
10 changes: 5 additions & 5 deletions packages/common/src/structs/event-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ Will NOT populate date-related props.
*/
export function parseEventDef(refined: EventRefined, extra: GenericObject, sourceId: string, allDay: boolean, hasEnd: boolean, context: CalendarContext): EventDef {
let def: EventDef = {
title: refined.title,
groupId: refined.groupId,
publicId: refined.id,
url: refined.url,
title: refined.title || '',
groupId: refined.groupId || '',
publicId: refined.id || '',
url: refined.url || '',
recurringDef: null,
defId: guid(),
sourceId,
Expand All @@ -143,7 +143,7 @@ export function parseEventDef(refined: EventRefined, extra: GenericObject, sourc
}


function parseSingle(refined: EventRefined, defaultAllDay: boolean | null, context: CalendarContext, leftovers?, allowOpenRange?: boolean) {
function parseSingle(refined: EventRefined, defaultAllDay: boolean | null, context: CalendarContext, allowOpenRange?: boolean) {
let allDay = refined.allDay
let startMeta
let startMarker = null
Expand Down
8 changes: 2 additions & 6 deletions packages/common/src/structs/view-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ViewDef, compileViewDefs } from './view-def'
import { Duration, createDuration, greatestDurationDenominator, getWeeksFromInput } from '../datelib/duration'
import { Duration, createDuration, greatestDurationDenominator } from '../datelib/duration'
import { mapHash } from '../util/object'
import { ViewOptions, CalendarOptions, BASE_OPTION_DEFAULTS } from '../options'
import { ViewConfigInputHash, parseViewConfigs, ViewConfigHash, ViewComponentType } from './view-config'
Expand Down Expand Up @@ -54,11 +54,7 @@ function buildViewSpec(viewDef: ViewDef, overrideConfigs: ViewConfigHash, option
duration = createDuration(durationInput)

if (duration) { // valid?
let denom = greatestDurationDenominator(
duration,
!getWeeksFromInput(durationInput)
)

let denom = greatestDurationDenominator(duration)
durationUnit = denom.unit

if (denom.value === 1) {
Expand Down
8 changes: 4 additions & 4 deletions packages/list/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { identity, Identity, ClassNamesGenerator, CustomContentGenerator, DidMou
import { NoEventsHookProps } from './ListView'

export const OPTION_REFINERS = {
noEventsText: String,
listDayFormat: createFalsableFormatter, // defaults specified in list plugins
listDaySideFormat: createFalsableFormatter, // "

noEventsClassNames: identity as Identity<ClassNamesGenerator<NoEventsHookProps>>,
noEventsContent: identity as Identity<CustomContentGenerator<NoEventsHookProps>>,
noEventsDidMount: identity as Identity<DidMountHandler<NoEventsHookProps>>,
noEventsWillUnmount: identity as Identity<WillUnmountHandler<NoEventsHookProps>>,
noEventsWillUnmount: identity as Identity<WillUnmountHandler<NoEventsHookProps>>

listDayFormat: createFalsableFormatter, // defaults specified in list plugins
listDaySideFormat: createFalsableFormatter, // "
// noEventsText is defined in base options
}

function createFalsableFormatter(input: FormatterInput | false) {
Expand Down
4 changes: 2 additions & 2 deletions packages/timegrid/src/TimeColsContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class TimeColsContent extends BaseComponent<TimeColsContentProps> { // TO
let nowIndicatorTop =
context.options.nowIndicator &&
props.slatCoords &&
props.slatCoords.safeComputeTop(props.nowDate)
props.slatCoords.safeComputeTop(props.nowDate) // might return void

let colCnt = props.cells.length
let fgEventSegsByRow = this.splitFgEventSegs(props.fgEventSegs, colCnt)
Expand Down Expand Up @@ -107,7 +107,7 @@ export class TimeColsContent extends BaseComponent<TimeColsContentProps> { // TO
</tr>
</tbody>
</table>
{nowIndicatorTop != null &&
{typeof nowIndicatorTop === 'number' &&
<NowIndicatorRoot isAxis={true} date={props.nowDate}>
{(rootElRef, classNames, innerElRef, innerContent) => (
<div
Expand Down
2 changes: 1 addition & 1 deletion packages/timegrid/src/TimeColsSlatsCoords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class TimeColsSlatsCoords {
// Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration).
// This is a makeshify way to compute the time-top. Assumes all slatMetas dates are uniform.
// Eventually allow computation with arbirary slat dates.
computeTimeTop(duration: Duration) {
computeTimeTop(duration: Duration): number {
let { positions, dateProfile, slatMetas } = this
let len = positions.els.length
let slotDurationMs = slatMetas[1].date.valueOf() - slatMetas[0].date.valueOf() // we assume dates are uniform
Expand Down
4 changes: 2 additions & 2 deletions packages/timegrid/src/event-placement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ function sortForwardSegs(forwardSegs: Seg[], eventOrderSpecs) {
}


function buildTimeGridSegCompareObj(seg: Seg) {
let obj = buildSegCompareObj(seg)
function buildTimeGridSegCompareObj(seg: Seg): any {
let obj = buildSegCompareObj(seg) as any

obj.forwardPressure = seg.forwardPressure
obj.backwardCoord = seg.backwardCoord
Expand Down
5 changes: 5 additions & 0 deletions packages/timegrid/src/styles/_timegrid-cols.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
right: 0;
bottom: 0;

// prevents now indicator arrow from bleeding out and causing more scrolling
// bad if we want to do sticky-titles on events in timegrid
// TODO: move now indicator arrow into own container, that does its own overflow
overflow: hidden;

& > table {
height: 100% !important;
}
Expand Down

0 comments on commit 5ae7978

Please sign in to comment.