@@ -12,43 +12,122 @@ class Link(BaseModel):
12
12
title : str = Field (..., description = 'The name of the URL.' )
13
13
url : str = Field (..., description = 'The URL.' )
14
14
15
+ @classmethod
16
+ def detail (cls , title : str , url : str ) -> 'Link' :
17
+ return cls (type = 'ui-detail' , title = title , url = url )
15
18
16
- class ProjectLinksManager :
19
+ @classmethod
20
+ def dashboard (cls , title : str , url : str ) -> 'Link' :
21
+ return cls (type = 'ui-dashboard' , title = title , url = url )
17
22
23
+ @classmethod
24
+ def docs (cls , title : str , url : str ) -> 'Link' :
25
+ return cls (type = 'docs' , title = title , url = url )
26
+
27
+
28
+ class ProjectLinksManager :
18
29
FLOW_DOCUMENTATION_URL = 'https://help.keboola.com/flows/'
19
30
20
31
def __init__ (self , base_url : str , project_id : str ):
21
- self .base_url = base_url
22
- self .project_id = project_id
32
+ self ._base_url = base_url
33
+ self ._project_id = project_id
23
34
24
35
@classmethod
25
36
async def from_client (cls , client : KeboolaClient ) -> 'ProjectLinksManager' :
26
37
base_url = client .storage_client .base_api_url
27
38
project_id = await client .storage_client .project_id ()
28
- return ProjectLinksManager (base_url , project_id )
39
+ return cls (base_url = base_url , project_id = project_id )
29
40
30
- def get_flow_url (self , flow_id : str | int ) -> str :
31
- """Get the UI detail URL for a specific flow."""
32
- return f'{ self .base_url } /admin/projects/{ self .project_id } /flows/{ flow_id } '
41
+ def _url (self , path : str ) -> str :
42
+ return f'{ self ._base_url } /admin/projects/{ self ._project_id } /{ path } '
33
43
34
- def get_flows_dashboard_url (self ) -> str :
35
- """Get the UI dashboard URL for all flows in a project."""
36
- return f'{ self .base_url } /admin/projects/{ self .project_id } /flows'
37
-
38
- def get_project_url (self ) -> str :
39
- """Return the UI URL for accessing the project."""
40
- return f'{ self .base_url } /admin/projects/{ self .project_id } '
44
+ # --- Project ---
45
+ def get_project_detail_link (self ) -> Link :
46
+ return Link .detail (title = 'Project Dashboard' , url = self ._url ('' ))
41
47
42
48
def get_project_links (self ) -> list [Link ]:
43
- """Return a list of relevant links for a project."""
44
- project_url = self .get_project_url ()
45
- return [Link (type = 'ui-detail' , title = 'Project Dashboard' , url = project_url )]
49
+ return [self .get_project_detail_link ()]
50
+
51
+ # --- Flows ---
52
+ def get_flow_detail_link (self , flow_id : str | int , flow_name : str ) -> Link :
53
+ return Link .detail (title = f'Flow: { flow_name } ' , url = self ._url (f'flows/{ flow_id } ' ))
54
+
55
+ def get_flows_dashboard_link (self ) -> Link :
56
+ return Link .dashboard (title = 'Flows in the project' , url = self ._url ('flows' ))
57
+
58
+ def get_flows_docs_link (self ) -> Link :
59
+ return Link .docs (title = 'Documentation for Keboola Flows' , url = self .FLOW_DOCUMENTATION_URL )
46
60
47
61
def get_flow_links (self , flow_id : str | int , flow_name : str ) -> list [Link ]:
48
- """Get a list of relevant links for a flow, including detail, dashboard, and documentation."""
49
- flow_detail_url = Link (type = 'ui-detail' , title = f'Flow: { flow_name } ' , url = self .get_flow_url (flow_id ))
50
- flows_dashboard_url = Link (
51
- type = 'ui-dashboard' , title = 'Flows in the project' , url = self .get_flows_dashboard_url ()
62
+ return [
63
+ self .get_flow_detail_link (flow_id , flow_name ),
64
+ self .get_flows_dashboard_link (),
65
+ self .get_flows_docs_link (),
66
+ ]
67
+
68
+ # --- Components ---
69
+ def get_component_config_link (self , component_id : str , configuration_id : str , configuration_name : str ) -> Link :
70
+ return Link .detail (
71
+ title = f'Configuration: { configuration_name } ' , url = self ._url (f'components/{ component_id } /{ configuration_id } ' )
72
+ )
73
+
74
+ def get_component_configs_dashboard_link (self , component_id : str , component_name : str ) -> Link :
75
+ return Link .dashboard (
76
+ title = f'{ component_name } Configurations Dashboard' , url = self ._url (f'components/{ component_id } ' )
52
77
)
53
- documentation_url = Link (type = 'docs' , title = 'Documentation for Keboola Flows' , url = self .FLOW_DOCUMENTATION_URL )
54
- return [flow_detail_url , flows_dashboard_url , documentation_url ]
78
+
79
+ def get_used_components_link (
80
+ self
81
+ ) -> Link :
82
+ return Link .dashboard (
83
+ title = 'Used Components Dashboard' , url = self ._url ('components/configurations' )
84
+ )
85
+
86
+ def get_component_configuration_links (
87
+ self , component_id : str , configuration_id : str , configuration_name : str
88
+ ) -> list [Link ]:
89
+ return [
90
+ self .get_component_config_link (
91
+ component_id = component_id , configuration_id = configuration_id , configuration_name = configuration_name
92
+ ),
93
+ self .get_component_configs_dashboard_link (component_id = component_id , component_name = component_id ),
94
+ ]
95
+
96
+ # --- Transformations ---
97
+ def get_transformations_dashboard_link (self ) -> Link :
98
+ return Link .dashboard (
99
+ title = 'Transformations dashboard' , url = self ._url ('transformations-v2' )
100
+ )
101
+
102
+ # --- Jobs ---
103
+ def get_job_detail_link (self , job_id : str ) -> Link :
104
+ return Link .detail (title = f'Job: { job_id } ' , url = self ._url (f'queue/{ job_id } ' ))
105
+
106
+ def get_jobs_dashboard_link (self ) -> Link :
107
+ return Link .dashboard (title = 'Jobs in the project' , url = self ._url ('queue' ))
108
+
109
+ def get_job_links (self , job_id : str ) -> list [Link ]:
110
+ return [self .get_job_detail_link (job_id ), self .get_jobs_dashboard_link ()]
111
+
112
+ # --- Buckets ---
113
+ def get_bucket_detail_link (self , bucket_id : str , bucket_name : str ) -> Link :
114
+ return Link .detail (title = f'Bucket: { bucket_name } ' , url = self ._url (f'storage/{ bucket_id } ' ))
115
+
116
+ def get_bucket_dashboard_link (self ) -> Link :
117
+ return Link .dashboard (title = 'Buckets in the project' , url = self ._url ('storage' ))
118
+
119
+ def get_bucket_links (self , bucket_id : str , bucket_name : str ) -> list [Link ]:
120
+ return [
121
+ self .get_bucket_detail_link (bucket_id , bucket_name ),
122
+ self .get_bucket_dashboard_link (),
123
+ ]
124
+
125
+ # --- Tables ---
126
+ def get_table_detail_link (self , bucket_id : str , table_name : str ) -> Link :
127
+ return Link .detail (title = f'Table: { table_name } ' , url = self ._url (f'storage/{ bucket_id } /table/{ table_name } ' ))
128
+
129
+ def get_table_links (self , bucket_id : str , table_name : str ) -> list [Link ]:
130
+ return [
131
+ self .get_table_detail_link (bucket_id , table_name ),
132
+ self .get_bucket_detail_link (bucket_id = bucket_id , bucket_name = bucket_id ),
133
+ ]
0 commit comments