Skip to content

Commit

Permalink
Fix [Feature Store] Schedule content doesn't match the customized data (
Browse files Browse the repository at this point in the history
  • Loading branch information
mariana-furyk authored Jan 18, 2024
1 parent d351378 commit 6cd7522
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ such restriction.
*/
import React from 'react'
import PropTypes from 'prop-types'
import cronstrue from 'cronstrue'

import FeatureSetsPanelSection from '../FeatureSetsPanelSection/FeatureSetsPanelSection'
import FilterParameters from './FilterParameters'
Expand Down Expand Up @@ -79,7 +78,7 @@ const FeatureSetsPanelDataSourceView = ({
className="schedule-tumbler"
label={
<>
{data.schedule ? cronstrue.toString(data.schedule) : 'Schedule'}
{data.schedule ? 'View schedule' : 'Set schedule'}
<Pencil className="schedule-tumbler__icon" />
</>
}
Expand All @@ -88,6 +87,7 @@ const FeatureSetsPanelDataSourceView = ({
/>
{showSchedule && (
<ScheduleFeatureSet
defaultCron={data.schedule}
setNewFeatureSetSchedule={cron => {
setNewFeatureSetSchedule(cron)
setData(state => ({ ...state, schedule: cron }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import { initialState, recurringReducer, scheduleActionType } from './recurringR
import { decodeLocale, getWeekDays, getWeekStart } from '../../../utils/datePicker.util'
import { getFormatTime } from '../../../utils'
import { generateCronInitialValue } from '../../../utils/generateCronInitialValue'
import { getDefaultSchedule } from '../../../utils/getDefaultSchedule'

const ScheduleFeatureSet = ({ setNewFeatureSetSchedule, setShowSchedule }) => {
const ScheduleFeatureSet = ({ defaultCron, setNewFeatureSetSchedule, setShowSchedule }) => {
const [activeTab, setActiveTab] = useState(tabs[0].id)
const [cron, setCron] = useState('10 * * * *')
const [recurringState, recurringDispatch] = useReducer(recurringReducer, initialState)
Expand Down Expand Up @@ -97,6 +98,12 @@ const ScheduleFeatureSet = ({ setNewFeatureSetSchedule, setShowSchedule }) => {
}
}, [activeTab, cron, daysOfWeek, recurringState.scheduleRepeat])

useEffect(() => {
if (defaultCron) {
getDefaultSchedule(defaultCron, recurringDispatch)
}
}, [defaultCron])

return (
<ScheduleFeatureSetView
activeTab={activeTab}
Expand Down
4 changes: 2 additions & 2 deletions src/components/FilterMenuModal/FilterMenuModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const FilterMenuModal = ({
if (
!event.target.closest('.filters-button') &&
!event.target.closest('.filters-wizard') &&
!event.target.parentNode.previousElementSibling?.classList?.contains('filters-wizard') &&
!event.target.parentNode.nextElementSibling?.classList?.contains('filters-wizard')
!event.target.parentNode?.previousElementSibling?.classList?.contains('filters-wizard') &&
!event.target.parentNode?.nextElementSibling?.classList?.contains('filters-wizard')
) {
setFiltersWizardIsShown(false)
}
Expand Down
66 changes: 2 additions & 64 deletions src/components/ScheduleJob/ScheduleJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { decodeLocale, getWeekDays, getWeekStart } from '../../utils/datePicker.
import { tabs } from './scheduleJobData'
import { getFormatTime } from '../../utils'
import { generateCronInitialValue } from '../../utils/generateCronInitialValue'
import { getDefaultSchedule } from '../../utils/getDefaultSchedule'

const ScheduleJob = ({
defaultCron,
Expand Down Expand Up @@ -112,70 +113,7 @@ const ScheduleJob = ({

useEffect(() => {
if (defaultCron) {
let cron = defaultCron.split(' ')

if (cron[4] !== '*') {
const weekDays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'week'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_DAYS_OF_WEEK,
payload: cron[4].split(',').map(day => weekDays[day])
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_WEEK_TIME,
payload: `${cron[1] >= 10 ? cron[1] : `0${cron[1]}`}:${
cron[0] >= 10 ? cron[0] : `0${cron[0]}`
}`
})
} else if (cron[2] !== '*') {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'month'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_MONTH_TIME,
payload: `${cron[1] >= 10 ? cron[1] : `0${cron[1]}`}:${
cron[0] >= 10 ? cron[0] : `0${cron[0]}`
}`
})
} else if (cron[1] !== '*' && cron[1].match('/')) {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'hour'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_MINUTE,
payload: 0
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_HOUR,
payload: Number(cron[1].replace(/.*\*\//g, ''))
})
} else if (cron[1] !== '*') {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'day'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_DAY_TIME,
payload: `${cron[1] >= 10 ? cron[1] : `0${cron[1]}`}:${
cron[0] >= 10 ? cron[0] : `0${cron[0]}`
}`
})
} else {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'minute'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_MINUTE,
payload: Number(cron[0].replace(/.*\*\//g, ''))
})
}
getDefaultSchedule(defaultCron, recurringDispatch)
}
}, [defaultCron])

Expand Down
87 changes: 87 additions & 0 deletions src/utils/getDefaultSchedule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2019 Iguazio Systems Ltd.
Licensed under the Apache License, Version 2.0 (the "License") with
an addition restriction as set forth herein. You may not use this
file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
In addition, you may not use the software for any purposes that are
illegal under applicable law, and the grant of the foregoing license
under the Apache 2.0 license is conditioned upon your compliance with
such restriction.
*/
import { scheduleActionType } from '../components/ScheduleJob/recurringReducer'

export const getDefaultSchedule = (defaultCron, recurringDispatch) => {
let cron = defaultCron.split(' ')

if (cron[4] !== '*') {
const weekDays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'week'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_DAYS_OF_WEEK,
payload: cron[4].split(',').map(day => weekDays[day])
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_WEEK_TIME,
payload: `${cron[1] >= 10 ? cron[1] : `0${cron[1]}`}:${
cron[0] >= 10 ? cron[0] : `0${cron[0]}`
}`
})
} else if (cron[2] !== '*') {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'month'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_MONTH_TIME,
payload: `${cron[1] >= 10 ? cron[1] : `0${cron[1]}`}:${
cron[0] >= 10 ? cron[0] : `0${cron[0]}`
}`
})
} else if (cron[1] !== '*' && cron[1].match('/')) {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'hour'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_MINUTE,
payload: 0
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_HOUR,
payload: Number(cron[1].replace(/.*\*\//g, ''))
})
} else if (cron[1] !== '*') {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'day'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_DAY_TIME,
payload: `${cron[1] >= 10 ? cron[1] : `0${cron[1]}`}:${
cron[0] >= 10 ? cron[0] : `0${cron[0]}`
}`
})
} else {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: 'minute'
})
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_MINUTE,
payload: Number(cron[0].replace(/.*\*\//g, ''))
})
}
}

0 comments on commit 6cd7522

Please sign in to comment.