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

Add device group feature flag in TeamType #3235

Conversation

knolleary
Copy link
Member

@knolleary knolleary commented Dec 19, 2023

This adds a deviceGroup feature flag to TeamType so the feature can be limited to certain team types.

As part of this, I found that if you open an application in a team that isn't your default team directly (ie paste the url in, or Ctrl-R on the page), we would load the user's default team first, then load the team of the application you were accessing.

This would cause the view to first load data associated with your default team, before refreshing with data for the team you were accessing - in some cases, it wouldn't refresh because there was no watch happening.

To fix this, I've modified the account load phase to skip loading the user's team if the url is on either /application, /device or /instance - as all of these views do a lookup of the team and call setTeam anyway. This avoids the double load.

However, I then hit the problem with the order the application page does things. It loads the application information, devices, deviceGroups etc, then it ensures the loaded team is the one for the application. This leads to a chicken-vs-egg situation as we now need to check the team's feature flags to decide whether to load the device groups or not.... but we may not have loaded the team yet.

As a workaround, I've put a try/catch around the loading of deviceGroups, which will 404 if the team isn't allowed to use device groups (we at least have the platform-level guard in there). I then pass a flag down through all of the Pipeline components to say if deviceGroups is enabled or not. I dislike this model - I find it much easier to reason over if a component uses mapState to access the team locally, rather than all of this passing down of properties. I'm sure there is a Vue reason it's being done the way it is...

Updated via 2ced020 - I've modified the order the Application loads things, having realised we can await the loading of the application team (if needed). This ensure we have the Team object so can check the device group feature flag. As a consequence, I've also removed the deviceGroupEnabled property I had added - cleaner (IMHO) to check the team directly from the store (ie via mapState...).

Copy link

codecov bot commented Dec 19, 2023

Codecov Report

Attention: 32 lines in your changes are missing coverage. Please review.

Comparison is base (bef6d99) 40.70% compared to head (2ced020) 40.68%.

Files Patch % Lines
frontend/src/store/account.js 0.00% 11 Missing ⚠️
frontend/src/pages/application/DeviceGroups.vue 0.00% 8 Missing ⚠️
frontend/src/pages/application/index.vue 0.00% 6 Missing ⚠️
...ges/admin/TeamTypes/dialogs/TeamTypeEditDialog.vue 0.00% 3 Missing ⚠️
...ntend/src/pages/application/PipelineStage/form.vue 0.00% 3 Missing ⚠️
forge/ee/routes/applicationDeviceGroups/index.js 66.66% 1 Missing ⚠️
Additional details and impacted files
@@                              Coverage Diff                               @@
##           2989-assign-device-group-to-pipeline-stage    #3235      +/-   ##
==============================================================================
- Coverage                                       40.70%   40.68%   -0.03%     
==============================================================================
  Files                                             598      598              
  Lines                                           22311    22327      +16     
  Branches                                         5374     5383       +9     
==============================================================================
+ Hits                                             9082     9084       +2     
- Misses                                          13229    13243      +14     
Flag Coverage Δ
backend 77.35% <75.00%> (-0.01%) ⬇️
frontend 2.03% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Steve-Mcl Steve-Mcl left a comment

Choose a reason for hiding this comment

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

Other than Pez's comments for clarification, happy to merge.

@Steve-Mcl Steve-Mcl linked an issue Dec 20, 2023 that may be closed by this pull request
@knolleary
Copy link
Member Author

@Steve-Mcl can you have a look at the last set of commits?

  • Added a Loading placeholder on the Device Group view (given the async nature of loading the groups, it was flashing up the empty state before showing the actual list).
  • Reworked the order the application loads things so we will have the team object available to check if the feature flag is set.

Comment on lines +15 to +19
<ff-loading
v-if="loading"
message="Loading Device Groups..."
/>
<div v-else-if="deviceGroups?.length > 0" class="pt-4 space-y-6" data-el="pipelines-list">
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of show/hide whole portions of the page, perhaps we should simply utelise the features of the data table like we do for "Loading Teams" and "Loading Users"?

https://flowfuse.github.io/forge-ui-components/#ff-data-table

Property Default Description
loading false Shows a placeholder Loading message in place of the data.
loading-message 'Loading Data...' If loading=true, then this message will be shown.

Copy link
Contributor

@Pezmc Pezmc left a comment

Choose a reason for hiding this comment

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

Much prefer the new approach!

@knolleary knolleary merged commit 390291b into 2989-assign-device-group-to-pipeline-stage Dec 20, 2023
9 of 10 checks passed
@knolleary knolleary deleted the 2989-device-group-team-tier-enabled branch December 20, 2023 10:55
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.

Implementing Device Groups Management
3 participants