New Action List Sort

Created on 5 April 2023, about 2 years ago

Problem/Motivation

This action should sort a list by given parameters like the order:

  • asc
  • desc

We could also include flags here:

SORT_REGULAR - compare items normally; the details are described in the comparison operators section
SORT_NUMERIC - compare items numerically
SORT_STRING - compare items as strings
SORT_LOCALE_STRING - compare items as strings, based on the current locale. It uses the locale, which can be changed using setlocale()
SORT_NATURAL - compare items as strings using "natural ordering" like natsort()

โœจ Feature request
Status

Active

Version

1.2

Component

Code

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany danielspeicher Steisslingen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @danielspeicher
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States luke.leber Pennsylvania

    luke.leber โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States luke.leber Pennsylvania

    I've taken a slightly different stab at this in the issue fork. Rather than providing various flags for the \sort function, the action operates at a slightly higher level by allowing users to pick different sorting functions.

    Jurgen also mentioned in a slack thread...

    I'd like to add that there should also be sorting based on either keys, values, or callbacks. The latter would allow sorting based on properties or other logic when values are complex data types.

    This might be a crazy idea, but I think that this could be feasible by linking to another ECA action that acts to compare two values with arbitrary steps!

    I know that the actual sorting implementation isn't correct -- but it at least allows the kernel tests to pass.

    I'll open a draft PR to get some feedback on this feature request.

    Thanks!

  • Pipeline finished with Failed
    2 months ago
    Total: 463s
    #458937
  • Pipeline finished with Success
    2 months ago
    Total: 569s
    #458990
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States luke.leber Pennsylvania

    Added some example model configuration files to aid in review.

    I'll mark as NR for the concept check anyhow.

  • Pipeline finished with Success
    2 months ago
    Total: 586s
    #459020
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States luke.leber Pennsylvania

    Clean up I.S.

  • Pipeline finished with Success
    2 months ago
    Total: 767s
    #459054
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    This looks great, thanks @luke.leber for your contribution. Just a minor suggestion in the MR, everything else is ready to be merged.

  • Pipeline finished with Canceled
    about 2 months ago
    Total: 445s
    #476064
  • Pipeline finished with Failed
    about 2 months ago
    Total: 492s
    #476067
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 85s
    #476073
  • Pipeline finished with Success
    about 2 months ago
    Total: 483s
    #476074
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States luke.leber Pennsylvania

    I gave this a manual test (via the attached model) and everything still seems to be in order. Switching back to NR - thanks Jรผrgen!

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Istari
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Istari

    I tested it and idk if documentation about my testing is a little too much :)
    Feel free to feedback

    Testing Results:

    - Tested with new Drupal 11.1.6
    - ECA 2.1.x
    - BPMN_IO 2.0

    Test scenario:

    = Triggering event:
    - Update Content entity, Type: Content Article
    - Building a list with 4 values in random order
    - Build up list with names
    (Order of List: add item actions, method: append)
    - Daniel
    - Clara
    - Anna
    - Ben

    Executing test with creating and updating new Node of type Article

    Testing created list

    :
    Expected result
    Daniel,Clara,Anna,Ben

    Result:(Type in logs: testing)
    Daniel, Clara, Anna, Ben

    Sort method: Ascending by value

    Expected result
    Anna, Ben, Clara, Daniel

    Result: (Type in logs: test_asc)
    Anna, Ben, Clara, Daniel

    Sort method: Descending by value

    Expected result
    Daniel, Clara, Ben, Anna

    Result: (Type in logs: test_desc)
    Daniel, Clara, Ben, Anna

    Sort method: Ascending by key

    Expected result
    Daniel, Clara, Anna, Ben

    Result: (Type in logs: test_asc_k)
    Daniel, Clara, Anna, Ben

    Sort method: Descending by key

    Expected result
    Ben, Anna, Clara, Daniel

    Result: (Type in logs: test_dsc_k)
    Ben, Anna, Clara, Daniel

    Sort method: natural

    Expected result (Type in logs: test_nat)
    Anna, Ben, Clara, Daniel

    Result:
    Anna, Ben, Clara, Daniel

    - Building a list with 4 values in random order
    - Build up list with letters
    (Order of List: add item actions, method: append)
    - A
    - B
    - b
    - a

    Testing created list

    :
    Expected result
    a,A,b,B

    Result: (Type in logs: testing)
    Daniel, Clara, Ben, Anna, A, B, b, a

    Sort method: natural case sensitive

    Expected result
    A,a,B,b

    Result: (Type in logs: test_nat_cs)
    A,a,Anna,B,b,Ben,Clara,Daniel

    Results:

    All results as expected
    Except natural case sensitive where I expected not to have any values of the first list.
    Both lists are separated by a gateway (see screenshot) and no tokens from list one are in the list two process contained

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Istari
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    @mysdiir regarding tests, as discussed in Leuven, I've looked for some existing tests that could be used as examples for how the tests should be written for this issue. The best example is modules/base/tests/src/Kernel/ListOperationTest.php with tests called \Drupal\Tests\eca_base\Kernel\ListOperationTest::testListCount, etc.

    You can copy that file into ListSortTest.php and then remove the test methods before adding your own test methods that initialize the action plugin with the configuration that you wrote about in #12, then execute the action and afterwards assert the result being what you expect.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    Updated so that this works against the 3.0.x branch.

  • Pipeline finished with Success
    29 days ago
    Total: 483s
    #489342
Production build 0.71.5 2024