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(plugin-workflow): add date range options to system variables #4728

Merged
merged 10 commits into from
Jun 30, 2024

Conversation

huanghui1
Copy link

@huanghui1 huanghui1 commented Jun 22, 2024

Description

Add date range options to system variables in workflow context.

Motivation

Date range variables in data block filter is convenient to use. It will also be useful in workflow nodes.

Key changes

  • Frontend
  • Backend

Test plan

Suggestions

Through test cases.

Underlying risk

Date range variables can not be used for operators other than "is".

Showcase

image

@CLAassistant
Copy link

CLAassistant commented Jun 22, 2024

CLA assistant check
All committers have signed the CLA.

@mytharcher mytharcher marked this pull request as draft June 22, 2024 06:25
@mytharcher mytharcher self-requested a review June 22, 2024 06:25
Copy link
Contributor

@mytharcher mytharcher left a comment

Choose a reason for hiding this comment

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

还需要增加相关的单元测试,例如:

    it('params.filter on date range: yesterday', async () => {
      const n1 = await workflow.createNode({
        type: 'query',
        config: {
          collection: 'posts',
          params: {
            filter: {
              createdAt: {
                $dateOn: '{{$system.dateRange.yesterday}}',
              },
            },
          },
        },
      });

      const now = new Date();
      const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);

      const post = await PostRepo.create({
        values: {
          title: 't1',
          createdAt: yesterday
        },
      });

      await sleep(500);

      const [execution] = await workflow.getExecutions();
      const [job] = await execution.getJobs();
      expect(job.result.title).toBe(post.title);
    });

不一定套在 query 节点里,只要能测试 Processor.getParsedValue 或者 Processor.getScope 的解析结果正确,且可以作为 filter 参数交给 repository.find 方法查询出正确的结果即可(时间边界范围需要覆盖)。

可以考虑单独针对 functions 开一个单测文件。

@mytharcher mytharcher changed the title feat(plugin-workflow): add date range options to system variable in workflow plugin feat(plugin-workflow): add date range options to system variables Jun 23, 2024
Copy link
Contributor

@mytharcher mytharcher left a comment

Choose a reason for hiding this comment

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

核心问题是测试用例的写法需要简化,可以参考这条评论:

可以直接使用 parse 后的内容对某个 repository 的 findAll 进行测试,会简化很多。

时间值的设置需要考虑临界点,更有针对性。

@mytharcher mytharcher marked this pull request as ready for review June 29, 2024 13:28
@mytharcher mytharcher self-requested a review June 30, 2024 08:22
@mytharcher mytharcher changed the base branch from main to next June 30, 2024 08:30
@mytharcher mytharcher merged commit 512557f into nocobase:next Jun 30, 2024
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants