From 6f6d2501d07bdeb3a5d0e3e60e918ffd19d89e24 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Tue, 24 Mar 2020 09:59:32 +0200 Subject: [PATCH] Remove Page::is_active() 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 --- iml-gui/crate/src/lib.rs | 2 +- iml-gui/crate/src/page/mod.rs | 40 +---------------------------------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/iml-gui/crate/src/lib.rs b/iml-gui/crate/src/lib.rs index 9ec1101e73..16255dd16d 100644 --- a/iml-gui/crate/src/lib.rs +++ b/iml-gui/crate/src/lib.rs @@ -345,7 +345,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders) }; } Msg::LoadPage => { - if model.loading.loaded() && !model.page.is_active(&model.route) { + if model.loading.loaded() { model.page = (&model.records, &model.route).into(); model.breadcrumbs.push((model.route.to_href(), model.page.title())); orders.send_msg(Msg::UpdatePageTitle); diff --git a/iml-gui/crate/src/page/mod.rs b/iml-gui/crate/src/page/mod.rs index aac6d2569b..4cc26c08e3 100644 --- a/iml-gui/crate/src/page/mod.rs +++ b/iml-gui/crate/src/page/mod.rs @@ -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; @@ -198,41 +195,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) { match self {