tachybase_todo/packages/plugins/@nocobase/plugin-workflow-delay/src/client/DelayInstruction.tsx
Junyi 0e7cb9e5cf
refactor(plugin-workflow): split workflow features into plugins (#3115)
* refactor(plugin-workflow): split manual and dynamic calculation into plugins

* refactor(plugin-workflow): move loop to plugin

* refactor(plugin-workflow): move parallel to plugin

* fix(plugin-dynamic-calculation): fix package title

* fix(plugin-workflow): fix plugin name

* refactor(plugin-workflow): move delay to plugin

* refactor(plugin-workflow): simplify exporting names

* refactor(plugin-workflow): move aggregate to plugin

* refactor(plugin-workflow): move sql to plugin

* refactor(plugin-workflow): move reqeust to plugin

* refactor(plugin-workflow): move form trigger to plugin

* refactor(plugin-workflow): move locale to plugins

* fix(plugin-workflow): fix test cases

* fix(plugin-workflow-request): package name typo

* fix(plugin-workflow): remove clean db from testkit

* fix(plugin-workflow-sql): skip independent case

* fix(plugin-workflow-sql): skip independent case

* fix(plugin-workflow-delay): fix test cases

* test(plugin-workflow-delay): fix test cases

* test(plugin-workflow-delay): fix test cases

* test(plugin-workflow-delay): fix test cases

* test(plugin-workflow-delay): fix test cases

* fix(plugin-workflow): fix migration version matching

* test(plugin-workflow): fix test case

* refactor(plugin-workflow): correct exporting of testkit

* fix(plugin-workflow): fix testkit and require module

* refactor(plugin-workflow): add workflow-test package for testing

* test(plugin-workflow): test weird case

* fix(plugin-workflow-test): remove workflow dependency to avoid cycling

* fix(plugin-workflow): fix migration version

* fix(plugin-workflow): fix migration and packages

* fix(plugin-workflow): fix package dependencies

* fix(preset): fix builtin list in preset

* fix(plugin-workflow): add package entry file

* fix(plugin-workflow): fix migrations

* refactor(plugin-workflow): remove require

* fix(plugin-workflow): fix locale namespace

* fix(plugin-workflow): fix merged errors

* fix(plugin-workflow): fix import cycling references

* refactor(plugin-workflow): change instruction and triggers to classes in client

* fix(plugin-workflow): fix migration version
2023-12-07 05:46:58 -08:00

88 lines
2.6 KiB
TypeScript

import React from 'react';
import { InputNumber, Select } from 'antd';
import { css, useCompile } from '@nocobase/client';
import { Instruction, JOB_STATUS } from '@nocobase/plugin-workflow/client';
import { NAMESPACE } from '../locale';
const UnitOptions = [
{ value: 1_000, label: `{{t('Seconds', { ns: "workflow" })}}` },
{ value: 60_000, label: `{{t('Minutes', { ns: "workflow" })}}` },
{ value: 3600_000, label: `{{t('Hours', { ns: "workflow" })}}` },
{ value: 86400_000, label: `{{t('Days', { ns: "workflow" })}}` },
{ value: 604800_000, label: `{{t('Weeks', { ns: "workflow" })}}` },
];
function getNumberOption(v) {
return UnitOptions.slice()
.reverse()
.find((item) => !(v % item.value));
}
function Duration({ value = 60000, onChange }) {
const compile = useCompile();
const option = getNumberOption(value);
const quantity = Math.round(value / option.value);
return (
<fieldset
className={css`
display: flex;
gap: 0.5em;
`}
>
<InputNumber
min={1}
value={quantity}
onChange={(v) => onChange(Math.round(v * option.value))}
className="auto-width"
/>
<Select
// @ts-ignore
role="button"
data-testid="select-time-unit"
popupMatchSelectWidth={false}
value={option.value}
onChange={(unit) => onChange(Math.round(quantity * unit))}
className="auto-width"
options={UnitOptions.map((item) => ({
value: item.value,
label: compile(item.label),
}))}
/>
</fieldset>
);
}
export default class extends Instruction {
title = `{{t("Delay", { ns: "${NAMESPACE}" })}}`;
type = 'delay';
group = 'control';
description = `{{t("Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.", { ns: "${NAMESPACE}" })}}`;
fieldset = {
duration: {
type: 'number',
title: `{{t("Duration", { ns: "${NAMESPACE}" })}}`,
'x-decorator': 'FormItem',
'x-component': 'Duration',
default: 60000,
required: true,
},
endStatus: {
type: 'number',
title: `{{t("End Status", { ns: "${NAMESPACE}" })}}`,
'x-decorator': 'FormItem',
'x-component': 'Radio.Group',
enum: [
{ label: `{{t("Succeed and continue", { ns: "${NAMESPACE}" })}}`, value: JOB_STATUS.RESOLVED },
{ label: `{{t("Fail and exit", { ns: "${NAMESPACE}" })}}`, value: JOB_STATUS.FAILED },
],
required: true,
default: JOB_STATUS.RESOLVED,
},
};
components = {
Duration,
};
}