Skip to content

Move path/patterns to common/routes. Export get*Path functions for correct value#39833

Merged
jfsiii merged 4 commits intoelastic:feature-integrations-managerfrom
jfsiii:named-route-improvements
Jul 1, 2019
Merged

Move path/patterns to common/routes. Export get*Path functions for correct value#39833
jfsiii merged 4 commits intoelastic:feature-integrations-managerfrom
jfsiii:named-route-improvements

Conversation

@jfsiii
Copy link
Copy Markdown
Contributor

@jfsiii jfsiii commented Jun 27, 2019

Summary

TL;DR: the client-side data fetching functions changed.

 export async function getIntegrationsList(): Promise<IntegrationList> {
-  const path = API_INTEGRATIONS_LIST;
+  const path = getListPath();
   const list: IntegrationList = await _fetch(path); 
 
   return list;
 }
 
 export async function getIntegrationInfoByKey(pkgkey: string): Promise<IntegrationInfo> {
-  const path = API_INTEGRATIONS_INFO.replace('{pkgkey}', pkgkey);
+  const path = getInfoPath(pkgkey);
   const info: IntegrationInfo = await _fetch(path);
 
   return info;

Problem

The client needs to know the location of certain routes (e.g. package list & detail APIs). The server clearly needs to know about these to create the handlers. How can we define route names & paths in one location without making the client & server worlds collide?

Proposal

Store the path/pattern that the server router uses from in common/routes.

The server imports the paths from common/routes and defines its route handlers in server/routes.

The client calls get*Path, with any parameters to substitute, and that function returns the correct path.


interface RouteDef {
path: string;
generatePath: (replacement?: string) => string;
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.

I should note this is “works for the 3 cases we have now”-level code. We’ll come back to this and change the shape as required.

Copy link
Copy Markdown
Member

@jasonrhodes jasonrhodes left a comment

Choose a reason for hiding this comment

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

Looks good, just a few changes/comments to work through. My overall reaction is this may be a bit more than what we need right now to get something simple off the ground, but I see the advantages too.

Simple. Works for now. Easy to delete later.
@jfsiii jfsiii requested a review from jasonrhodes June 29, 2019 14:20
@jfsiii
Copy link
Copy Markdown
Contributor Author

jfsiii commented Jun 29, 2019

@jasonrhodes mind taking another look? I made it much closer to what we’re currently doing, but still moved knowledge/work out of the views.

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@jfsiii jfsiii changed the title Lift server/routes up to common/routes. Server binds handlers to those Add common/routes for path/patterns. Also exports get*Path functions to correct value Jun 29, 2019
@jfsiii jfsiii changed the title Add common/routes for path/patterns. Also exports get*Path functions to correct value Move path/patterns to common/routes. Export get*Path functions for correct value Jun 29, 2019
Copy link
Copy Markdown
Member

@jasonrhodes jasonrhodes left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for simplifying. 👍

@jfsiii jfsiii merged commit 73d479e into elastic:feature-integrations-manager Jul 1, 2019
@jen-huang jen-huang added the Team:Fleet Team label for Observability Data Collection Fleet team label Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team:Fleet Team label for Observability Data Collection Fleet team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants