This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 7f3200276 feat(config-ui): improve the ux of the sync frequency
setting (#5656)
7f3200276 is described below
commit 7f3200276bb8ba17a9b85564673fe87745b51c1b
Author: 青湛 <[email protected]>
AuthorDate: Tue Jul 18 02:20:41 2023 +1200
feat(config-ui): improve the ux of the sync frequency setting (#5656)
* feat(config-ui): support style props in form-item component
* feat(config-ui): improve the ux of the sync frequency setting
---
config-ui/src/components/form/item/index.tsx | 4 +-
config-ui/src/config/cron.ts | 14 +++
.../detail/components/sync-policy/index.tsx | 117 +++++++++++++++------
.../components/sync-policy/start-from-selector.tsx | 92 ----------------
.../detail/components/sync-policy/styled.ts | 44 ++++----
.../components/update-policy-dialog/index.tsx | 4 +-
6 files changed, 129 insertions(+), 146 deletions(-)
diff --git a/config-ui/src/components/form/item/index.tsx
b/config-ui/src/components/form/item/index.tsx
index 0ee800c6d..89c64fee4 100644
--- a/config-ui/src/components/form/item/index.tsx
+++ b/config-ui/src/components/form/item/index.tsx
@@ -21,15 +21,17 @@ import { FormGroup } from '@blueprintjs/core';
import * as S from './styled';
interface Props {
+ style?: React.CSSProperties;
label?: React.ReactNode;
subLabel?: React.ReactNode;
required?: boolean;
children: React.ReactNode;
}
-export const FormItem = ({ label, subLabel, required, children }: Props) => {
+export const FormItem = ({ style, label, subLabel, required, children }:
Props) => {
return (
<FormGroup
+ style={style}
label={<S.Label>{label}</S.Label>}
subLabel={<S.subLabel>{subLabel}</S.subLabel>}
labelInfo={required ? <S.LabelInfo>*</S.LabelInfo> : null}
diff --git a/config-ui/src/config/cron.ts b/config-ui/src/config/cron.ts
index fed86dbdb..529e6e7cd 100644
--- a/config-ui/src/config/cron.ts
+++ b/config-ui/src/config/cron.ts
@@ -44,6 +44,17 @@ const getNextTime = (config: string) => {
}
};
+const getNextTimes = (config: string) => {
+ try {
+ return parser
+ .parseExpression(config, { tz: 'utc' })
+ .iterate(3)
+ .map((date) => date.toString());
+ } catch {
+ return [];
+ }
+};
+
export const getCron = (isManual: boolean, config: string) => {
if (isManual) {
return {
@@ -52,6 +63,7 @@ export const getCron = (isManual: boolean, config: string) =>
{
description: '',
config: '',
nextTime: '',
+ nextTimes: [],
};
}
@@ -62,6 +74,7 @@ export const getCron = (isManual: boolean, config: string) =>
{
...preset,
value: preset.config,
nextTime: getNextTime(preset.config),
+ nextTimes: getNextTimes(preset.config),
}
: {
label: 'Custom',
@@ -69,6 +82,7 @@ export const getCron = (isManual: boolean, config: string) =>
{
description: 'Custom',
config,
nextTime: getNextTime(config),
+ nextTimes: getNextTimes(config),
};
};
diff --git
a/config-ui/src/pages/blueprint/detail/components/sync-policy/index.tsx
b/config-ui/src/pages/blueprint/detail/components/sync-policy/index.tsx
index 1586e321c..819a065e0 100644
--- a/config-ui/src/pages/blueprint/detail/components/sync-policy/index.tsx
+++ b/config-ui/src/pages/blueprint/detail/components/sync-policy/index.tsx
@@ -18,11 +18,14 @@
import { useMemo } from 'react';
import dayjs from 'dayjs';
-import { Checkbox, FormGroup, InputGroup, Radio, RadioGroup } from
'@blueprintjs/core';
+import { Tag, Checkbox, FormGroup, InputGroup, Radio, RadioGroup } from
'@blueprintjs/core';
+import { TimePrecision } from '@blueprintjs/datetime';
+import { DateInput2 } from '@blueprintjs/datetime2';
+import { FormItem, ExternalLink } from '@/components';
import { getCron, getCronOptions } from '@/config';
+import { formatTime } from '@/utils';
-import StartFromSelector from './start-from-selector';
import * as S from './styled';
interface Props {
@@ -48,10 +51,23 @@ export const SyncPolicy = ({
onChangeSkipOnFail,
onChangeTimeAfter,
}: Props) => {
- const [mintue, hour, day, month, week] = useMemo(() => cronConfig.split('
'), [cronConfig]);
+ const [timezone, quickTimeOpts, cronOpts] = useMemo(() => {
+ const timezone = dayjs().format('ZZ').replace('00', '');
+ const quickTimeOpts = [
+ { label: 'Last 6 months', date: dayjs().subtract(6, 'month').toDate() },
+ { label: 'Last 90 days', date: dayjs().subtract(90, 'day').toDate() },
+ { label: 'Last 30 days', date: dayjs().subtract(30, 'day').toDate() },
+ { label: 'Last Year', date: dayjs().subtract(1, 'year').toDate() },
+ ];
+
+ const cronOpts = getCronOptions();
+
+ return [timezone, quickTimeOpts, cronOpts];
+ }, []);
+
const cron = useMemo(() => getCron(isManual, cronConfig), [isManual,
cronConfig]);
- const options = useMemo(() => getCronOptions(), []);
+ const [mintue, hour, day, month, week] = useMemo(() => cronConfig.split('
'), [cronConfig]);
const handleChangeFrequency = (e: React.FormEvent<HTMLInputElement>) => {
const value = (e.target as HTMLInputElement).value;
@@ -68,21 +84,51 @@ export const SyncPolicy = ({
return (
<S.Wrapper>
+ <div className="timezone">
+ Your local time zone is <strong>UTC {timezone}</strong>. All time
listed below is shown in your local time.
+ </div>
{showTimeFilter && (
- <div className="block">
- <h3>Time Filter *</h3>
- <p>Select the data range you wish to collect. This filter applies to
all data sources except SonarQube.</p>
- <StartFromSelector value={timeAfter} onChange={onChangeTimeAfter} />
- </div>
+ <FormItem
+ label="Time Range"
+ subLabel="Select the time range for the data you wish to collect.
DevLake will collect the last six months of data by default."
+ >
+ <div className="quick-selection">
+ {quickTimeOpts.map((opt, i) => (
+ <Tag
+ key={i}
+ style={{ marginRight: 5, cursor: 'pointer' }}
+ minimal={formatTime(opt.date) !== formatTime(timeAfter)}
+ intent="primary"
+ onClick={() =>
onChangeTimeAfter(dayjs(opt.date).utc().format('YYYY-MM-DD[T]HH:mm:ssZ'))}
+ >
+ {opt.label}
+ </Tag>
+ ))}
+ </div>
+
+ <div className="time-selection">
+ <DateInput2
+ timePrecision={TimePrecision.MINUTE}
+ showTimezoneSelect={false}
+ formatDate={formatTime}
+ parseDate={(str: string) => new Date(str)}
+ placeholder="Select start from"
+ popoverProps={{ placement: 'bottom' }}
+ value={timeAfter}
+ onChange={(date) => onChangeTimeAfter(date ?
dayjs(date).utc().format('YYYY-MM-DD[T]HH:mm:ssZ') : null)}
+ />
+ <strong>to Now</strong>
+ </div>
+ </FormItem>
)}
- <div className="block" style={{ display: 'flex' }}>
- <div className="left" style={{ flex: '0 0 400px', marginRight: 100 }}>
- <h3>Frequency</h3>
- <p>
- Blueprints will run on creation and recurringly based on the
schedule. The time shown is your LOCAL time.
- </p>
+ <div className="cron">
+ <FormItem
+ style={{ flex: '0 0 400px', marginRight: 50 }}
+ label="Sync Frequency"
+ subLabel="Blueprints will run on creation and recurringly based on
the schedule."
+ >
<RadioGroup selectedValue={cron.value}
onChange={handleChangeFrequency}>
- {options.map(({ value, label, subLabel }) => (
+ {cronOpts.map(({ value, label, subLabel }) => (
<Radio key={value} label={`${label} ${subLabel}`} value={value}
/>
))}
</RadioGroup>
@@ -123,26 +169,37 @@ export const SyncPolicy = ({
{!cron.nextTime && <S.Error>Invalid Cron code, please enter
again.</S.Error>}
</>
)}
- </div>
- <div className="right">
- <h3>Next Run Time:</h3>
- <h4>{cron.nextTime ? dayjs(cron.nextTime).format('YYYY-MM-DD HH:mm
A') : 'N/A'}</h4>
- </div>
+ <ExternalLink style={{ display: 'block', marginTop: 16 }}
link="https://crontab.cronhub.io/">
+ Learn about how to use cron code
+ </ExternalLink>
+ </FormItem>
+ <FormItem label="Next Three Runs:">
+ {cron.nextTimes.length ? (
+ <ul>
+ {cron.nextTimes.map((it, i) => (
+ <li key={i}>
+ {dayjs(it).format('YYYY-MM-DD HH:mm
A')}({dayjs(it).fromNow()})
+ </li>
+ ))}
+ </ul>
+ ) : (
+ 'N/A'
+ )}
+ </FormItem>
</div>
- <div className="block">
- <h3>Running Policy</h3>
+ <FormItem label="Running Policy">
<Checkbox
- label="Skip failed tasks (Recommended when collecting large volume
of data, eg. 10+ GitHub repos/Jira boards)"
+ label="Skip failed tasks (Recommended when collecting a large volume
of data, eg. 10+ GitHub repos, Jira boards, etc.)"
checked={skipOnFail}
onChange={(e) => onChangeSkipOnFail((e.target as
HTMLInputElement).checked)}
/>
- <p>
- A task is a unit of a pipeline. A pipeline is an execution of a
blueprint. By default, when a task is failed,
- the whole pipeline will fail and all the data that has been
collected will be discarded. By skipping failed
- tasks, the pipeline will continue to run, and the data collected by
other tasks will not be affected. After
- the pipeline is finished, you can rerun these failed tasks.
+ <p style={{ paddingLeft: 28 }}>
+ A task is a unit of a pipeline, an execution of a blueprint. By
default, when a task is failed, the whole
+ pipeline will fail and all the data that has been collected will be
discarded. By skipping failed tasks, the
+ pipeline will continue to run, and the data collected by successful
tasks will not be affected. After the
+ pipeline is finished, you can rerun these failed tasks.
</p>
- </div>
+ </FormItem>
</S.Wrapper>
);
};
diff --git
a/config-ui/src/pages/blueprint/detail/components/sync-policy/start-from-selector.tsx
b/config-ui/src/pages/blueprint/detail/components/sync-policy/start-from-selector.tsx
deleted file mode 100644
index fbf25efa8..000000000
---
a/config-ui/src/pages/blueprint/detail/components/sync-policy/start-from-selector.tsx
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); 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.
- *
- */
-import { useCallback, useMemo } from 'react';
-import { Tag } from '@blueprintjs/core';
-import { TimePrecision } from '@blueprintjs/datetime';
-import { DateInput2 } from '@blueprintjs/datetime2';
-
-import { formatTime } from '@/utils';
-
-import * as S from './styled';
-
-interface Props {
- value: string | null;
- onChange: (val: string | null) => void;
-}
-
-const StartFromSelector = ({ value, onChange }: Props) => {
- const formatDate = useCallback((date: Date) => formatTime(date), []);
- const parseDate = useCallback((str: string) => new Date(str), []);
-
- const quickDates = useMemo(() => {
- const now = new Date();
- now.setHours(0, 0, 0, 0);
- const ago6m = new Date(now);
- ago6m.setMonth(now.getMonth() - 6);
- const ago90d = new Date(now);
- ago90d.setDate(ago90d.getDate() - 90);
- const ago30d = new Date(now);
- ago30d.setDate(ago30d.getDate() - 30);
- const ago1y = new Date(now);
- ago1y.setUTCFullYear(ago1y.getFullYear() - 1);
-
- return [
- { label: 'Last 6 months', date: ago6m },
- { label: 'Last 90 days', date: ago90d },
- { label: 'Last 30 days', date: ago30d },
- { label: 'Last Year', date: ago1y },
- ];
- }, []);
-
- const handleChangeDate = (val: string | Date | null) => {
- onChange(val ? formatTime(val, 'YYYY-MM-DD[T]HH:mm:ssZ') : null);
- };
-
- return (
- <S.FromTimeWrapper>
- <div className="quick-selection">
- {quickDates.map((quickDate) => (
- <Tag
- key={quickDate.date.toISOString()}
- minimal={formatDate(quickDate.date) !== formatTime(value)}
- intent="primary"
- onClick={() => handleChangeDate(quickDate.date)}
- style={{ marginRight: 5 }}
- >
- {quickDate.label}
- </Tag>
- ))}
- </div>
-
- <div className="time-selection">
- <DateInput2
- timePrecision={TimePrecision.MINUTE}
- formatDate={formatDate}
- parseDate={parseDate}
- placeholder="Select start from"
- popoverProps={{ placement: 'bottom' }}
- value={value}
- onChange={handleChangeDate}
- />{' '}
- <strong>to Now</strong>
- </div>
- </S.FromTimeWrapper>
- );
-};
-
-export default StartFromSelector;
diff --git
a/config-ui/src/pages/blueprint/detail/components/sync-policy/styled.ts
b/config-ui/src/pages/blueprint/detail/components/sync-policy/styled.ts
index 41c3b55f3..a2f1e3327 100644
--- a/config-ui/src/pages/blueprint/detail/components/sync-policy/styled.ts
+++ b/config-ui/src/pages/blueprint/detail/components/sync-policy/styled.ts
@@ -19,8 +19,25 @@
import styled from 'styled-components';
export const Wrapper = styled.div`
- .block + .block {
- margin-top: 24px;
+ .timezone {
+ margin-bottom: 16px;
+ }
+
+ .quick-selection {
+ margin-bottom: 8px;
+ }
+
+ .time-selection {
+ display: flex;
+ align-items: center;
+
+ strong {
+ margin-left: 8px;
+ }
+ }
+
+ .cron {
+ display: flex;
}
`;
@@ -28,6 +45,10 @@ export const Input = styled.div`
display: flex;
align-items: center;
+ .bp4-form-group {
+ margin-bottom: 4px;
+ }
+
.bp4-form-group + .bp4-form-group {
margin-left: 8px;
}
@@ -40,22 +61,3 @@ export const Input = styled.div`
export const Error = styled.div`
color: #e34040;
`;
-
-export const FromTimeWrapper = styled.div`
- .quick-selection {
- margin-bottom: 16px;
-
- & > .bp4-tag {
- cursor: pointer;
- }
- }
-
- .time-selection {
- display: flex;
- align-items: center;
-
- & > strong {
- margin-left: 4px;
- }
- }
-`;
diff --git
a/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
b/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
index c70118c9e..d694ad3f5 100644
---
a/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
+++
b/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
@@ -67,9 +67,9 @@ export const UpdatePolicyDialog = ({ blueprint, operating,
onCancel, onSubmit, .
return (
<Dialog
isOpen
- title="Change Sync Policy"
+ title="Set Sync Policy"
style={{
- width: 720,
+ width: 820,
}}
okText="Save"
okLoading={operating}