-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Reactify ExecutionWindows component (#7113)
- Loading branch information
Jammy Louie
committed
Jun 17, 2019
1 parent
2905d5e
commit c358801
Showing
16 changed files
with
543 additions
and
740 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...pts/modules/core/src/pipeline/config/stages/executionWindows/ExecutionWindowDayPicker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as React from 'react'; | ||
import { DAYS_OF_WEEK } from './daysOfWeek'; | ||
|
||
export interface IExecutionWindowDayPickerConfigProps { | ||
days?: number[]; | ||
onChange: (days: number[]) => void; | ||
} | ||
|
||
export const ExecutionWindowDayPicker = (props: IExecutionWindowDayPickerConfigProps) => { | ||
const daySelected = (ordinal: number): boolean => { | ||
if (props.days) { | ||
return props.days.includes(ordinal); | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
const all = (): void => { | ||
props.onChange([1, 2, 3, 4, 5, 6, 7]); | ||
}; | ||
|
||
const none = (): void => { | ||
props.onChange([]); | ||
}; | ||
|
||
const weekdays = (): void => { | ||
props.onChange([2, 3, 4, 5, 6]); | ||
}; | ||
|
||
const weekend = (): void => { | ||
props.onChange([1, 7]); | ||
}; | ||
|
||
const updateModel = (day: any): void => { | ||
const days = props.days ? [...props.days] : []; | ||
if (days.includes(day.ordinal)) { | ||
days.splice(days.indexOf(day.ordinal), 1); | ||
} else { | ||
days.push(day.ordinal); | ||
} | ||
props.onChange(days); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="btn-group"> | ||
{DAYS_OF_WEEK.map((d, i) => ( | ||
<button | ||
className={'btn btn-default ' + (daySelected(d.ordinal) ? 'active' : '')} | ||
key={i} | ||
onClick={() => updateModel(d)} | ||
type="button" | ||
> | ||
{d.label} | ||
</button> | ||
))} | ||
</div> | ||
<div className="button-controls"> | ||
<span className="btn btn-link" onClick={all}> | ||
All | ||
</span> | ||
<span className="btn btn-link" onClick={none}> | ||
None | ||
</span> | ||
<span className="btn btn-link" onClick={weekdays}> | ||
Weekdays | ||
</span> | ||
<span className="btn btn-link" onClick={weekend}> | ||
Weekend | ||
</span> | ||
</div> | ||
</> | ||
); | ||
}; |
91 changes: 0 additions & 91 deletions
91
...ore/src/pipeline/config/stages/executionWindows/ExecutionWindowDayPickerComponent.spec.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.