fix(plugin-workflow): fix date range variables (#5954)

* feat: hidden date range variables from nodes which is not filter components

* feat: remove system daterange variables from plugin

* refactor(plugin-workflow): move date range variables to component

* fix(plugin-workflow): remove useless code

---------

Co-authored-by: Linda <huanghui9850@gmail.com>
This commit is contained in:
Junyi 2024-12-26 23:42:38 +08:00 committed by GitHub
parent b8618e4c92
commit c7831676af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 123 additions and 115 deletions

View File

@ -58,6 +58,7 @@ export function AssignedFieldsFormSchemaConfig(props) {
const { setFormValueChanged } = useActionContext(); const { setFormValueChanged } = useActionContext();
const api = useAPIClient(); const api = useAPIClient();
const scope = useWorkflowVariableOptions(); const scope = useWorkflowVariableOptions();
const { values, setValuesIn, disabled } = useForm(); const { values, setValuesIn, disabled } = useForm();
const params = toJS(values.params); const params = toJS(values.params);
const [dataSourceName, collectionName] = parseCollectionName(values.collection); const [dataSourceName, collectionName] = parseCollectionName(values.collection);

View File

@ -9,13 +9,131 @@
import React from 'react'; import React from 'react';
import { Variable } from '@nocobase/client'; import { useCompile, Variable } from '@nocobase/client';
import type { DefaultOptionType } from 'antd/lib/cascader';
import { useWorkflowVariableOptions } from '../variable'; import { useWorkflowVariableOptions } from '../variable';
import { NAMESPACE } from '../locale';
const dateRangeSystemVariables = {
key: 'dateRange',
label: `{{t('Date range', { ns: '${NAMESPACE}' })}}`,
value: 'dateRange',
children: [
{
key: 'yesterday',
value: 'yesterday',
label: '{{t("Yesterday")}}',
},
{
key: 'today',
value: 'today',
label: '{{t("Today")}}',
},
{
key: 'tomorrow',
value: 'tomorrow',
label: '{{t("Tomorrow")}}',
},
{
key: 'lastWeek',
value: 'lastWeek',
label: '{{t("Last week")}}',
},
{
key: 'thisWeek',
value: 'thisWeek',
label: '{{t("This week")}}',
},
{
key: 'nextWeek',
value: 'nextWeek',
label: '{{t("Next week")}}',
},
{
key: 'lastMonth',
value: 'lastMonth',
label: '{{t("Last month")}}',
},
{
key: 'thisMonth',
value: 'thisMonth',
label: '{{t("This month")}}',
},
{
key: 'nextMonth',
value: 'nextMonth',
label: '{{t("Next month")}}',
},
{
key: 'lastQuarter',
value: 'lastQuarter',
label: '{{t("Last quarter")}}',
},
{
key: 'thisQuarter',
value: 'thisQuarter',
label: '{{t("This quarter")}}',
},
{
key: 'nextQuarter',
value: 'nextQuarter',
label: '{{t("Next quarter")}}',
},
{
key: 'lastYear',
value: 'lastYear',
label: '{{t("Last year")}}',
},
{
key: 'thisYear',
value: 'thisYear',
label: '{{t("This year")}}',
},
{
key: 'nextYear',
value: 'nextYear',
label: '{{t("Next year")}}',
},
{
key: 'last7Days',
value: 'last7Days',
label: '{{t("Last 7 days")}}',
},
{
key: 'next7Days',
value: 'next7Days',
label: '{{t("Next 7 days")}}',
},
{
key: 'last30Days',
value: 'last30Days',
label: '{{t("Last 30 days")}}',
},
{
key: 'next30Days',
value: 'next30Days',
label: '{{t("Next 30 days")}}',
},
{
key: 'last90Days',
value: 'last90Days',
label: '{{t("Last 90 days")}}',
},
{
key: 'next90Days',
value: 'next90Days',
label: '{{t("Next 90 days")}}',
},
],
};
export function FilterDynamicComponent({ value, onChange, renderSchemaComponent }) { export function FilterDynamicComponent({ value, onChange, renderSchemaComponent }) {
const scope = useWorkflowVariableOptions(); const compile = useCompile();
const scope: Partial<DefaultOptionType>[] | (() => Partial<DefaultOptionType>[]) = useWorkflowVariableOptions();
const index = scope.findIndex((v) => v.key === '$system');
scope[index].children.push(compile(dateRangeSystemVariables));
return ( return (
<Variable.Input value={value} onChange={onChange} scope={scope}> <Variable.Input value={value} onChange={onChange} scope={scope}>
{renderSchemaComponent()} {renderSchemaComponent()}

View File

@ -18,7 +18,8 @@ import {
LoadingOutlined, LoadingOutlined,
RedoOutlined, RedoOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { NAMESPACE } from './locale'; import { i18n } from '@nocobase/client';
import { NAMESPACE, lang } from './locale';
export const EXECUTION_STATUS = { export const EXECUTION_STATUS = {
QUEUEING: null, QUEUEING: null,

View File

@ -126,118 +126,6 @@ export default class PluginWorkflowClient extends Plugin {
label: `{{t("System time", { ns: "${NAMESPACE}" })}}`, label: `{{t("System time", { ns: "${NAMESPACE}" })}}`,
value: 'now', value: 'now',
}); });
this.registerSystemVariable({
key: 'dateRange',
label: `{{t("Date range", { ns: "${NAMESPACE}" })}}`,
value: 'dateRange',
children: [
{
key: 'yesterday',
value: 'yesterday',
label: `{{t("Yesterday")}}`,
},
{
key: 'today',
value: 'today',
label: `{{t("Today")}}`,
},
{
key: 'tomorrow',
value: 'tomorrow',
label: `{{t("Tomorrow")}}`,
},
{
key: 'lastWeek',
value: 'lastWeek',
label: `{{t("Last week")}}`,
},
{
key: 'thisWeek',
value: 'thisWeek',
label: `{{t("This week")}}`,
},
{
key: 'nextWeek',
value: 'nextWeek',
label: `{{t("Next week")}}`,
},
{
key: 'lastMonth',
value: 'lastMonth',
label: `{{t("Last month")}}`,
},
{
key: 'thisMonth',
value: 'thisMonth',
label: `{{t("This month")}}`,
},
{
key: 'nextMonth',
value: 'nextMonth',
label: `{{t("Next month")}}`,
},
{
key: 'lastQuarter',
value: 'lastQuarter',
label: `{{t("Last quarter")}}`,
},
{
key: 'thisQuarter',
value: 'thisQuarter',
label: `{{t("This quarter")}}`,
},
{
key: 'nextQuarter',
value: 'nextQuarter',
label: `{{t("Next quarter")}}`,
},
{
key: 'lastYear',
value: 'lastYear',
label: `{{t("Last year")}}`,
},
{
key: 'thisYear',
value: 'thisYear',
label: `{{t("This year")}}`,
},
{
key: 'nextYear',
value: 'nextYear',
label: `{{t("Next year")}}`,
},
{
key: 'last7Days',
value: 'last7Days',
label: `{{t("Last 7 days")}}`,
},
{
key: 'next7Days',
value: 'next7Days',
label: `{{t("Next 7 days")}}`,
},
{
key: 'last30Days',
value: 'last30Days',
label: `{{t("Last 30 days")}}`,
},
{
key: 'next30Days',
value: 'next30Days',
label: `{{t("Next 30 days")}}`,
},
{
key: 'last90Days',
value: 'last90Days',
label: `{{t("Last 90 days")}}`,
},
{
key: 'next90Days',
value: 'next90Days',
label: `{{t("Next 90 days")}}`,
},
],
});
} }
} }