Skip to content

Commit 35f0981

Browse files
committed
memo and json
1 parent c1a9bf9 commit 35f0981

21 files changed

Lines changed: 386 additions & 363 deletions

src/views/schedule-details/__fixtures__/schedule-details-sections-config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export const mockScheduleDetailsSectionsConfig: ScheduleDetailsSectionConfig[] =
1111
{
1212
key: 'primary',
1313
getLabel: () => 'Primary row',
14-
getValue: ({ describeSchedule }) =>
15-
describeSchedule.policies?.overlapPolicy,
14+
getValue: ({ formattedScheduleDetails: { policies } }) =>
15+
policies?.overlapPolicy,
1616
},
1717
{
1818
key: 'conditional',
1919
getLabel: () => 'Conditional row',
2020
getValue: () => 'conditional-value',
21-
hide: ({ describeSchedule }) =>
22-
describeSchedule.policies?.overlapPolicy !==
21+
hide: ({ formattedScheduleDetails: { policies } }) =>
22+
policies?.overlapPolicy !==
2323
ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_BUFFER,
2424
},
2525
],

src/views/schedule-details/config/schedule-policies-details.config.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,45 @@ const schedulePoliciesDetailsConfig: ScheduleDetailRowConfig[] = [
1414
{
1515
key: 'overlapPolicy',
1616
getLabel: () => 'Overlap policy',
17-
getValue: ({ describeSchedule }) =>
17+
getValue: ({ formattedScheduleDetails: { policies } }) =>
1818
formatScheduleEnumWithDefault(
19-
describeSchedule.policies?.overlapPolicy,
19+
policies?.overlapPolicy,
2020
SCHEDULE_OVERLAP_POLICY_LABELS,
2121
SERVER_OVERLAP_POLICY_DEFAULT
2222
),
2323
},
2424
{
2525
key: 'catchUpPolicy',
2626
getLabel: () => 'Catchup policy',
27-
getValue: ({ describeSchedule }) =>
27+
getValue: ({ formattedScheduleDetails: { policies } }) =>
2828
formatScheduleEnumWithDefault(
29-
describeSchedule.policies?.catchUpPolicy,
29+
policies?.catchUpPolicy,
3030
SCHEDULE_CATCH_UP_POLICY_LABELS,
3131
SERVER_CATCH_UP_POLICY_DEFAULT
3232
),
3333
},
3434
{
3535
key: 'pauseOnFailure',
3636
getLabel: () => 'Pause on failure',
37-
getValue: ({ describeSchedule }) =>
38-
describeSchedule.policies?.pauseOnFailure ? 'Yes' : 'No',
37+
getValue: ({ formattedScheduleDetails: { policies } }) =>
38+
policies?.pauseOnFailure ? 'Yes' : 'No',
3939
},
4040
{
4141
key: 'bufferLimit',
4242
getLabel: () => 'Buffer limit',
43-
getValue: ({ describeSchedule }) =>
44-
formatScheduleLimitValue(describeSchedule.policies?.bufferLimit),
45-
hide: ({ describeSchedule }) =>
46-
describeSchedule.policies?.overlapPolicy !==
43+
getValue: ({ formattedScheduleDetails: { policies } }) =>
44+
formatScheduleLimitValue(policies?.bufferLimit),
45+
hide: ({ formattedScheduleDetails: { policies } }) =>
46+
policies?.overlapPolicy !==
4747
ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_BUFFER,
4848
},
4949
{
5050
key: 'concurrencyLimit',
5151
getLabel: () => 'Concurrency limit',
52-
getValue: ({ describeSchedule }) =>
53-
formatScheduleLimitValue(describeSchedule.policies?.concurrencyLimit),
54-
hide: ({ describeSchedule }) =>
55-
describeSchedule.policies?.overlapPolicy !==
52+
getValue: ({ formattedScheduleDetails: { policies } }) =>
53+
formatScheduleLimitValue(policies?.concurrencyLimit),
54+
hide: ({ formattedScheduleDetails: { policies } }) =>
55+
policies?.overlapPolicy !==
5656
ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_CONCURRENT,
5757
},
5858
];

src/views/schedule-details/config/schedule-specifications-details.config.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createElement } from 'react';
33
import { type ScheduleDetailRowConfig } from '@/views/schedule-details/schedule-details.types';
44

55
import ScheduleDetailsBadges from '../schedule-details-badges/schedule-details-badges';
6-
import ScheduleDetailsMemo from '../schedule-details-memo/schedule-details-memo';
6+
import ScheduleDetailsJsonView from '../schedule-details-json-view/schedule-details-json-view';
77
import { formatScheduleCronExpression } from '../helpers/format-schedule-cron-expression';
88
import { formatScheduleDuration } from '../helpers/format-schedule-duration';
99
import { formatScheduleTimestamp } from '../helpers/format-schedule-timestamp';
@@ -17,26 +17,26 @@ const scheduleSpecificationsDetailsConfig: ScheduleDetailRowConfig[] = [
1717
{
1818
key: 'cronExpression',
1919
getLabel: () => 'Cron execution',
20-
getValue: ({ describeSchedule }) =>
21-
formatScheduleCronExpression(describeSchedule.spec?.cronExpression),
20+
getValue: ({ formattedScheduleDetails: { spec } }) =>
21+
formatScheduleCronExpression(spec?.cronExpression),
2222
},
2323
{
2424
key: 'nextRunTime',
2525
getLabel: () => 'Next run',
26-
getValue: ({ describeSchedule }) =>
27-
formatScheduleTimestamp(describeSchedule.info?.nextRunTime),
26+
getValue: ({ formattedScheduleDetails: { info } }) =>
27+
formatScheduleTimestamp(info?.nextRunTime),
2828
},
2929
{
3030
key: 'lastRunTime',
3131
getLabel: () => 'Last run',
32-
getValue: ({ describeSchedule }) =>
33-
formatScheduleTimestamp(describeSchedule.info?.lastRunTime),
32+
getValue: ({ formattedScheduleDetails: { info } }) =>
33+
formatScheduleTimestamp(info?.lastRunTime),
3434
},
3535
{
3636
key: 'totalRuns',
3737
getLabel: () => 'Total runs',
38-
getValue: ({ describeSchedule }) => {
39-
const total = describeSchedule.info?.totalRuns || '0';
38+
getValue: ({ formattedScheduleDetails: { info } }) => {
39+
const total = info?.totalRuns || '0';
4040
return createElement(ScheduleDetailsBadges, {
4141
labels: [`${total} runs`],
4242
});
@@ -45,38 +45,41 @@ const scheduleSpecificationsDetailsConfig: ScheduleDetailRowConfig[] = [
4545
{
4646
key: 'createTime',
4747
getLabel: () => 'Creation time',
48-
getValue: ({ describeSchedule }) =>
49-
formatScheduleTimestamp(describeSchedule.info?.createTime),
50-
hide: ({ describeSchedule }) => !describeSchedule.info?.createTime,
48+
getValue: ({ formattedScheduleDetails: { info } }) =>
49+
formatScheduleTimestamp(info?.createTime),
50+
hide: ({ formattedScheduleDetails: { info } }) => !info?.createTime,
5151
},
5252
{
5353
key: 'startTime',
5454
getLabel: () => 'Start time',
55-
getValue: ({ describeSchedule }) =>
56-
formatScheduleTimestamp(describeSchedule.spec?.startTime),
57-
hide: ({ describeSchedule }) => !describeSchedule.spec?.startTime,
55+
getValue: ({ formattedScheduleDetails: { spec } }) =>
56+
formatScheduleTimestamp(spec?.startTime),
57+
hide: ({ formattedScheduleDetails: { spec } }) => !spec?.startTime,
5858
},
5959
{
6060
key: 'endTime',
6161
getLabel: () => 'End time',
62-
getValue: ({ describeSchedule }) =>
63-
formatScheduleTimestamp(describeSchedule.spec?.endTime),
64-
hide: ({ describeSchedule }) => !describeSchedule.spec?.endTime,
62+
getValue: ({ formattedScheduleDetails: { spec } }) =>
63+
formatScheduleTimestamp(spec?.endTime),
64+
hide: ({ formattedScheduleDetails: { spec } }) => !spec?.endTime,
6565
},
6666
{
6767
key: 'memo',
6868
getLabel: () => 'Memo',
69-
getValue: ({ describeSchedule }) =>
70-
createElement(ScheduleDetailsMemo, { memo: describeSchedule.memo }),
71-
hide: ({ describeSchedule }) => !describeSchedule.memo?.fields,
69+
getValue: ({ formattedScheduleDetails: { action } }) =>
70+
createElement(ScheduleDetailsJsonView, {
71+
json: action?.startWorkflow?.memo?.fields ?? null,
72+
}),
73+
hide: ({ formattedScheduleDetails: { action } }) =>
74+
!action?.startWorkflow?.memo?.fields,
7275
},
7376

7477
{
7578
key: 'jitter',
7679
getLabel: () => 'Jitter duration',
77-
getValue: ({ describeSchedule }) =>
78-
formatScheduleDuration(describeSchedule.spec?.jitter),
79-
hide: ({ describeSchedule }) => !describeSchedule.spec?.jitter,
80+
getValue: ({ formattedScheduleDetails: { spec } }) =>
81+
formatScheduleDuration(spec?.jitter),
82+
hide: ({ formattedScheduleDetails: { spec } }) => !spec?.jitter,
8083
},
8184
];
8285

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { getMockRunningDescribeScheduleResponse } from '@/route-handlers/describe-schedule/__fixtures__/mock-describe-schedule-response';
2+
3+
import { formatScheduleDetails } from '../format-schedule-details';
4+
5+
describe(formatScheduleDetails.name, () => {
6+
it('formats workflow input and memo fields in place', () => {
7+
const describeSchedule = getMockRunningDescribeScheduleResponse({
8+
action: {
9+
startWorkflow: {
10+
workflowType: { name: 'ScheduleWorker' },
11+
taskList: {
12+
name: 'schedule-task-list',
13+
kind: 'TASK_LIST_KIND_NORMAL',
14+
baseName: 'schedule-task-list',
15+
},
16+
input: {
17+
data: 'eyJ3b3JrZmxvd0FyZyI6InRlc3QtdmFsdWUifQ==',
18+
},
19+
workflowIdPrefix: 'schedule-prefix',
20+
executionStartToCloseTimeout: null,
21+
taskStartToCloseTimeout: null,
22+
retryPolicy: null,
23+
memo: {
24+
fields: {
25+
owner: { data: 'ImVuZy1sZWFkIg==' },
26+
},
27+
},
28+
searchAttributes: null,
29+
},
30+
},
31+
memo: {
32+
fields: {
33+
team: { data: 'ImNhZGVuY2Ui' },
34+
note: { data: 'dGVzdC1ub3Rl' },
35+
},
36+
},
37+
});
38+
39+
const { memo: _scheduleMemo, ...scheduleWithoutMemo } = describeSchedule;
40+
41+
expect(formatScheduleDetails(describeSchedule)).toEqual({
42+
...scheduleWithoutMemo,
43+
action: {
44+
...describeSchedule.action,
45+
startWorkflow: {
46+
...describeSchedule.action!.startWorkflow!,
47+
input: [{ workflowArg: 'test-value' }],
48+
memo: { fields: { owner: 'eng-lead' } },
49+
},
50+
},
51+
});
52+
});
53+
54+
it('omits root memo when action is absent', () => {
55+
const describeSchedule = getMockRunningDescribeScheduleResponse();
56+
const { memo: _scheduleMemo, ...scheduleWithoutMemo } = describeSchedule;
57+
58+
expect(formatScheduleDetails(describeSchedule)).toEqual({
59+
...scheduleWithoutMemo,
60+
action: null,
61+
});
62+
});
63+
});

src/views/schedule-details/helpers/__tests__/get-rows-from-config.test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getMockRunningDescribeScheduleResponse } from '@/route-handlers/describ
33
import { type DescribeScheduleResponse } from '@/route-handlers/describe-schedule/describe-schedule.types';
44

55
import { type ScheduleDetailRowConfig } from '../../schedule-details.types';
6+
import { formatScheduleDetails } from '../format-schedule-details';
67
import { getRowsFromConfig } from '../get-rows-from-config';
78

89
describe(getRowsFromConfig.name, () => {
@@ -12,6 +13,7 @@ describe(getRowsFromConfig.name, () => {
1213
},
1314
} as Partial<DescribeScheduleResponse>);
1415
const scheduleId = 'my-schedule';
16+
const formattedScheduleDetails = formatScheduleDetails(describeSchedule);
1517

1618
it('maps row config to table rows', () => {
1719
const config: ScheduleDetailRowConfig[] = [
@@ -22,7 +24,9 @@ describe(getRowsFromConfig.name, () => {
2224
},
2325
];
2426

25-
expect(getRowsFromConfig(config, describeSchedule, scheduleId)).toEqual([
27+
expect(
28+
getRowsFromConfig(config, formattedScheduleDetails, scheduleId)
29+
).toEqual([
2630
{ key: 'overlap', label: 'Overlap', value: 'my-schedule-value' },
2731
]);
2832
});
@@ -42,27 +46,24 @@ describe(getRowsFromConfig.name, () => {
4246
},
4347
];
4448

45-
expect(getRowsFromConfig(config, describeSchedule, scheduleId)).toEqual([
46-
{ key: 'visible', label: 'Visible', value: 'shown' },
47-
]);
49+
expect(
50+
getRowsFromConfig(config, formattedScheduleDetails, scheduleId)
51+
).toEqual([{ key: 'visible', label: 'Visible', value: 'shown' }]);
4852
});
4953

50-
it('passes describeSchedule and scheduleId to hide predicate', () => {
54+
it('passes formatted schedule details to hide predicate', () => {
55+
const hide = jest.fn(() => false);
5156
const config: ScheduleDetailRowConfig[] = [
5257
{
5358
key: 'conditional',
5459
getLabel: () => 'Conditional',
5560
getValue: () => 'value',
56-
hide: ({ describeSchedule: data, scheduleId: id }) =>
57-
data.policies?.overlapPolicy !==
58-
ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_BUFFER ||
59-
id !== 'my-schedule',
61+
hide,
6062
},
6163
];
6264

63-
expect(getRowsFromConfig(config, describeSchedule, scheduleId)).toEqual([
64-
{ key: 'conditional', label: 'Conditional', value: 'value' },
65-
]);
66-
expect(getRowsFromConfig(config, describeSchedule, 'other-id')).toEqual([]);
65+
getRowsFromConfig(config, formattedScheduleDetails, scheduleId);
66+
67+
expect(hide).toHaveBeenCalledWith({ formattedScheduleDetails, scheduleId });
6768
});
6869
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import formatInputPayload from '@/utils/data-formatters/format-input-payload';
2+
import formatPayloadMap from '@/utils/data-formatters/format-payload-map';
3+
import { type DescribeScheduleResponse } from '@/views/shared/hooks/use-describe-schedule/use-describe-schedule.types';
4+
5+
import { type FormattedScheduleDetails } from '../schedule-details.types';
6+
7+
export function formatScheduleDetails(
8+
describeSchedule: DescribeScheduleResponse
9+
): FormattedScheduleDetails {
10+
const { memo: _scheduleMemo, action, ...scheduleWithoutMemo } =
11+
describeSchedule;
12+
const startWorkflow = action?.startWorkflow;
13+
14+
return {
15+
...scheduleWithoutMemo,
16+
action: action
17+
? {
18+
...action,
19+
startWorkflow: startWorkflow
20+
? {
21+
...startWorkflow,
22+
input: formatInputPayload(startWorkflow.input),
23+
memo: formatPayloadMap(startWorkflow.memo, 'fields'),
24+
}
25+
: startWorkflow,
26+
}
27+
: action,
28+
} as FormattedScheduleDetails;
29+
}

src/views/schedule-details/helpers/get-rows-from-config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ import { type ScheduleDetailsTableRow } from '@/views/schedule-details/schedule-
22

33
import {
44
type ScheduleDetailRowConfig,
5-
type ScheduleDetailRowArgs,
5+
type FormattedScheduleDetails,
66
} from '../schedule-details.types';
77

88
export function getRowsFromConfig(
99
config: ScheduleDetailRowConfig[],
10-
data: ScheduleDetailRowArgs['describeSchedule'],
10+
formattedScheduleDetails: FormattedScheduleDetails,
1111
scheduleId: string
1212
): ScheduleDetailsTableRow[] {
13-
const args = { describeSchedule: data, scheduleId };
13+
const args = { formattedScheduleDetails, scheduleId };
1414
return config
1515
.filter(
16-
(rowConfig) =>
17-
!rowConfig.hide ||
18-
!rowConfig.hide({ describeSchedule: data, scheduleId })
16+
(rowConfig) => !rowConfig.hide || !rowConfig.hide(args)
1917
)
2018
.map((rowConfig) => ({
2119
key: rowConfig.key,

0 commit comments

Comments
 (0)