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: add groups for assets #306

Merged
merged 17 commits into from
Jul 17, 2023
Merged

feat: add groups for assets #306

merged 17 commits into from
Jul 17, 2023

Conversation

sebtiz13
Copy link
Member

@sebtiz13 sebtiz13 commented Jun 1, 2023

Depend to #307

What does this PR do ?

This PR implement groups for assets.
The groups can have sub groups and groups can have many assets, but assets can only belong to one group.

How should this be manually tested?

// TODO

  • Step 1 :
  • Step 2 :
  • Step 3 :

Boyscout

Add @types/lodash in devDependencies to get autocomplete and correct type on lodash functions

@sebtiz13 sebtiz13 self-assigned this Jun 1, 2023
@sebtiz13 sebtiz13 force-pushed the feat/assets-groups branch 8 times, most recently from e943ed6 to 1126661 Compare June 2, 2023 15:19
@sebtiz13 sebtiz13 marked this pull request as ready for review June 12, 2023 10:11
Copy link
Contributor

@Aschen Aschen left a comment

Choose a reason for hiding this comment

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

😘

lib/modules/asset/AssetModule.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/types/AssetGroupContent.ts Show resolved Hide resolved
lib/modules/plugin/DeviceManagerEngine.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,34 @@
import { AssetsGroupsBody } from "../../lib/modules/asset/types/AssetGroupContent";

export const assetGroupTestId = "test-group";
Copy link
Contributor

Choose a reason for hiding this comment

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

It's really nitpicking but IMHO the example would be more explicit with "real" hierarchic groups like Occitanie, Montpellier, Ecusson, Rue des écoles Pies

@sebtiz13 sebtiz13 force-pushed the feat/assets-groups branch 6 times, most recently from 19c03d9 to 5c4d928 Compare June 14, 2023 21:32
@tdislay
Copy link
Contributor

tdislay commented Jun 15, 2023

It's hard to review force pushed code. It means re-reading everything, and not just the newly added code

@sebtiz13
Copy link
Member Author

It's hard to review force pushed code. It means re-reading everything, and not just the newly added code

Ok it's noted, now I rebase only when the review is finished

@Aschen
Copy link
Contributor

Aschen commented Jun 15, 2023

Also the documentation is missing, here is some ideas of things to do:

lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
Comment on lines 187 to 207
query: {
bool: {
must: [
{
regexp: {
name: {
case_insensitive: true,
value: body.name,
},
},
},
],
must_not: [
{
terms: {
_id: typeof assetId === "string" ? [assetId] : [],
},
},
],
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using koncorde syntax ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't manage to use regexp in case-insensitive mode in Koncorde, the flag i like it's explain in documentation throw an error and like I haven't the time to search more at the moment I have preferred to use Elasticsearch syntax that works correctly.

But it's true, maybe we need to refactor that later

Copy link
Contributor

Choose a reason for hiding this comment

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

I dug a little bit and found, that atm, regexp is not usable in search queries. Because it's not translated from Koncorde DSL to ES DSL (Idk why).

So if we don't implement it (because there are maybe good reasons 🤷), you can either add a comment to explain why we use a ES query, or I also suggest to use the regexp syntax from ES (yes, therefore you can mix koncorde & es lol):

query: {
  and: [
    {
      regexp: {
        name: {
          case_insensitive: true,
          value: body.name,
        },
      },
    },
    {
      not: {
        "equals": { _id: typeof assetId === "string" ? [assetId] : [] }
      }
    }
  ],
},

Copy link
Contributor

Choose a reason for hiding this comment

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

Koncorde regex and ES regex does not have the same syntax that's why

Copy link
Contributor

Choose a reason for hiding this comment

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

Koncorde regex and ES regex does not have the same syntax that's why. We could allow the keyword though but it would be confusing since the filter will have ES syntax in Koncorde DSL

Copy link
Contributor

@tdislay tdislay Jul 5, 2023

Choose a reason for hiding this comment

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

I don't understand. Actually the keyword is allowed when searching for documents, via Koncorde.
The query above is working (although it may return an error 🤷)

Copy link
Contributor

Choose a reason for hiding this comment

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

Koncorde requests are supposed to be used indifferently in realtime filters and in search queries but if you use a regex then it cannot works in both because the syntax is difference

lib/modules/asset/AssetsGroupsController.ts Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Outdated Show resolved Hide resolved
lib/modules/asset/AssetsGroupsController.ts Show resolved Hide resolved
tests/scenario/modules/assets/asset-group.test.ts Outdated Show resolved Hide resolved
@sebtiz13 sebtiz13 merged commit c49e5c7 into 2-dev Jul 17, 2023
3 checks passed
@sebtiz13 sebtiz13 deleted the feat/assets-groups branch July 17, 2023 11:54
sebtiz13 added a commit that referenced this pull request Jul 24, 2023
* feat(assets-groups): implement CRUD actions
* feat(assets-groups): implement add assets to group
* feat: implement remove assets to group
* feat: export group api types
* feat(createGroup): id is not mandatory anymore, auto generated if missing
* feat(groupName): add check of name unicity
* feat(groupAsset): handle group hierarchy
* feat(groupName): check presence of name when create
sebtiz13 added a commit that referenced this pull request Aug 14, 2023
* feat(assetGroups): implement CRUD actions
* feat(assetGroups): implement add assets to group
* feat(assetGroups): implement remove assets to group
* chore(types): export group api types
* feat(createGroup): id is not mandatory anymore, auto generated if missing
* feat(groupName): add check of name unicity
* feat(groupAsset): handle group hierarchy
* feat(groupName): check presence of name when create
github-actions bot pushed a commit that referenced this pull request Aug 14, 2023
# [2.3.0](v2.2.8...v2.3.0) (2023-08-14)

### Bug Fixes

* composite measures should be correctly exported to CSV ([#309](#309)) ([487c1e8](487c1e8))
* **docs:** wrong arguments in models' getDevice request ([#310](#310)) ([028c65c](028c65c))

### Features

* **assetGroups:** add assetGroups roles ([b9d0fae](b9d0fae))
* **assetGroups:** add groups for assets ([#306](#306)) ([10de8b4](10de8b4))
* **assetGroups:** add lastUpdate on changes  ([#311](#311)) ([36a4575](36a4575))
* **semantic-release:** add semantic release support to device manager ([99b1683](99b1683))
github-actions bot pushed a commit that referenced this pull request Aug 14, 2023
# [2.3.0](v2.2.8...v2.3.0) (2023-08-14)

### Bug Fixes

* composite measures should be correctly exported to CSV ([#309](#309)) ([487c1e8](487c1e8))
* **docs:** wrong arguments in models' getDevice request ([#310](#310)) ([028c65c](028c65c))

### Features

* **assetGroups:** add assetGroups roles ([b9d0fae](b9d0fae))
* **assetGroups:** add groups for assets ([#306](#306)) ([10de8b4](10de8b4))
* **assetGroups:** add lastUpdate on changes  ([#311](#311)) ([36a4575](36a4575))
* **semantic-release:** add semantic release support to device manager ([99b1683](99b1683))
sebtiz13 pushed a commit that referenced this pull request Aug 14, 2023
# [2.3.0](v2.2.8...v2.3.0) (2023-08-14)

### Bug Fixes

* composite measures should be correctly exported to CSV ([#309](#309)) ([487c1e8](487c1e8))
* **docs:** wrong arguments in models' getDevice request ([#310](#310)) ([028c65c](028c65c))

### Features

* **assetGroups:** add assetGroups roles ([b9d0fae](b9d0fae))
* **assetGroups:** add groups for assets ([#306](#306)) ([10de8b4](10de8b4))
* **assetGroups:** add lastUpdate on changes  ([#311](#311)) ([36a4575](36a4575))
* **semantic-release:** add semantic release support to device manager ([99b1683](99b1683))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants