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

feat: render CronSchedule #107

Merged
merged 4 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -78,7 +78,7 @@
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@date-io/moment": "1.3.9",
"@lyft/flyteidl": "^0.18.4",
"@lyft/flyteidl": "^0.18.9",
"@material-ui/core": "^4.0.0",
"@material-ui/icons": "^4.0.0",
"@material-ui/pickers": "^3.2.2",
Expand Down
13 changes: 13 additions & 0 deletions src/common/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ export function getScheduleFrequencyString(schedule?: Admin.ISchedule) {
if (schedule.rate) {
return fixedRateToString(schedule.rate);
}
if (schedule.cronSchedule && schedule.cronSchedule.schedule) {
return cronstrue.toString(`${schedule.cronSchedule.schedule}`);
schottra marked this conversation as resolved.
Show resolved Hide resolved
}
return '';
}

export function getScheduleOffsetString(schedule?: Admin.ISchedule) {
if (schedule == null) {
return '';
}
if (schedule.cronSchedule) {
return schedule.cronSchedule.offset;
}
return '';
}

Expand Down
38 changes: 38 additions & 0 deletions src/common/test/formatters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { millisecondsToDuration } from 'common/utils';
import { Admin } from 'flyteidl';
import {
subSecondString,
unknownValueString,
Expand All @@ -12,6 +13,8 @@ import {
formatDate,
formatDateLocalTimezone,
formatDateUTC,
getScheduleFrequencyString,
getScheduleOffsetString,
leftPaddedNumber,
millisecondsToHMS,
protobufDurationToHMS
Expand Down Expand Up @@ -160,6 +163,41 @@ describe('millisecondsToHMS', () => {
);
});

describe('getScheduleFrequencyString', () => {
schottra marked this conversation as resolved.
Show resolved Hide resolved
// input and expected result
const cases: [Admin.ISchedule, string][] = [
[{ cronExpression: '* * * * *' }, 'Every minute'],
[
{ rate: { value: 1, unit: Admin.FixedRateUnit.MINUTE } },
'Every 1 minutes'
],
[{ cronSchedule: { schedule: '* * * * *' } }, 'Every minute'],
[null!, ''],
[{ cronSchedule: { schedule: '' } }, '']
];

cases.forEach(([input, expected]) =>
it(`should produce ${expected} with input ${input}`, () => {
expect(getScheduleFrequencyString(input)).toEqual(expected);
})
);
});

describe('getScheduleOffsetString', () => {
// input and expected result
const cases: [Admin.ISchedule, string][] = [
[{ cronSchedule: { offset: 'P1D' } }, 'P1D'],
[null!, ''],
[{ cronSchedule: { offset: '' } }, '']
];

cases.forEach(([input, expected]) =>
it(`should produce ${expected} with input ${input}`, () => {
expect(getScheduleOffsetString(input)).toEqual(expected);
})
);
});

describe('ensureUrlWithProtocol', () => {
// input and expected result
const cases: [string, string][] = [
Expand Down
11 changes: 9 additions & 2 deletions src/components/Entities/EntitySchedules.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Typography } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import { getScheduleFrequencyString } from 'common/formatters';
import {
getScheduleFrequencyString,
getScheduleOffsetString
} from 'common/formatters';
import { WaitForData } from 'components/common';
import { useCommonStyles } from 'components/common/styles';
import { useWorkflowSchedules } from 'components/hooks';
Expand All @@ -23,7 +26,11 @@ const RenderSchedules: React.FC<{
{launchPlans.map((launchPlan, idx) => {
const { schedule } = launchPlan.spec.entityMetadata;
const frequencyString = getScheduleFrequencyString(schedule);
return <li key={idx}>{frequencyString}</li>;
const offsetString = getScheduleOffsetString(schedule);
const scheduleString = offsetString
? `${frequencyString} (offset: ${offsetString})`
schottra marked this conversation as resolved.
Show resolved Hide resolved
: frequencyString;
return <li key={idx}>{scheduleString}</li>;
})}
</ul>
);
Expand Down
17 changes: 16 additions & 1 deletion src/components/Launch/SchedulesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Chip from '@material-ui/core/Chip';
import { makeStyles, Theme } from '@material-ui/core/styles';
import * as classnames from 'classnames';
import { getScheduleFrequencyString } from 'common/formatters';
import {
getScheduleFrequencyString,
getScheduleOffsetString
} from 'common/formatters';
import { ListProps } from 'components/common';
import { useCommonStyles } from 'components/common/styles';
import {
Expand Down Expand Up @@ -54,6 +57,18 @@ export const schedulesTableColumns: KeyedColumnProps[] = [
label: 'frequency',
width: schedulesTableColumnsWidths.frequency
},
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly sure how this is used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component isn't actually used at the moment. It's left over from the first iteration of the UI which had a very basic view of the schedules (both active and inactive) in a workflow.

cellDataGetter: ({ rowData }: CellDataGetterParams) =>
rowData.spec.entityMetadata.schedule,
cellRenderer: ({ cellData: schedule }: TableCellProps<Schedule>) =>
getScheduleOffsetString(schedule),
dataKey: 'closure',
flexGrow: 1,
flexShrink: 0,
key: 'offset',
label: 'offset',
width: schedulesTableColumnsWidths.offset
},
{
cellDataGetter: ({ rowData }: CellDataGetterParams) =>
isLaunchPlanActive(rowData),
Expand Down
1 change: 1 addition & 0 deletions src/components/Launch/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export const launchPlansTableColumnWidths = {
export const schedulesTableColumnsWidths = {
active: 80,
frequency: 300,
offset: 80,
name: 250
};
35 changes: 9 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1855,10 +1855,10 @@
dependencies:
core-js "^2.5.7"

"@lyft/flyteidl@^0.18.4":
version "0.18.4"
resolved "https://registry.yarnpkg.com/@lyft/flyteidl/-/flyteidl-0.18.4.tgz#47177a33e082355a105f8276bfe15cd2388fcb4a"
integrity sha512-kQ40KN6ffUogPsQmaoLyVRvrg8tcxVaoVSDiGol4cnspeLxsB6728qBHzQY1oRcOeRBFCRASyImJrbbBVpNXeg==
"@lyft/flyteidl@^0.18.9":
version "0.18.9"
resolved "https://registry.yarnpkg.com/@lyft/flyteidl/-/flyteidl-0.18.9.tgz#e8c06a598329de052ca5b539c382749379a93ad7"
integrity sha512-BZCAiHpq+JMsd5u2m8UuedlL1E/CQZjDywXnOO27QmNzJv1zdcZ4QDkBU6ClCQQr/KOBszolyfRVY3N//3AG2Q==

"@marionebl/sander@^0.6.0":
version "0.6.1"
Expand Down Expand Up @@ -7057,7 +7057,7 @@ debug@^3.0.0, debug@^3.1.0, debug@^3.2.5:
dependencies:
ms "^2.1.1"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
Expand Down Expand Up @@ -9720,7 +9720,7 @@ import-local@^3.0.2:
pkg-dir "^4.2.0"
resolve-cwd "^3.0.0"

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
Expand Down Expand Up @@ -11605,11 +11605,6 @@ lodash._basecopy@^3.0.0:
resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36"
integrity sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
Expand All @@ -11618,16 +11613,11 @@ lodash._baseuniq@~4.6.0:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*, lodash._bindcallback@^3.0.0:
lodash._bindcallback@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=

lodash._createassigner@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/lodash._createassigner/-/lodash._createassigner-3.1.1.tgz#838a5bae2fdaca63ac22dee8e19fa4e6d6970b11"
Expand All @@ -11637,19 +11627,12 @@ lodash._createassigner@^3.0.0:
lodash._isiterateecall "^3.0.0"
lodash.restparam "^3.0.0"

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=

lodash._getnative@*, lodash._getnative@^3.0.0:
lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=
Expand Down Expand Up @@ -11770,7 +11753,7 @@ [email protected], lodash.memoize@^4.1.2:
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.restparam@*, lodash.restparam@^3.0.0:
lodash.restparam@^3.0.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=
Expand Down