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

Docs: Add Support for "<seealso />" Links #10314

Merged
merged 21 commits into from
Dec 6, 2024

Conversation

jperson2000
Copy link
Contributor

@jperson2000 jperson2000 commented Nov 23, 2024

Description

This update adds support for <seealso cref="" /> and <seealso href="" /> links in the API documentation. Links are detected by the MudBlazor.Docs.Compiler and are available to the docs web site via the new DocumentedType.Links property. Additionally, the new ApiSeeAlsoLinks component can display all of the see-also links for a given type, which is now available at the bottom of API documentation pages.

For example: Writing the following <seealso /> tags for the Bar chart component:

    /// <summary>
    /// Represents a chart which displays series values as rectangular bars.
    /// </summary>
    /// <seealso cref="Donut"/>
    /// <seealso cref="Line"/>
    /// <seealso cref="Pie"/>
    /// <seealso cref="StackedBar"/>
    /// <seealso cref="TimeSeries"/>
    partial class Bar : MudCategoryChartBase

... will produce the following See Also section on the Bar API documentation page:

image

See also links can also use the href tag for external links, as well as inner text:

<seealso href="https://www.mudblazor.com/components/MudAlert">MudAlert Examples</seealso>

Linking From Non-Component Types to Component Examples

In some cases, a type such as MudDrawerHeader may not have its own example page, but should still be linked to a different component, MudDrawer. These links are controlled via the MenuService._docsComponents, as shown below:

image

How Has This Been Tested?

Since this change affects the entire docs web site, testing involves regression testing the entire MudBlazor docs site. For component and API pages, the following steps were done:

  1. Visit all non-component pages
  2. For each component in the left-hand menu:
  3. Visit the component
  4. Click the "Documentation" button to visit the API documentation page.
  5. Observe any see-also links at the bottom of the page.
  6. Click the "Example" button to return the the component page

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added the docs Related to docs label Nov 23, 2024
@ScarletKuro
Copy link
Member

ScarletKuro commented Nov 23, 2024

Not sure it's worth renaming Component to TypeName, to me, the difference is small. Considering the amount of changes and possible conflicts in other PRs.

@danielchalmers
Copy link
Member

Not sure it's worth renaming Component to TypeName, to me, the difference is small. Considering the amount of changes and possible conflicts in other PRs.

It's being moved from DocsPageHeader to DocsPage so it will create a diff anyway, and TypeName is more encompassing for non-component pages. I'd be surprised if it generates conflicts as it's in a part that is rarely edited too.

@danielchalmers
Copy link
Member

The docs/examples button should be a link instead of a button.

Will try to get more feedback later. Love the direction this is going!

@jperson2000
Copy link
Contributor Author

Not sure it's worth renaming Component to TypeName, to me, the difference is small. Considering the amount of changes and possible conflicts in other PRs.

Thanks, @ScarletKuro , the parameter had moved up a level to the DocsPage, but I agree that this may be too far-reaching of a change for one PR. Maybe I can just get <seealso /> support in for this one and we can see if the links between API and component pages should be changed.

@jperson2000
Copy link
Contributor Author

Not sure it's worth renaming Component to TypeName, ...

It's being moved from DocsPageHeader to DocsPage ...

Oops, I replied before reading Daniel's comments lol. Well, I'm fine moving those to another PR if that feels better.

@ScarletKuro
Copy link
Member

t's being moved from DocsPageHeader to DocsPage

Ok, I didn't notice that during scrolling, then nvm above.
Tho I'm worried we doing this pattern in Docs when it's banned in the core.

[Parameter]
public string TypeName
{
get => _typeName;
set
{
_typeName = value?.Replace("%601", "`1");
_type = value == null ? null : ApiDocumentation.GetType(_typeName);
StateHasChanged();
}
}

@jperson2000
Copy link
Contributor Author

t's being moved from DocsPageHeader to DocsPage

Ok, I didn't notice that during scrolling, then nvm above. Tho I'm worried we doing this pattern in Docs when it's banned in the core.

Ok sure, I think I just didn't know how to follow the parameter state like with other controls, but I'll update this to use the same pattern. It makes me want to use that at my day job somehow as well!

@jperson2000
Copy link
Contributor Author

Ok, I've rolled back the other changes for now, but there are still a bunch of whitespace changes in this PR. Should I roll those back as well to make this easier to merge @ScarletKuro ?

@ScarletKuro
Copy link
Member

Ok sure, I think I just didn't know how to follow the parameter state like with other controls, but I'll update this to use the same pattern.

Considering the low amount or parameters and that you don't need to set value of the parameters inside the DocsPage and you don't need any change handlers you don't really need parameter state, you could do something simple as:

private string _typeName = string.Empty;
private string _type = string.Empty;

[Parameter]
public string TypeName { get; set; }

protected override void OnParametersSet()
{
	// Can crete SetTypeName to not duplicate logic
	_typeName = TypeName?.Replace("%601", "`1");
	_type = value == null ? null : ApiDocumentation.GetType(_typeName);
}

protected override void OnInitialized()
{
	// Can crete SetTypeName to not duplicate logic
	_typeName = TypeName?.Replace("%601", "`1");
}

You just need to make sure that you only read from the _typeName, not from the TypeName.

@ScarletKuro
Copy link
Member

Should I roll those back

You can keep these changes.

@ScarletKuro
Copy link
Member

ScarletKuro commented Nov 24, 2024

Ok sure, I think I just didn't know how to follow the parameter state like with other controls, but I'll update this to use the same pattern.

Considering the low amount or parameters and that you don't need to set value of the parameters inside the DocsPage and you don't need any change handlers you don't really need parameter state, you could do something simple as:

private string _typeName = string.Empty;
private string _type = string.Empty;

[Parameter]
public string TypeName { get; set; }

protected override void OnParametersSet()
{
	// Can crete SetTypeName to not duplicate logic
	_typeName = TypeName?.Replace("%601", "`1");
	_type = value == null ? null : ApiDocumentation.GetType(_typeName);
}

protected override void OnInitialized()
{
	// Can crete SetTypeName to not duplicate logic
	_typeName = TypeName?.Replace("%601", "`1");
}

You just need to make sure that you only read from the _typeName, not from the TypeName.

Maybe, you don't even need the OnParametersSet, since you set the values only once, I don't think they change? At least i just use sometimes only OnInitialized in some of my Blazor libs as the value doesn't change.

@jperson2000
Copy link
Contributor Author

Maybe, you don't even need the OnParametersSet, since you set the values only once, I don't think they change? At least i just use sometimes only OnInitialized in some of my Blazor libs as the value doesn't change.

If a user navigates to the same page but for a different type, the TypeName will change but OnInitialized won't get called. Still, I see what you're saying and will do simpler code here for OnParametersSet on the next commit.

@henon
Copy link
Collaborator

henon commented Nov 25, 2024

This is a really cool feature. Thanks for adding that @jperson2000

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.43%. Comparing base (4798bbf) to head (292fe2c).
Report is 5 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #10314   +/-   ##
=======================================
  Coverage   91.43%   91.43%           
=======================================
  Files         418      418           
  Lines       13226    13226           
  Branches     2538     2538           
=======================================
  Hits        12093    12093           
  Misses        554      554           
  Partials      579      579           

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

@ScarletKuro
Copy link
Member

Does this PR fixes?
bug

@jperson2000
Copy link
Contributor Author

Does this PR fixes?

Yes, the link to a component page will now only appear if the type is mentioned in MenuService._docsComponents. But, it created broken tests because tests assumed that every type had an example page link. Hopefully I can fix this today after work.

@ScarletKuro
Copy link
Member

Don't forget to update your branch as we got new component Heatmap #10263

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Comment on lines +138 to +159
public List<Type> TypesWithExamples =
[
typeof(MudContainer), typeof(MudGrid), typeof(MudItem), typeof(MudHidden), typeof(MudBreakpointProvider), typeof(MudChip<object>), typeof(MudChipSet<object>),
typeof(MudBadge), typeof(MudAppBar), typeof(MudDrawer), typeof(MudDrawerHeader), typeof(MudDrawerContainer), typeof(MudDropZone<object>), typeof(MudDropContainer<object>),
typeof(MudDynamicDropItem<object>), typeof(MudLink), typeof(MudMenu), typeof(MudMenuItem), typeof(MudMessageBox), typeof(MudNavMenu), typeof(MudNavLink), typeof(MudNavGroup),
typeof(MudTabs), typeof(MudTabPanel), typeof(MudDynamicTabs), typeof(MudProgressCircular), typeof(MudProgressLinear), typeof(MudDialog), typeof(MudDialogContainer),
typeof(MudDialogProvider), typeof(SnackbarService), typeof(MudSnackbarProvider), typeof(MudSnackbarElement), typeof(MudAvatar), typeof(MudAvatarGroup),
typeof(MudAlert), typeof(MudCard), typeof(MudCardActions), typeof(MudCardContent), typeof(MudCardHeader), typeof(MudCardMedia), typeof(MudDivider),
typeof(MudExpansionPanels), typeof(MudExpansionPanel), typeof(MudImage), typeof(MudIcon), typeof(MudList<object>), typeof(MudListItem<object>), typeof(MudListSubheader),
typeof(MudPaper), typeof(MudRating), typeof(MudRatingItem), typeof(MudSkeleton), typeof(MudTableBase), typeof(MudTable<object>), typeof(MudTablePager),
typeof(MudTableGroupRow<object>), typeof(MudTableSortLabel<object>), typeof(MudTd), typeof(MudTh), typeof(MudTr), typeof(MudTFootRow), typeof(MudTHeadRow),
typeof(MudDataGrid<object>), typeof(Column<object>), typeof(FilterHeaderCell<object>), typeof(FooterCell<object>), typeof(HeaderCell<object>), typeof(HierarchyColumn<object>), typeof(MudDataGridPager<object>),
typeof(TemplateColumn<object>), typeof(MudSimpleTable), typeof(MudTooltip), typeof(MudText), typeof(MudOverlay), typeof(MudHighlighter), typeof(MudElement),
typeof(MudFocusTrap), typeof(MudTreeView<object>), typeof(MudTreeViewItem<object>), typeof(MudTreeViewItemToggleButton), typeof(MudBreadcrumbs), typeof(MudScrollToTop),
typeof(MudPopover), typeof(MudSwipeArea), typeof(MudToolBar), typeof(MudCarousel<object>), typeof(MudCarouselItem), typeof(MudTimeline), typeof(MudTimelineItem),
typeof(MudPagination), typeof(MudStack), typeof(MudSpacer), typeof(MudCollapse), typeof(MudStepper), typeof(MudStep), typeof(MudRadio<object>), typeof(MudRadioGroup<object>),
typeof(MudCheckBox<object>), typeof(MudSelect<object>), typeof(MudSelectItem<object>), typeof(MudSlider<int>), typeof(MudSwitch<object>), typeof(MudTextField<object>),
typeof(MudNumericField<object>), typeof(MudForm), typeof(MudAutocomplete<object>), typeof(MudField), typeof(MudFileUpload<object>), typeof(MudToggleGroup<object>), typeof(MudToggleItem<object>),
typeof(MudDatePicker), typeof(MudDateRangePicker), typeof(MudTimePicker), typeof(MudColorPicker), typeof(MudButton), typeof(MudButtonGroup), typeof(MudIconButton),
typeof(MudToggleIconButton), typeof(MudFab), typeof(ChartOptions), typeof(Donut), typeof(Line), typeof(Legend), typeof(Pie), typeof(Bar), typeof(HeatMap),typeof(StackedBar),
typeof(TimeSeries), typeof(MudTimeSeriesChartBase), typeof(MudTimeSeriesChart)
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section is used by the test generator to figure out which types should have associated example pages. These types come from the types mentioned in MenuService. Since we can't link to MenuService directly, the types have to be duplicated here. Hopefully that's okay.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jperson2000 this breaks my reflective Docs Compiler since this now requires a reference to MudBlazor. IDK if theres another way to do this?

Copy link
Member

Choose a reason for hiding this comment

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

@jperson2000 this breaks my reflective Docs Compiler since this now requires a reference to MudBlazor. IDK if theres another way to do this?

What does the "now" mean? Even before the PR the compiler was referencing the MudBlazor and some types were used, proof:
Reference
This is the used referenced before the PR merge.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeh sorry I meant this is a new static type that I noticed when merging this into my work. In my work I was already loading the assembly at runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a place we could move MenuService where it can be accessible by both the Docs and Compiler projects? If so, then I can use it to get the types with examples, and delete this TypesWithExamples property.

@jperson2000 jperson2000 marked this pull request as ready for review December 3, 2024 05:00
@jperson2000
Copy link
Contributor Author

Okay guys, this is finally ready to review and all tests now pass. The docs tests needed a change to indicate which API docs pages should have a link back to an example page. I wish we could access MenuService since all the types are mentioned there, but a reference from the Docs Compiler to MudBlazor.Docs is currently not possible. Thanks for taking a look!

@mikes-gh
Copy link
Contributor

mikes-gh commented Dec 3, 2024

Thanks! Looking through it and it seems reasonable but I definitely have an issue with it crashing on my Surface Laptop 7th - ARM64, 16GB RAM

Hi @danielchalmers is this during a build? Any logs

@danielchalmers
Copy link
Member

Thanks! Looking through it and it seems reasonable but I definitely have an issue with it crashing on my Surface Laptop 7th - ARM64, 16GB RAM

Hi @danielchalmers is this during a build? Any logs

@mikes-gh It was during debug after I navigated. Best type of logs to send you?

@mikes-gh
Copy link
Contributor

mikes-gh commented Dec 3, 2024

@danielchalmers

Can you give steps for a repo please.
Are you debugging docs?
Are you launching in wasmhost?
Are you attempting to use hot reload?
Does it work OK before this PR.
etc

Copy link

sonarqubecloud bot commented Dec 4, 2024

@danielchalmers
Copy link
Member

@danielchalmers

Can you give steps for a repo please. Are you debugging docs? Are you launching in wasmhost? Are you attempting to use hot reload? Does it work OK before this PR. etc

Apologies, I can't provide in depth info this week, but it was an issue before this PR so should be safe to merge. @mikes-gh

@danielchalmers danielchalmers removed their request for review December 4, 2024 22:15
@henon henon changed the title Docs: Added Support for "<seealso />" Links Docs: Add Support for "<seealso />" Links Dec 6, 2024
@henon henon merged commit c940584 into MudBlazor:dev Dec 6, 2024
6 checks passed
@henon
Copy link
Collaborator

henon commented Dec 6, 2024

Thanks @jperson2000 !

@jperson2000 jperson2000 deleted the feature/docs-seealso-links branch December 6, 2024 16:10
@mikes-gh
Copy link
Contributor

mikes-gh commented Dec 9, 2024

@jperson2000 This PR seems to remove the API link on components page. Is that intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Related to docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants