Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Remove Page::is_active()
Browse files Browse the repository at this point in the history
The purpose of this method is to prevent reloading of the current page if
the same URL is clicked. But this has downsides and, probably, no value:

* It is easy to forget to update this method.

* Needs access to models' fields which better be private.

* An opened URL is still clickable but confusingly has no effect.

* There is no way to reinitialize a page other than total reload (or go
  to another page first).

Signed-off-by: Igor Pashev <[email protected]>
  • Loading branch information
ip1981 committed Apr 27, 2020
1 parent 39a78f4 commit fa1970d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
2 changes: 1 addition & 1 deletion iml-gui/crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)
};
}
Msg::LoadPage => {
if model.loading.loaded() && !model.page.is_active(&model.route) {
if model.loading.loaded() {
model.page = (&model.records, &model.route).into();
orders.send_msg(Msg::UpdatePageTitle);
model.page.init(&model.records, &mut orders.proxy(Msg::Page));
Expand Down
40 changes: 1 addition & 39 deletions iml-gui/crate/src/page/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ pub mod users;
pub mod volume;
pub mod volumes;

use crate::{
route::{Route, RouteId},
GMsg,
};
use crate::{route::Route, GMsg};
use iml_wire_types::warp_drive::{ArcCache, ArcRecord, RecordId};
use seed::prelude::Orders;
use std::sync::Arc;
Expand Down Expand Up @@ -211,41 +208,6 @@ impl<'a> From<(&ArcCache, &Route<'a>)> for Page {
}

impl Page {
/// Is the given `Route` equivalent to the current page?
pub fn is_active<'a>(&self, route: &Route<'a>) -> bool {
match (route, self) {
(Route::About, Self::About)
| (Route::Filesystems, Self::Filesystems(_))
| (Route::Dashboard, Self::Dashboard(dashboard::Model { .. }))
| (Route::Jobstats, Self::Jobstats)
| (Route::Login, Self::Login(_))
| (Route::Mgt, Self::Mgts(_))
| (Route::NotFound, Self::NotFound)
| (Route::OstPools, Self::OstPools)
| (Route::PowerControl, Self::PowerControl)
| (Route::Servers, Self::Servers(_))
| (Route::Targets, Self::Targets)
| (Route::Users, Self::Users)
| (Route::Volumes, Self::Volumes(_)) => true,
(Route::OstPool(route_id), Self::OstPool(ostpool::Model { id }))
| (Route::Volume(route_id), Self::Volume(volume::Model { id })) => route_id == &RouteId::from(id),
(Route::Server(route_id), Self::Server(x)) => route_id == &RouteId::from(x.server.id),
(Route::User(route_id), Self::User(x)) => route_id == &RouteId::from(x.user.id),
(Route::Filesystem(route_id), Self::Filesystem(x)) => route_id == &RouteId::from(x.fs.id),
(Route::Target(route_id), Self::Target(x)) => route_id == &RouteId::from(x.target.id),
(Route::FsDashboard(route_id), Self::FsDashboard(x)) => {
let fs_dashboard::Model { fs_name, .. } = &**x;
&route_id.to_string() == fs_name
}
(Route::ServerDashboard(route_id), Self::ServerDashboard(server_dashboard::Model { host_name })) => {
&route_id.to_string() == host_name
}
(Route::TargetDashboard(route_id), Self::TargetDashboard(target_dashboard::Model { target_name, .. })) => {
&route_id.to_string() == target_name
}
_ => false,
}
}
/// Initialize the page. This gives a chance to initialize data when a page is switched to.
pub fn init(&mut self, cache: &ArcCache, orders: &mut impl Orders<Msg, GMsg>) {
match self {
Expand Down

0 comments on commit fa1970d

Please sign in to comment.