Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] console - add pagination #254

Merged
merged 6 commits into from May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -250,4 +250,5 @@ trunk serve

#### Running with a cloud backend

You can also run the frontend with a backend in the cloud (or local cluster, e.g. minikube).
You can also run the frontend with a backend in the cloud (or local cluster, e.g. minikube).
To do so, you can create a `console-frontend/dev/endpoints/backend.local.json` file and populate it with the API and SSO urls of your drogue instance.
71 changes: 12 additions & 59 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion console-frontend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion console-frontend/Cargo.toml
Expand Up @@ -91,7 +91,7 @@ opt-level = 's'
lto = true

[patch.crates-io]
patternfly-yew = { git = "https://github.com/ctron/patternfly-yew", rev = "57829945179d823f754314d870290edc3de9701d" } # FIXME: awaiting release
patternfly-yew = { git = "https://github.com/ctron/patternfly-yew", rev = "4d94074a35b35f7f237effc68bead6dc3b79567a" } # FIXME: awaiting release
#patternfly-yew = { path = "../../patternfly-yew" }

drogue-client = { git = "https://github.com/drogue-iot/drogue-client", rev = "788e3ba00b675b15e3adcd83836f6e2b8f678bc3" } # FIXME: awaiting release
Expand Down
11 changes: 9 additions & 2 deletions console-frontend/src/backend/mod.rs
Expand Up @@ -85,6 +85,7 @@ impl BackendInformation {
&self,
method: http::Method,
path: S,
query: Vec<(&str, &str)>,
payload: IN,
headers: Vec<(String, String)>,
handler: H,
Expand All @@ -100,6 +101,10 @@ impl BackendInformation {
request = request.header(k.into(), v.into());
}

for (k, v) in query {
request = request.query(k.into(), v.into());
}

request = request
.body(payload)
.map_err(RequestError::PayloadConversion)?;
Expand All @@ -118,6 +123,7 @@ impl AuthenticatedBackend {
&self,
method: http::Method,
path: S,
query: Vec<(&str, &str)>,
payload: IN,
headers: Vec<(String, String)>,
handler: H,
Expand All @@ -127,13 +133,14 @@ impl AuthenticatedBackend {
IN: RequestPayload,
H: RequestHandler<anyhow::Result<Response>>,
{
self.request_with(method, path, payload, headers, handler)
self.request_with(method, path, query, payload, headers, handler)
}

pub fn request_with<S, IN, H>(
&self,
method: http::Method,
path: S,
query: Vec<(&str, &str)>,
payload: IN,
mut headers: Vec<(String, String)>,
handler: H,
Expand All @@ -147,7 +154,7 @@ impl AuthenticatedBackend {
headers.push(("Authorization".into(), bearer));

self.backend
.unauth_request_with(method, path, payload, headers, handler)
.unauth_request_with(method, path, query, payload, headers, handler)
}
}

Expand Down
23 changes: 22 additions & 1 deletion console-frontend/src/backend/request/mod.rs
Expand Up @@ -33,6 +33,7 @@ pub struct RequestBuilder<'b> {
///
/// *Note:* This may also be a relative URL.
url: String,
query: Vec<(Cow<'b, str>, Cow<'b, str>)>,
headers: Vec<(Cow<'b, str>, Cow<'b, str>)>,

body: Option<JsValue>,
Expand All @@ -50,6 +51,7 @@ impl<'b> RequestBuilder<'b> {
method,
url: url.into(),
headers: vec![],
query: vec![],

body: None,
content_type: None,
Expand All @@ -61,6 +63,11 @@ impl<'b> RequestBuilder<'b> {
}
}

pub fn query(mut self, key: Cow<'b, str>, value: Cow<'b, str>) -> Self {
self.query.push((key, value));
self
}

pub fn header(mut self, key: Cow<'b, str>, value: Cow<'b, str>) -> Self {
self.headers.push((key, value));
self
Expand Down Expand Up @@ -151,10 +158,24 @@ impl Request {
init.signal(Some(&abort_controller.signal()));
}

let query = if !request.query.is_empty() {
let mut query = Vec::<String>::new();
for (k, v) in request.query {
query.push(format!("{}={}", k, v));
}
Some(query.join("&"))
} else {
None
};

init.body(request.body.as_ref());

let window = gloo_utils::window();
let url = request.url.to_string();
let url = if let Some(query) = query {
format!("{}?{}", request.url.to_string(), query)
} else {
request.url.to_string()
};
Self {
url,
init,
Expand Down
1 change: 1 addition & 0 deletions console-frontend/src/components/about.rs
Expand Up @@ -75,6 +75,7 @@ impl AboutModal {
Ok(ctx.props().backend.request(
Method::GET,
"/.well-known/drogue-version",
vec![],
Nothing,
vec![],
ctx.callback_api::<Json<DrogueVersion>, _>(|response| match response {
Expand Down
1 change: 1 addition & 0 deletions console-frontend/src/examples/mod.rs
Expand Up @@ -138,6 +138,7 @@ impl ExamplePage {
Ok(ctx.props().backend.request(
Method::GET,
"/api/console/v1alpha1/info",
vec![],
Nothing,
vec![],
ctx.callback_api::<Json<Endpoints>, _>(|response| match response {
Expand Down
3 changes: 3 additions & 0 deletions console-frontend/src/pages/access_tokens.rs
Expand Up @@ -178,6 +178,7 @@ impl AccessTokens {
Ok(ctx.props().backend.request(
Method::GET,
"/api/tokens/v1alpha1",
vec![],
Nothing,
vec![],
ctx.callback_api::<Json<Vec<AccessToken>>, _>(move |response| match response {
Expand All @@ -204,6 +205,7 @@ impl AccessTokens {
Ok(ctx.props().backend.request(
Method::DELETE,
format!("/api/tokens/v1alpha1/{}", token.prefix),
vec![],
Nothing,
vec![],
ctx.callback_api::<(), _>(move |response| match response {
Expand All @@ -217,6 +219,7 @@ impl AccessTokens {
Ok(ctx.props().backend.request(
Method::POST,
"/api/tokens/v1alpha1",
vec![],
Nothing,
vec![],
ctx.callback_api::<Json<AccessTokenCreated>, _>(move |response| match response {
Expand Down
1 change: 1 addition & 0 deletions console-frontend/src/pages/apps/create.rs
Expand Up @@ -118,6 +118,7 @@ impl CreateDialog {
Ok(ctx.props().backend.request(
Method::POST,
"/api/registry/v1alpha1/apps",
vec![],
Json(payload),
vec![],
ctx.callback_api::<(), _>(move |response| match response {
Expand Down
5 changes: 5 additions & 0 deletions console-frontend/src/pages/apps/details/admin.rs
Expand Up @@ -304,6 +304,7 @@ impl Admin {
"/api/admin/v1alpha1/apps/{}/members",
url_encode(&ctx.props().name)
),
vec![],
Nothing,
vec![],
ctx.callback_api::<Json<Members>, _>(move |response| match response {
Expand All @@ -328,6 +329,7 @@ impl Admin {
"/api/admin/v1alpha1/apps/{}/members",
url_encode(&ctx.props().name)
),
vec![],
Json(members),
vec![],
ctx.callback_api::<(), _>(move |response| match response {
Expand Down Expand Up @@ -369,6 +371,7 @@ impl Admin {
"/api/admin/v1alpha1/apps/{}/transfer-ownership",
url_encode(&ctx.props().name)
),
vec![],
Json(payload),
vec![],
ctx.callback_api::<(), _>(move |response| match response {
Expand Down Expand Up @@ -401,6 +404,7 @@ impl Admin {
"/api/admin/v1alpha1/apps/{}/transfer-ownership",
url_encode(&ctx.props().name)
),
vec![],
Nothing,
vec![],
ctx.callback_api::<(), _>(|response| match response {
Expand All @@ -417,6 +421,7 @@ impl Admin {
"/api/admin/v1alpha1/apps/{}/transfer-ownership",
url_encode(&ctx.props().name)
),
vec![],
Nothing,
vec![],
ctx.callback_api::<Option<Json<TransferOwnership>>, _>(move |response| {
Expand Down
3 changes: 3 additions & 0 deletions console-frontend/src/pages/apps/details/mod.rs
Expand Up @@ -147,6 +147,7 @@ impl Details {
"/api/registry/v1alpha1/apps/{}",
url_encode(&ctx.props().name)
),
vec![],
Nothing,
vec![],
ctx.callback_api::<Json<Application>, _>(move |response| match response {
Expand All @@ -160,6 +161,7 @@ impl Details {
"/api/admin/v1alpha1/apps/{}/members",
url_encode(&ctx.props().name)
),
vec![],
Nothing,
vec![],
ctx.callback_api::<(), _>(move |response| match response {
Expand All @@ -181,6 +183,7 @@ impl Details {
"/api/registry/v1alpha1/apps/{}",
url_encode(&ctx.props().name)
),
vec![],
Json(&app),
vec![],
ctx.callback_api::<(), _>(move |response| match response {
Expand Down