frontend: Add UUID and creation date

This exposes the new info in the GraphQL API, and adds it to the frontend.
This commit is contained in:
Iván Izaguirre 2022-07-21 12:10:37 +02:00 committed by GitHub
parent 4ba0db4e9e
commit 5c584536b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 88 additions and 3 deletions

View File

@ -2,6 +2,8 @@ query GetGroupDetails($id: Int!) {
group(groupId: $id) {
id
displayName
creationDate
uuid
users {
id
displayName

View File

@ -2,5 +2,6 @@ query GetGroupList {
groups {
id
displayName
creationDate
}
}

View File

@ -6,6 +6,7 @@ query GetUserDetails($id: String!) {
firstName
lastName
creationDate
uuid
groups {
id
displayName

View File

@ -68,6 +68,45 @@ impl GroupDetails {
}
}
fn view_details(&self, g: &Group) -> Html {
html! {
<>
<h3>{g.display_name.to_string()}</h3>
<div class="py-3">
<form class="form">
<div class="form-group row mb-3">
<label for="displayName"
class="form-label col-4 col-form-label">
{"Group: "}
</label>
<div class="col-8">
<span id="groupId" class="form-constrol-static">{g.display_name.to_string()}</span>
</div>
</div>
<div class="form-group row mb-3">
<label for="creationDate"
class="form-label col-4 col-form-label">
{"Creation date: "}
</label>
<div class="col-8">
<span id="creationDate" class="form-constrol-static">{g.creation_date.date().naive_local()}</span>
</div>
</div>
<div class="form-group row mb-3">
<label for="uuid"
class="form-label col-4 col-form-label">
{"UUID: "}
</label>
<div class="col-8">
<span id="uuid" class="form-constrol-static">{g.uuid.to_string()}</span>
</div>
</div>
</form>
</div>
</>
}
}
fn view_user_list(&self, g: &Group) -> Html {
let make_user_row = |user: &User| {
let user_id = user.id.clone();
@ -92,7 +131,6 @@ impl GroupDetails {
};
html! {
<>
<h3>{g.display_name.to_string()}</h3>
<h5 class="fw-bold">{"Members"}</h5>
<div class="table-responsive">
<table class="table table-striped">
@ -201,6 +239,7 @@ impl Component for GroupDetails {
(Some(u), error) => {
html! {
<div>
{self.view_details(u)}
{self.view_user_list(u)}
{self.view_add_user_button(u)}
{self.view_messages(error)}

View File

@ -97,7 +97,8 @@ impl GroupTable {
<table class="table table-striped">
<thead>
<tr>
<th>{"Groups"}</th>
<th>{"Group name"}</th>
<th>{"Creation date"}</th>
<th>{"Delete"}</th>
</tr>
</thead>
@ -122,6 +123,9 @@ impl GroupTable {
{&group.display_name}
</Link>
</td>
<td>
{&group.creation_date.date().naive_local()}
</td>
<td>
<DeleteGroup
group=group.clone()

View File

@ -195,6 +195,15 @@ impl Component for UserDetailsForm {
<span id="creationDate" class="form-constrol-static">{&self.common.user.creation_date.date().naive_local()}</span>
</div>
</div>
<div class="form-group row mb-3">
<label for="uuid"
class="form-label col-4 col-form-label">
{"UUID: "}
</label>
<div class="col-8">
<span id="creationDate" class="form-constrol-static">{&self.common.user.uuid}</span>
</div>
</div>
<div class="form-group row justify-content-center">
<button
type="submit"
@ -267,6 +276,7 @@ impl UserDetailsForm {
first_name: model.first_name,
last_name: model.last_name,
creation_date: self.common.user.creation_date,
uuid: self.common.user.uuid.clone(),
groups: self.common.user.groups.clone(),
};
self.just_updated = true;

View File

@ -17,6 +17,8 @@ type Mutation {
type Group {
id: Int!
displayName: String!
creationDate: DateTimeUtc!
uuid: String!
"The groups to which this user belongs."
users: [User!]!
}
@ -67,6 +69,7 @@ type User {
firstName: String!
lastName: String!
creationDate: DateTimeUtc!
uuid: String!
"The groups to which this user belongs."
groups: [Group!]!
}

View File

@ -221,6 +221,10 @@ impl<Handler: BackendHandler + Sync> User<Handler> {
self.user.creation_date
}
fn uuid(&self) -> &str {
self.user.uuid.as_str()
}
/// The groups to which this user belongs.
async fn groups(&self, context: &Context<Handler>) -> FieldResult<Vec<Group<Handler>>> {
let span = debug_span!("[GraphQL query] user::groups");
@ -260,6 +264,7 @@ pub struct Group<Handler: BackendHandler> {
group_id: i32,
display_name: String,
creation_date: chrono::DateTime<chrono::Utc>,
uuid: String,
members: Option<Vec<String>>,
_phantom: std::marker::PhantomData<Box<Handler>>,
}
@ -272,6 +277,12 @@ impl<Handler: BackendHandler + Sync> Group<Handler> {
fn display_name(&self) -> String {
self.display_name.clone()
}
fn creation_date(&self) -> chrono::DateTime<chrono::Utc> {
self.creation_date
}
fn uuid(&self) -> String {
self.uuid.clone()
}
/// The groups to which this user belongs.
async fn users(&self, context: &Context<Handler>) -> FieldResult<Vec<User<Handler>>> {
let span = debug_span!("[GraphQL query] group::users");
@ -300,6 +311,7 @@ impl<Handler: BackendHandler> From<GroupDetails> for Group<Handler> {
group_id: group_details.group_id.0,
display_name: group_details.display_name,
creation_date: group_details.creation_date,
uuid: group_details.uuid.into_string(),
members: None,
_phantom: std::marker::PhantomData,
}
@ -312,6 +324,7 @@ impl<Handler: BackendHandler> From<DomainGroup> for Group<Handler> {
group_id: group.id.0,
display_name: group.display_name,
creation_date: group.creation_date,
uuid: group.uuid.into_string(),
members: Some(group.users.into_iter().map(UserId::into_string).collect()),
_phantom: std::marker::PhantomData,
}
@ -350,8 +363,12 @@ mod tests {
user(userId: "bob") {
id
email
creationDate
uuid
groups {
id
creationDate
uuid
}
}
}"#;
@ -363,6 +380,8 @@ mod tests {
Ok(DomainUser {
user_id: UserId::new("bob"),
email: "bob@bobbers.on".to_string(),
creation_date: chrono::Utc.timestamp_millis(42),
uuid: crate::uuid!("b1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"),
..Default::default()
})
});
@ -391,7 +410,13 @@ mod tests {
"user": {
"id": "bob",
"email": "bob@bobbers.on",
"groups": [{"id": 3}]
"creationDate": "1970-01-01T00:00:00.042+00:00",
"uuid": "b1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
"groups": [{
"id": 3,
"creationDate": "1970-01-01T00:00:00.000000042+00:00",
"uuid": "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8"
}]
}
}),
vec![]