Skip to content

Commit

Permalink
Merge pull request #228 from Esri/Caleb/Update-SampleViewerSearchBar
Browse files Browse the repository at this point in the history
[Update] Improve Sample Viewer search
  • Loading branch information
yo1995 authored Aug 15, 2023
2 parents ae2dc52 + 62e0b96 commit 452c08e
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 128 deletions.
32 changes: 16 additions & 16 deletions Samples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
0005580A2817C51E00224BC6 /* SampleDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 000558092817C51E00224BC6 /* SampleDetailView.swift */; };
00181B462846AD7100654571 /* View+Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00181B452846AD7100654571 /* View+Alert.swift */; };
001C6DE127FE8A9400D472C2 /* AppSecrets.swift.masque in Sources */ = {isa = PBXBuildFile; fileRef = 001C6DD827FE585A00D472C2 /* AppSecrets.swift.masque */; };
00273CF42A82AB5900A7A77D /* SamplesSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */; };
00273CF62A82AB8700A7A77D /* SampleRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00273CF52A82AB8700A7A77D /* SampleRow.swift */; };
0039A4E92885C50300592C86 /* AddSceneLayerFromServiceView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = E066DD3F28610F55004D3D5B /* AddSceneLayerFromServiceView.swift */; };
0039A4EA2885C50300592C86 /* ClipGeometryView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = E000E75F2869E33D005D87C5 /* ClipGeometryView.swift */; };
0039A4EB2885C50300592C86 /* CreatePlanarAndGeodeticBuffersView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = E004A6EC2849556E002A1FE6 /* CreatePlanarAndGeodeticBuffersView.swift */; };
Expand Down Expand Up @@ -51,6 +53,7 @@
00B042E8282EDC690072E1B4 /* SetBasemapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B042E5282EDC690072E1B4 /* SetBasemapView.swift */; };
00B04FB5283EEBA80026C882 /* DisplayOverviewMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B04FB4283EEBA80026C882 /* DisplayOverviewMapView.swift */; };
00C43AED2947DC350099AE34 /* ArcGISToolkit in Frameworks */ = {isa = PBXBuildFile; productRef = 00C43AEC2947DC350099AE34 /* ArcGISToolkit */; };
00C7993B2A845AAF00AFE342 /* Sidebar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C7993A2A845AAF00AFE342 /* Sidebar.swift */; };
00C94A0D28B53DE1004E42D9 /* raster-file in Resources */ = {isa = PBXBuildFile; fileRef = 00C94A0C28B53DE1004E42D9 /* raster-file */; settings = {ASSET_TAGS = (AddRasterFromFile, ); }; };
00CB9138284814A4005C2C5D /* SearchWithGeocodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CB9137284814A4005C2C5D /* SearchWithGeocodeView.swift */; };
00CCB8A5285BAF8700BBAB70 /* OnDemandResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CCB8A4285BAF8700BBAB70 /* OnDemandResource.swift */; };
Expand Down Expand Up @@ -134,10 +137,7 @@
88F93CC129C3D59D0006B28E /* SketchOnMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88F93CC029C3D59C0006B28E /* SketchOnMapView.swift */; };
88F93CC229C4D3480006B28E /* SketchOnMapView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 88F93CC029C3D59C0006B28E /* SketchOnMapView.swift */; };
D701D72C2A37C7F7006FF0C8 /* bradley_low_3ds in Resources */ = {isa = PBXBuildFile; fileRef = D701D72B2A37C7F7006FF0C8 /* bradley_low_3ds */; settings = {ASSET_TAGS = (ShowViewshedFromGeoelementInScene, ); }; };
D70BE5792A5624A80022CA02 /* CategoryGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE5782A5624A80022CA02 /* CategoryGridView.swift */; };
D70BE57F2A5753B70022CA02 /* SampleListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE57E2A5753B70022CA02 /* SampleListView.swift */; };
D70BE5832A5766CA0022CA02 /* CategoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE5822A5766C90022CA02 /* CategoryView.swift */; };
D70BE5882A5787530022CA02 /* CategoryView+Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE5872A5787530022CA02 /* CategoryView+Search.swift */; };
D70BE5792A5624A80022CA02 /* CategoriesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE5782A5624A80022CA02 /* CategoriesView.swift */; };
D710996D2A27D9210065A1C1 /* DensifyAndGeneralizeGeometryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D710996C2A27D9210065A1C1 /* DensifyAndGeneralizeGeometryView.swift */; };
D710996E2A27D9B30065A1C1 /* DensifyAndGeneralizeGeometryView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D710996C2A27D9210065A1C1 /* DensifyAndGeneralizeGeometryView.swift */; };
D71099702A2802FA0065A1C1 /* DensifyAndGeneralizeGeometryView.SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D710996F2A2802FA0065A1C1 /* DensifyAndGeneralizeGeometryView.SettingsView.swift */; };
Expand Down Expand Up @@ -380,6 +380,8 @@
000558092817C51E00224BC6 /* SampleDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleDetailView.swift; sourceTree = "<group>"; };
00181B452846AD7100654571 /* View+Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Alert.swift"; sourceTree = "<group>"; };
001C6DD827FE585A00D472C2 /* AppSecrets.swift.masque */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AppSecrets.swift.masque; sourceTree = "<group>"; };
00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SamplesSearchView.swift; sourceTree = "<group>"; };
00273CF52A82AB8700A7A77D /* SampleRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleRow.swift; sourceTree = "<group>"; };
003D7C342821EBCC009DDFD2 /* masquerade */ = {isa = PBXFileReference; lastKnownFileType = text; path = masquerade; sourceTree = "<group>"; };
003D7C352821EBCC009DDFD2 /* GenerateSampleViewSourceCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateSampleViewSourceCode.swift; sourceTree = "<group>"; };
0042E24228E4BF8F001F33D6 /* ShowViewshedFromPointInSceneView.Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowViewshedFromPointInSceneView.Model.swift; sourceTree = "<group>"; };
Expand All @@ -397,6 +399,7 @@
00B04272282EC59E0072E1B4 /* AboutView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
00B042E5282EDC690072E1B4 /* SetBasemapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetBasemapView.swift; sourceTree = "<group>"; };
00B04FB4283EEBA80026C882 /* DisplayOverviewMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayOverviewMapView.swift; sourceTree = "<group>"; };
00C7993A2A845AAF00AFE342 /* Sidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar.swift; sourceTree = "<group>"; };
00C94A0C28B53DE1004E42D9 /* raster-file */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "raster-file"; sourceTree = "<group>"; };
00CB9137284814A4005C2C5D /* SearchWithGeocodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchWithGeocodeView.swift; sourceTree = "<group>"; };
00CCB8A2285AAD7D00BBAB70 /* DowloadPortalItemData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DowloadPortalItemData.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -445,10 +448,7 @@
883C121429C9136600062FF9 /* DownloadPreplannedMapAreaView.MapPicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadPreplannedMapAreaView.MapPicker.swift; sourceTree = "<group>"; };
88F93CC029C3D59C0006B28E /* SketchOnMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SketchOnMapView.swift; sourceTree = "<group>"; };
D701D72B2A37C7F7006FF0C8 /* bradley_low_3ds */ = {isa = PBXFileReference; lastKnownFileType = folder; path = bradley_low_3ds; sourceTree = "<group>"; };
D70BE5782A5624A80022CA02 /* CategoryGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryGridView.swift; sourceTree = "<group>"; };
D70BE57E2A5753B70022CA02 /* SampleListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleListView.swift; sourceTree = "<group>"; };
D70BE5822A5766C90022CA02 /* CategoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryView.swift; sourceTree = "<group>"; };
D70BE5872A5787530022CA02 /* CategoryView+Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CategoryView+Search.swift"; sourceTree = "<group>"; };
D70BE5782A5624A80022CA02 /* CategoriesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoriesView.swift; sourceTree = "<group>"; };
D710996C2A27D9210065A1C1 /* DensifyAndGeneralizeGeometryView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DensifyAndGeneralizeGeometryView.swift; sourceTree = "<group>"; };
D710996F2A2802FA0065A1C1 /* DensifyAndGeneralizeGeometryView.SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DensifyAndGeneralizeGeometryView.SettingsView.swift; sourceTree = "<group>"; };
D722BD212A420DAD002C2087 /* ShowExtrudedFeaturesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowExtrudedFeaturesView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -523,12 +523,13 @@
isa = PBXGroup;
children = (
00B04272282EC59E0072E1B4 /* AboutView.swift */,
D70BE5782A5624A80022CA02 /* CategoryGridView.swift */,
D70BE5822A5766C90022CA02 /* CategoryView.swift */,
D70BE5782A5624A80022CA02 /* CategoriesView.swift */,
00E5400D27F3CCA100CF66D5 /* ContentView.swift */,
000558092817C51E00224BC6 /* SampleDetailView.swift */,
E041ABD6287DB04D0056009B /* SampleInfoView.swift */,
D70BE57E2A5753B70022CA02 /* SampleListView.swift */,
00273CF52A82AB8700A7A77D /* SampleRow.swift */,
00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */,
00C7993A2A845AAF00AFE342 /* Sidebar.swift */,
E041ABBF287CA9F00056009B /* WebView.swift */,
);
path = Views;
Expand All @@ -537,7 +538,6 @@
00181B442846AD3900654571 /* Extensions */ = {
isa = PBXGroup;
children = (
D70BE5872A5787530022CA02 /* CategoryView+Search.swift */,
E08953F02891899600E077CF /* EnvironmentValues+SampleInfoVisibility.swift */,
00181B452846AD7100654571 /* View+Alert.swift */,
E0082216287755AC002AD138 /* View+Sheet.swift */,
Expand Down Expand Up @@ -1590,11 +1590,10 @@
D752D9462A3A6F80003EB25E /* MonitorChangesToMapLoadStatusView.swift in Sources */,
E0082217287755AC002AD138 /* View+Sheet.swift in Sources */,
00181B462846AD7100654571 /* View+Alert.swift in Sources */,
00273CF62A82AB8700A7A77D /* SampleRow.swift in Sources */,
D7ABA2FF2A32881C0021822B /* ShowViewshedFromGeoelementInSceneView.swift in Sources */,
E0FE32E728747778002C6ACA /* BrowseBuildingFloorsView.swift in Sources */,
D70BE5882A5787530022CA02 /* CategoryView+Search.swift in Sources */,
D752D95F2A3BCE06003EB25E /* DisplayMapFromPortalItemView.swift in Sources */,
D70BE5832A5766CA0022CA02 /* CategoryView.swift in Sources */,
1CAB8D4B2A3CEAB0002AA649 /* RunValveIsolationTraceView.Model.swift in Sources */,
E070A0A3286F3B6000F2B606 /* DownloadPreplannedMapAreaView.swift in Sources */,
D77570C02A2942F800F490CD /* AnimateImagesWithImageOverlayView.swift in Sources */,
Expand Down Expand Up @@ -1623,6 +1622,7 @@
E041ABC0287CA9F00056009B /* WebView.swift in Sources */,
E088E1572862579D00413100 /* SetSurfacePlacementModeView.swift in Sources */,
1CAF831F2A20305F000E1E60 /* ShowUtilityAssociationsView.swift in Sources */,
00C7993B2A845AAF00AFE342 /* Sidebar.swift in Sources */,
E004A6C128414332002A1FE6 /* SetViewpointRotationView.swift in Sources */,
883C121529C9136600062FF9 /* DownloadPreplannedMapAreaView.MapPicker.swift in Sources */,
1C9B74C929DB43580038B06F /* ShowRealisticLightAndShadowsView.swift in Sources */,
Expand All @@ -1633,7 +1633,7 @@
108EC04129D25B2C000F35D0 /* QueryFeatureTableView.swift in Sources */,
00B04FB5283EEBA80026C882 /* DisplayOverviewMapView.swift in Sources */,
D7CC33FF2A31475C00198EDF /* ShowLineOfSightBetweenPointsView.swift in Sources */,
D70BE5792A5624A80022CA02 /* CategoryGridView.swift in Sources */,
D70BE5792A5624A80022CA02 /* CategoriesView.swift in Sources */,
4D2ADC5D29C4F612003B367F /* ChangeMapViewBackgroundView.SettingsView.swift in Sources */,
75DD739529D38B1B0010229D /* NavigateRouteView.swift in Sources */,
D75362D22A1E886700D83028 /* ApplyUniqueValueRendererView.swift in Sources */,
Expand All @@ -1657,7 +1657,6 @@
00B042E8282EDC690072E1B4 /* SetBasemapView.swift in Sources */,
E004A6E62846A61F002A1FE6 /* StyleGraphicsWithSymbolsView.swift in Sources */,
E088E1742863B5F800413100 /* GenerateOfflineMapView.swift in Sources */,
D70BE57F2A5753B70022CA02 /* SampleListView.swift in Sources */,
0074ABC428174F430037244A /* Sample.swift in Sources */,
00A7A14A2A2FC5B700F035F7 /* DisplayContentOfUtilityNetworkContainerView.Model.swift in Sources */,
E004A6F0284E4B9B002A1FE6 /* DownloadVectorTilesToLocalCacheView.swift in Sources */,
Expand All @@ -1667,6 +1666,7 @@
1C19B4F52A578E46001D2506 /* CreateLoadReportView.Model.swift in Sources */,
0042E24528E4F82C001F33D6 /* ShowViewshedFromPointInSceneView.ViewshedSettingsView.swift in Sources */,
1C9B74D929DB54560038B06F /* ChangeCameraControllerView.swift in Sources */,
00273CF42A82AB5900A7A77D /* SamplesSearchView.swift in Sources */,
D78666AD2A2161F100C60110 /* FindNearestVertexView.swift in Sources */,
D744FD172A2112D90084A66C /* CreateConvexHullAroundPointsView.swift in Sources */,
00CB9138284814A4005C2C5D /* SearchWithGeocodeView.swift in Sources */,
Expand Down
14 changes: 13 additions & 1 deletion Scripts/GenerateSampleViewSourceCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ private struct SampleMetadata: Decodable {
let offlineData: [String]?
/// The tags and relevant APIs of the sample.
let keywords: [String]
/// The relevant APIs of the sample.
let relevantApis: [String]
}

extension SampleMetadata {
Expand All @@ -57,6 +59,16 @@ extension SampleMetadata {
// E.g., DisplayMapView -> DisplayMap
viewName.dropLast(4)
}

/// The tags of a sample.
/// - Note: See common-samples/wiki/README.metadata.json#keywords.
/// The keywords in the sample metadata combines Tags and Relevant APIs
/// from the README. This is done in Scripts/CI/common.py by appending the
/// relevant APIs to the tags. Therefore, dropping the relevant APIs will
/// give the tags.
var tags: Array<String>.SubSequence {
keywords.dropLast(relevantApis.count)
}
}

// MARK: Script Entry
Expand Down Expand Up @@ -116,7 +128,7 @@ private let sampleStructs = sampleMetadata
var category: String { \"\(sample.category)\" }
var description: String { \"\(sample.description)\" }
var snippets: [String] { \(sample.snippets) }
var tags: Set<String> { \(sample.keywords) }
var tags: Set<String> { \(sample.tags) }
\(portalItemIDs.isEmpty ? "" : "var hasDependencies: Bool { true }\n")
func makeBody() -> AnyView { .init(\(sample.viewName)()) }
}
Expand Down
27 changes: 0 additions & 27 deletions Shared/Supporting Files/Extensions/CategoryView+Search.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Shared/Supporting Files/Models/Sample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protocol Sample {
/// The relative paths to the code snippets.
var snippets: [String] { get }

/// The tags and relevant APIs of the sample.
/// The tags of the sample.
var tags: Set<String> { get }

/// A Boolean value that indicates whether a sample has offline data dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import SwiftUI

struct CategoryGridView: View {
struct CategoriesView: View {
/// All samples that will be shown in the categories.
private let samples: [Sample]

Expand All @@ -38,7 +38,7 @@ struct CategoryGridView: View {
LazyVGrid(columns: columns) {
ForEach(categories, id: \.self) { category in
NavigationLink {
SampleListView(samples: samples.filter { $0.category == category })
CategoryList(samples: samples.filter { $0.category == category })
.navigationTitle(category)
} label: {
CategoryTitleView(category: category)
Expand All @@ -49,12 +49,29 @@ struct CategoryGridView: View {
.buttonStyle(.plain)
}
}
.padding(8)
.padding()
}
}
}

private extension CategoryGridView {
private extension CategoriesView {
struct CategoryList: View {
/// The samples in a category.
let samples: [Sample]

var body: some View {
List(samples, id: \.name) { sample in
NavigationLink {
SampleDetailView(sample: sample)
.id(sample.name)
} label: {
SampleRow(name: AttributedString(sample.name), description: AttributedString(sample.description))
}
}
.listStyle(.sidebar)
}
}

struct CategoryTitleView: View {
/// The category name used to load the images from assets.
let category: String
Expand Down
4 changes: 2 additions & 2 deletions Shared/Supporting Files/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct ContentView: View {
}

var sidebar: some View {
CategoryView(samples: samples, query: $query)
.searchable(text: $query, prompt: "Search By Sample Name")
Sidebar(samples: samples, query: query)
.searchable(text: $query)
}

var detail: some View {
Expand Down
Loading

0 comments on commit 452c08e

Please sign in to comment.