Skip to content

Use the host search function - #7912

Merged
User-Zhaoyang merged 7 commits into
DynamoDS:LibraryReorgfrom
User-Zhaoyang:LibraryReorg
Jun 8, 2017
Merged

User-Zhaoyang merged 7 commits into
DynamoDS:LibraryReorgfrom
User-Zhaoyang:LibraryReorg

Conversation

@User-Zhaoyang

@User-Zhaoyang User-Zhaoyang commented May 31, 2017 •

Copy link
Copy Markdown
Contributor

Purpose

This is to implement to use the old search function.

Here is the old search result when "list.s" is input in the search box:
image

Here is the search result now:
image

The order and content(only part of the result is in the view) are the same.

Declarations

Check these if you believe they are true

  • The code base is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning, and are documented in the API Changes document.

Reviewers

@sharadkjaiswal

FYIs

@benglin @riteshchandawar @Racel

…o LibraryReorg

# Conflicts:
#	src/LibraryViewExtension/Handlers/NodeItemDataProvider.cs
#	src/LibraryViewExtension/LibraryViewController.cs
{
supportedSchemes.Add(provider.Scheme);
resourceProviders.Add(baseurl, provider);
if (!resourceProviders.ContainsKey(baseurl))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should not be changing resource provider for the same url. Url should have additional data to differentiate the different scenarios.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, I don't think we should allow updating the old provider.

/// Provides json resource data for all the loaded nodes
/// </summary>
class NodeItemDataProvider : ResourceProviderBase
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would rather subclass this class to implement node search data provider.

refreshLibraryView(libController);

libController.searchLibraryItemsHandler = function (text, callback) {
let url = csharpController.searchLibraryItems(text);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can directly have a url to provide a search service as http://localhost/nodesearch/{searchText} and register a provider for http://localhost/nodesearch/

…o LibraryReorg

# Conflicts:
#	src/LibraryViewExtension/Handlers/NodeItemDataProvider.cs
@@ -86,7 +100,6 @@ public static string GetFullyQualifiedName(NodeSearchElement element)
/// <returns></returns>
internal LoadedTypeItem CreateLoadedTypeItem(NodeSearchElement element)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can use Generics to implement this method so that you don't have to use the same code again for LoadedTypeItemExtended class.
internal T CreateLoadedTypeItem<T>(NodeSearchElement element) where T : LoadedTypeItem, new()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You mean the constructor of LoadedTypeItem?

/// </summary>
/// <param name="element"></param>
/// <param name="item"></param>
protected void InitializeLoadedTypeItem(NodeSearchElement element, LoadedTypeItem item)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure why do we need this method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the one that after an instance of LoadedTypeItem or its derived class is created, the data need to be initialized to set iconUrl or update fully qualified name. This will be the same in the base and the derived classes.

{
supportedSchemes.Add(provider.Scheme);
resourceProviders.Add(baseurl, provider);
if (!resourceProviders.ContainsKey(baseurl))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, I don't think we should allow updating the old provider.

var uri = new Uri(url);
var pathAndQuery = uri.PathAndQuery;
var index = url.IndexOf(serviceIdentifier);
var text = url.Substring(index + serviceIdentifier.Length + 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what if the passed url is /search/point/bycoordinates, the text becomes point/bycoordinates?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you might consider having a method IEnumerable<LoadedTypeItem> GetLoadedTypeDataForRequest(Uri requestUri) then the base class implementation doesn't need to be overridden. Here is how the base class implementation would look like.

public override Stream GetResource(IRequest request, out string extension)
{
   var uri = new Uri(request.Url);
   var items = GetLoadedTypeDataForRequest(uri);
   extension = "json";
   return GetLoadedTypeDataStream(items);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The old search behavior allows input text like "point/bycoordinates".

@User-Zhaoyang User-Zhaoyang Jun 2, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For the second point, then you need to override GetLoadedTypeDataForRequest. But as GetResource is only a function with few lines, why not override it directly?

/// <param name="element"></param>
/// <param name="w"></param>
/// <returns></returns>
private LoadedTypeItem CreateLoadedTypeItemExtended(NodeSearchElement element, int w = 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this method not returning LoadedTypeItemExtended instead of LoadedTypeItem?

var sw = new StreamWriter(ms);
var serializer = new JsonSerializer();

var data = CreateObjectForSerialization(searchEntries);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if this method accepts list of LoadedTypeItem instead of searchEntities, then you won't need an additional method CreateObjectForSerialization?
protected Stream GetLoadedTypeDataStream(IEnumerable<LoadedTypeItem> items) {...}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CreateObjectForSerialization basically creates different instance of LoadedTypeData in the base class and the derived class.

}

class LoadedTypeData
class LoadedTypeData<T>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you might want to put a condition for T to be derived from LoadedTypeItem

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am wondering if it would have worked as it is when loadedTypes internally contains the list of LoadedTypeItemExtended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is how template means? If it does not work, I doubt the reason why this language feature exists.

@User-Zhaoyang User-Zhaoyang Jun 2, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But if you mean LoadedTypeData<A> can not be casted to LoadedTypeData<B> directly, then you are right. But this is not the intention here.

@User-Zhaoyang

Copy link
Copy Markdown
Contributor Author

@sharadkjaiswal
As discussed, I am merging this.

@User-Zhaoyang
User-Zhaoyang merged commit a56a7bb into DynamoDS:LibraryReorg Jun 8, 2017
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.

2 participants