Skip to content

Conversation

@yt-ms
Copy link
Collaborator

@yt-ms yt-ms commented May 13, 2021

Add support for filtered views, FilteredViews are slightly odd in that they don't have their own layout (they just take from their base view). In the Java implementation, they actually don't inherit from View because of this even though there are some common fields - in Python, I've introduced a new AbstractView superclass of View which is also common with FilteredView (I felt this was less disruptive than stripping View down and introducing a new type between View and all its current subtypes..

Also resolved a couple of TODOs in ViewSet.

This PR follows on from #78 so only commits from 6ef8af3 onwards are really part of this PR. I'll rebase once #78 is merged.


THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE Apache License v.2.0. YOU MAY OBTAIN A COPY OF THE LICENSE AT https://www.apache.org/licenses/LICENSE-2.0.

THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.

@yt-ms yt-ms linked an issue May 13, 2021 that may be closed by this pull request
1 task
@Midnighter
Copy link
Owner

I'll review this once we have resolved #78. Sorry for the long wait.

@yt-ms yt-ms force-pushed the issue-81-filtered-views branch from 1e7548c to ff4990b Compare June 8, 2021 10:50
@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2021

Codecov Report

Merging #82 (b393557) into devel (4778f21) will increase coverage by 0.24%.
The diff coverage is 95.65%.

Impacted file tree graph

@@ Coverage Diff @@ ## devel #82 +/- ## ========================================== + Coverage 93.76% 94.00% +0.24%  ========================================== Files 74 76 +2 Lines 2327 2404 +77 Branches 241 248 +7 ========================================== + Hits 2182 2260 +78  + Misses 119 116 -3  - Partials 26 28 +2 
Impacted Files Coverage Δ
src/structurizr/view/filtered_view.py 93.93% <93.93%> (ø)
src/structurizr/view/view_set.py 74.48% <94.11%> (+6.39%) ⬆️
src/structurizr/view/abstract_view.py 100.00% <100.00%> (ø)
src/structurizr/view/view.py 89.58% <100.00%> (-0.14%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4778f21...b393557. Read the comment docs.

@yt-ms yt-ms force-pushed the issue-81-filtered-views branch from ff4990b to 4a1463f Compare June 9, 2021 16:52
@yt-ms yt-ms force-pushed the issue-81-filtered-views branch from 4a1463f to 5d4ffda Compare June 9, 2021 21:08
@yt-ms yt-ms marked this pull request as ready for review June 9, 2021 21:12
Copy link
Owner

@Midnighter Midnighter left a comment

Choose a reason for hiding this comment

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

Neat, I like that you created the abstract view class and it's nice to see how it's all coming together. I have some suggestions for improvements. The only major thing would be adding a dictionary attribute to the ViewSet class as mentioned in one of the comments. Not sure it's worth it right now.

Comment on lines +69 to +73
return {
"key": view_io.key,
"description": view_io.description,
"title": view_io.title,
}
Copy link
Owner

Choose a reason for hiding this comment

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

I'm still not very happy with how we construct these arguments but that's neither here nor there.


base_view_key: str = Field(alias="baseViewKey")
mode: FilterMode
tags: List[str]
Copy link
Owner

Choose a reason for hiding this comment

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

Take a look at ModelItemIO. We introduced two methods there to convert the tags to and from string which is what the structurizr API expects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, the API is inconsistent, and for FilteredView the tags are serialised in JSON as an array. I've added the validator anyway for safety.

https://editor.swagger.io/?url=https://raw.githubusercontent.com/structurizr/json/master/structurizr.yaml

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will try this against an actual Structurizr instance to make sure the Swagger is correct though...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, I built a filtered view in Structurizr and exported the JSON, and it does indeed serialise the tags as an array rather than comma-separated.

Copy link
Owner

Choose a reason for hiding this comment

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

Huh, thanks for digging into that. @simonbrowndotje is that an oversight or fully intentional?

Copy link

@simonbrowndotje simonbrowndotje Jun 10, 2021

Choose a reason for hiding this comment

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

It was intentional at one point in time, but not any more ... when I first started writing the Java client library (5+ years ago), I had some issues with the order of array elements being preserved. The order for tags defining a filtered view isn't important, but the ordering of element/relationship tags is. So the former is an array, whereas the latter is a comma-separated list.

)
return next((view for view in all_views if view.key == key), None)

def __getitem__(self, key: str) -> AbstractView:
Copy link
Owner

Choose a reason for hiding this comment

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

This method points a bit towards creating a 'private' attribute which is a dict of all the views. Then fetching a particular view by key is very easy. It would mean managing that dictionary, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, so I've had a crack at this - actually replacing the various sets with a single dictionary. I think this actually works quite well - see what you think.

yt-ms and others added 5 commits June 10, 2021 08:49
@Midnighter
Copy link
Owner

Looks all good to me then. Thank you for the quick work on the changes.

@Midnighter Midnighter merged commit e91f1f4 into Midnighter:devel Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants