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

Added "Referenced By" and "Depends On" section for each SQL file #106

Merged
merged 15 commits into from
Aug 11, 2020

Conversation

stephen8chang
Copy link
Contributor

@stephen8chang stephen8chang commented Jun 25, 2020

Problem

When one is trying to view SQL files and their immediate relationships to other SQL files in DBT docs, they have to go through a rather annoying process of clicking the lineage graph, and possibly few other clicks just to view the parent or child of the currently selected SQL file.

Solution

To make this process more convenient for the user, this PR adds a "Referenced By" and "Depends On" section in addition to the description of each SQL file, thus allowing the user to view the immediate parent and immediate child files (of any type) of the currently selected SQL file.

image

To accomplish this, the following changes were made to most files in src/app/docs :

  • Additional section components were added for "Referenced By" and "Depends On" in the HTML docs files
  • Added utils.js, which includes the functions to obtain the files that are "Referenced By" or "Depends On" the current SQL file. This is imported into all of the JavaScript files in the docs folder.
  • In macro.js, unique versions of the above two functions are written, mainly to accommodate for the fact that macro's can only have parents that are other macros (this change does not appear in src/manifest.json)

Other Information

@guy-adams
Copy link

FWIW this is a lovely addition - well done!

@drewbanin
Copy link
Contributor

hey @stephen8chang - this is AWESOME! I'll try to dig in here today, but just wanted to give you an early heads up that

  1. I really love this and
  2. I'm definitely interested in figuring out how to get this merged

@drewbanin
Copy link
Contributor

Thanks for sending through this PR @stephen8chang (and h/t to @Matt343 as well!). I've spent some time clicking around in here today, and I do buy the utility of some new components in the UI for "referenced by" and "depends on" for sure.

I think that at a certain point, we're going to need to rethink the UI/layout of this page. I don't love the fact that our only place for information like this today is inline in the page. Ideally, I'd like to consider some alternative layouts that keep the primary information front-and-center, while still making information like this accessible when it is relevant. @amy-byrum, you think maybe we can use this PR as an opportunity to give some thought to the future of the Docs UI?

All this said, I don't think we need to block merging this PR on a redesign of the Docs site :D. @jtcohen6 adding you for review here. I'll take care of the code review piece, but it would be awesome if you could spend some time clicking around in here and noting your thoughts. I would really like to get this change shipped for 0.18.0 if we can!

Thanks again all - super exciting!

@drewbanin drewbanin requested review from drewbanin and jtcohen6 July 25, 2020 16:04
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

Just dropped a couple of comments in here, happy to discuss!

@@ -0,0 +1,36 @@
const _ = require('underscore');
export function getReferences(project, model) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We've historically leveraged services for things like this, but I'm increasingly super into the idea of just using a require instead of going through Angular's dependency injection flow.

Can you just rename this from utils.js to something more specific like dag_utils.js instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do!

@@ -15,25 +15,47 @@ angular
$scope.project = projectService;
$scope.codeService = codeService;

function getReferences(project, macro) {
var references = _.filter(project.nodes, function(node) {
function getReferences(project, self) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think there's a way to reconcile this logic with the code in src/app/docs/utils.js? I totally get that the different namespaces for macros and nodes could make this challenging, but it feels funny to have two very similar sets of functions so far apart from each other. Let me know what you think!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The decision to include these two functions in macro.js and separate from utils.js was to accommodate for the differing properties of macros and nodes. Would it make sense to you to have the two functions in macro.js included in utils.js as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@drewbanin I moved the functions related to obtaining references and parents for macros from macro.js to dag_utils.js (previously utils.js). Let me know what you think.

@@ -36,6 +36,8 @@ <h1>
<li ui-sref-active='active'><a ui-sref="dbt.model({'#': 'details'})">Details</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.model({'#': 'description'})">Description</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.model({'#': 'columns'})">Columns</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.model({'#': 'referenced_by'})">Referenced By</a></li>
Copy link
Contributor

Choose a reason for hiding this comment

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

We can and should figure out a better way to reduce the copy/paste necessary for these different node types. Not a problem at all for right now though :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! Let me know if you would like me to spend some time on figuring out how to reduce the copy pasting.

@jtcohen6
Copy link
Contributor

jtcohen6 commented Aug 2, 2020

This is really cool! I agree with your comments above @drewbanin. Let's think about a better home for this information during a future redesign.

A couple of oddities I noticed:

  • Models include schema tests in the Referenced By section, as well they should. This is weird only because, while schema tests do populate pages in the docs site, they don't map to anything in the Project, Database, or DAG view. (example). Every other resource maps to one or more of those.
  • Macros do not appear as each others' dependencies. E.g. dbt_utils.date_spine calls dbt_utils.dateadd, but dbt_utils.dateadd says no resources reference it. That's true in the docs today.
  • The placeholder text, for both Referenced By and Depends On, appears to be No resources reference this macro, regardless of resource type.

The only change I'd request of the current PR relates to the last point. I think the simplest solution would be to exclude the Referenced By/Depends On section if it's completely empty.

@Matt343
Copy link
Contributor

Matt343 commented Aug 3, 2020

  • Macros do not appear as each others' dependencies. E.g. dbt_utils.date_spine calls dbt_utils.dateadd, but dbt_utils.dateadd says no resources reference it. That's true in the docs today.

The reason for this is that the relevant sections in the manifest.json file are always empty for macros. I'm not sure why that is, but depends_on.macros is always empty for a macro node, even if it does contain macro references. To fix this, we'd need to fix that bug in dbt core.

@stephen8chang
Copy link
Contributor Author

@jtcohen6 The References By/Depends On section now appears only if it exists for that specific table.

@jtcohen6
Copy link
Contributor

jtcohen6 commented Aug 6, 2020

Re: inter-macro dependencies: it sounds like we're not recording those in the manifest as we should be.

Thanks for making the change around empty Depends On / Referenced By! I definitely like the look better. I think we may now be missing some sections in cases where a model is referenced by or depends on only non-model nodes. In the deploy preview, e.g.

@stephen8chang
Copy link
Contributor Author

@jtcohen6 Sorry for the late response! Looks like the issue was with the conditional for the HTML components I had for commit 39345e5. Let me know how it looks on your end.

Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

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

Nice! Looks like that resolved it. Thanks so much for the contribution @stephen8chang

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.

Add Referenced By and Depends On section to node pages
5 participants