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

Add banner for scheduled maintenance #7284

Merged
merged 25 commits into from
Sep 18, 2023
Merged

Add banner for scheduled maintenance #7284

merged 25 commits into from
Sep 18, 2023

Conversation

fm3
Copy link
Member

@fm3 fm3 commented Aug 17, 2023

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

Backend:

  • Create new maintenance with curl -X POST 'http://localhost:9000/api/maintenances' -H 'X-Auth-Token: secretSampleUserToken' -H "Content-Type: application/json" -d '{"startTime":1692272319000, "endTime":1692272320000, "message":"a message!"}' (adapt timestamps to something in the future or current, use https://www.epochconverter.com/ for millisecond unix timestamps)
  • delete and update routes, as well as readOne and listAll are also only available for super users
    • curl -X DELETE 'http://localhost:9000/api/maintenances/64de02abee0100c103ab66b6' -H 'X-Auth-Token: secretSampleUserToken' (replace id)
    • curl -X PUT 'http://localhost:9000/api/maintenances/64de0390ee0100a006ab66cc' -H 'X-Auth-Token: secretSampleUserToken' -H "Content-Type: application/json" -d '{"startTime":1692272319000, "message":"a message!!!"}'
  • You should see maintenances at GET api/maintenances/listCurrentAndUpcoming (this is what the frontend uses)
    Frontend:
  • open wk without any maintenances -> should look as always
  • create an upcoming maintenance -> wk should show this in a banner. the banner should be closable. a page refresh should not show that banner anymore.
  • create a current maintennance -> wk should show this banner, but it should not be closable.
  • scrolling with the banner should behave intuitively.
  • in the annotation view, touching the banner with the mouse should move the banner to the bottom of the page (and vice versa)

TODOs:

  • Backend
    • schema
    • clarify permissions
    • CRUD routes
  • Frontend
    • Adapt to new format of maintenance rest api route (GET api/maintenances/listCurrentAndUpcoming)
    • Banner for closest upcoming maintenance “Maintenance starting in 3h” with tooltip showing more details
    • Banner for current maintenance “Current Maintenance” with tooltip showing more details

Issues:


(Please delete unneeded items, merge only when none are left open)

@fm3
Copy link
Member Author

fm3 commented Aug 17, 2023

@normanrz I am unsure about the permission system here. Who should be allowed to create/update scheduled maintenances in the database?

  • Only superusers? Then we would have to promote the users who want to use this feature to superuser on their wk instances
  • All organization admins? But maintenances are not currently scoped to organizations, so that would give a lot of users on webknossos.org this permission
  • Or do we add an entry in the config to enable/disable this for “normal admins”?

@normanrz
Copy link
Member

Either we do it just for superadmins, which seems fine to me, or we scope the maintenance banners to orgs.

@fm3 fm3 requested a review from frcroth September 4, 2023 09:39
@dieknolle3333
Copy link
Contributor

I have some more questions :)

  • If there is a maintenance currently running, I'm assuming that only the "Current maintenance" banner should be shown? Or should the next upcoming maintenance still be displayed?
  • I am assuming that "more details" are the duration and the maintenance's message?

@normanrz
Copy link
Member

normanrz commented Sep 5, 2023

  • If there is a maintenance currently running, I'm assuming that only the "Current maintenance" banner should be shown? Or should the next upcoming maintenance still be displayed?

Yes, either the current or the next maintenance should be shown. No more than 1 banner.

  • I am assuming that "more details" are the duration and the maintenance's message?

I think the message should be kept short to fit in the banner.

@dieknolle3333
Copy link
Contributor

dieknolle3333 commented Sep 6, 2023

this should be a basic frontend implementation without storing the maintenance info in the redux store (moved to new branch).
some useful timestamps: 1696024800000 is 30.09.23 00:00; 1695938400000 is 29.09.23 00:00; 1693778400000 is 4.9.23 00:00.

@dieknolle3333
Copy link
Contributor

@fm3 could you help me with the merge conflicts in MIGRATIONS.unreleased.md? I'm not sure how to resolve them

@dieknolle3333 dieknolle3333 marked this pull request as ready for review September 7, 2023 07:29
Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks quite good already, but I still have some feedback :)

Comment on lines 113 to 120
.ant-alert-message {
margin-left: 5px;
}
.ant-alert-banner {
position: absolute;
z-index: 1000;
width: 100%;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are antd classes, right? Please move these (and the rule in line 121f) to antd_overwrites.less.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay! when does something count as overwriting?
there are multiple CSS rules for antd in main.less, e.g. in l. 72 and I am not sure I understand when to write antd rules where

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it's not very clear right now. I moved another rule, but the others rules mostly use antd class names in combination with other descriptors (e.g., #main-container > section > .ant-layout-header). This means that only specific occurrences of antd components are changed. In the overwrites module, on the other hand, the rules are mutating all occurrences of the mentioned antd components. So, this is can be used as a rule of thumb :)

frontend/javascripts/admin/admin_rest_api.ts Outdated Show resolved Hide resolved
frontend/javascripts/admin/admin_rest_api.ts Outdated Show resolved Hide resolved
frontend/javascripts/admin/admin_rest_api.ts Outdated Show resolved Hide resolved
frontend/javascripts/maintenance_banner.tsx Outdated Show resolved Hide resolved
frontend/javascripts/maintenance_banner.tsx Outdated Show resolved Hide resolved
frontend/javascripts/maintenance_banner.tsx Outdated Show resolved Hide resolved
frontend/javascripts/maintenance_banner.tsx Show resolved Hide resolved
frontend/javascripts/maintenance_banner.tsx Outdated Show resolved Hide resolved
frontend/javascripts/maintenance_banner.tsx Outdated Show resolved Hide resolved
@philippotto
Copy link
Member

Nice! Works well 👍 However, there's an oddity about the banner when the user scrolls in the dashboard. See these screenshots:

image

image

I see two possible solutions:

  • use sticky instead of absolute so that the scrolling doesn't interfere
  • don't use the absolute positioning, but normal positioning (as it was in an earlier iteration) for all pages except for the tracing layout view. the "switch position to the bottom of the screen" would only be needed for the tracing layout view.

The first option is probably easier. I hope that it behaves well then. If not, the second option might be the better approach (since the layout in the tracing view should forbid scrolling anyway).

@dieknolle3333
Copy link
Contributor

with the first option I faced the problem that the lower position wasn't taken into account, so the switching didnt work any more. thus I implemented the second version. this leads to some views (at least Statistics > Overview) scrolling, not sure whether that is a problem. other than that it seems to be working fine!

const INTERVAL_TO_FETCH_MAINTENANCES_MS = 60000;

export function MaintenanceBanner() {
const { activeUser, uiInformation } = Store.getState();
const activeUser = useSelector((state: OxalisState) => state.activeUser);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dieknolle3333 just fyi, I fixed the store access here. When rendering react components, it's always important to properly hook up with the store so that the component updates when the store updates. This listener can be set up with connect (from react-redux) or in case of functional components useSelector (which is better in my opinion since it's less verbose). Your access to Store.getState() is fine in event handlers (e.g., onClick handler in a button) when one doesn't need the synchronization. However, during rendering this would mean that the component gets outdated at some point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I understand!

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great :) I fixed some smaller stuff and now think that the PR should be ready to go 🚀

@philippotto philippotto merged commit 21cc4c9 into master Sep 18, 2023
1 check passed
@philippotto philippotto deleted the maintenance-banner branch September 18, 2023 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance banner
5 participants