Skip to content

Commit

Permalink
- janky wasm SPA for kiota search
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Oct 19, 2022
1 parent 4aaf5e4 commit c3137c2
Show file tree
Hide file tree
Showing 30 changed files with 1,347 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kiota.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{2DF34BB8
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kiota.Tests", "tests\Kiota.Tests\Kiota.Tests.csproj", "{E4C108A5-A13F-4C3F-B32A-86210A4EC52A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EAAC5CEA-33B8-495D-9CD0-B36794B8AFE7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kiota.Web", "src\Kiota.Web\Kiota.Web.csproj", "{C27E6F75-8E64-4F3D-8EA0-E632BFAFF600}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,6 +45,10 @@ Global
{E4C108A5-A13F-4C3F-B32A-86210A4EC52A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4C108A5-A13F-4C3F-B32A-86210A4EC52A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4C108A5-A13F-4C3F-B32A-86210A4EC52A}.Release|Any CPU.Build.0 = Release|Any CPU
{C27E6F75-8E64-4F3D-8EA0-E632BFAFF600}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C27E6F75-8E64-4F3D-8EA0-E632BFAFF600}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C27E6F75-8E64-4F3D-8EA0-E632BFAFF600}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C27E6F75-8E64-4F3D-8EA0-E632BFAFF600}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -50,5 +58,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E4C108A5-A13F-4C3F-B32A-86210A4EC52A} = {2DF34BB8-B19F-4623-9E3D-9F59A14C0660}
{C27E6F75-8E64-4F3D-8EA0-E632BFAFF600} = {EAAC5CEA-33B8-495D-9CD0-B36794B8AFE7}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions src/Kiota.Web/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
18 changes: 18 additions & 0 deletions src/Kiota.Web/Kiota.Web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.10" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Kiota.Builder\Kiota.Builder.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/Kiota.Web/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@page "/counter"

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}
}
57 changes: 57 additions & 0 deletions src/Kiota.Web/Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@page "/fetchdata"
@inject HttpClient Http

<PageTitle>Weather forecast</PageTitle>

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}

@code {
private WeatherForecast[]? forecasts;

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}

public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public string? Summary { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
78 changes: 78 additions & 0 deletions src/Kiota.Web/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
@page "/"
@using Kiota.Builder
@using Kiota.Builder.SearchProviders
@using Kiota.Builder.Configuration
@using System.Linq
@inject ILoggerFactory LoggerFactory

<PageTitle>Kiota - search for an OpenAPI description</PageTitle>

<h1>Search query</h1>

<div>
<div class="form-group">
<div class="form-row">
<div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-6">
<label for="term">Search term or Key</label>
<input id="term" type="text" @bind="SearchTerm" class="form-control" required="true" />
</div>
</div>
<div class="form-row">
<div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-6">
<label for="version">Version</label>
<input id="version" type="text" @bind="Version" class="form-control" />
</div>
</div>
</div>
<button @onclick="SearchDocuments" class="btn btn-primary">Search</button>
</div>

@if (SearchResults.Any() && (SearchTerm?.Contains("::") ?? false) && SearchResults.ContainsKey(SearchTerm)) {
var singleResult = SearchResults[SearchTerm];
<div id="single-result">
<h2>Single result</h2>
<p>
<span>Key: </span><a href="@singleResult.DescriptionUrl" target="_blank">@SearchTerm</a><br />
<span>Description: </span>@singleResult.Description<br />
<span>Service root: </span>@singleResult.ServiceUrl<br />
<span>Version(s): </span>@(Version ?? string.Join(", ", singleResult.VersionLabels))<br />
</p>
</div>
} else if (SearchResults.Any()) {
<div id="results">
<h2>Multiple Results</h2>
<table>
<thead>
<tr>
<th>Key</th>
<th>Description</th>
<th>Version</th>
</tr>
</thead>
<tbody>
@foreach (var result in SearchResults)
{
<tr>
<td><a href="@result.Value.DescriptionUrl" target="_blank">@result.Key</a></td>
<td><p>@result.Value.Description</p></td>
<td><p>@string.Join(", ", result.Value.VersionLabels)</p></td>
</tr>
}
</tbody>
</table>
</div>
}

@code {
private string? SearchTerm { get; set; }
private string? Version { get; set; }
private IDictionary<string, SearchResult> SearchResults = new Dictionary<string, SearchResult>();
private async Task SearchDocuments() {
var searchConfig = new SearchConfiguration() {
SearchTerm = SearchTerm,
Version = Version,
};
var logger = LoggerFactory.CreateLogger<KiotaSearcher>();
SearchResults = await new KiotaSearcher(logger, searchConfig).SearchAsync(new CancellationToken());
}
}
11 changes: 11 additions & 0 deletions src/Kiota.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Kiota.Web;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();
30 changes: 30 additions & 0 deletions src/Kiota.Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:35259",
"sslPort": 44313
}
},
"profiles": {
"Kiota.Web": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7230;http://localhost:5130",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
17 changes: 17 additions & 0 deletions src/Kiota.Web/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>
81 changes: 81 additions & 0 deletions src/Kiota.Web/Shared/MainLayout.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}

main {
flex: 1;
}

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}

.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}

.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}

.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 640.98px) {
.top-row:not(.auth) {
display: none;
}

.top-row.auth {
justify-content: space-between;
}

.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}

@media (min-width: 641px) {
.page {
flex-direction: row;
}

.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}

.top-row {
position: sticky;
top: 0;
z-index: 1;
}

.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}

.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
39 changes: 39 additions & 0 deletions src/Kiota.Web/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">Kiota.Web</a>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All"><!-- icons list https://github.com/iconic/open-iconic/tree/master/svg -->
<span class="oi oi-magnifying-glass" aria-hidden="true"></span> Search
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</div>
</nav>
</div>

@code {
private bool collapseNavMenu = true;

private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
Loading

0 comments on commit c3137c2

Please sign in to comment.