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

[SDPAP-6839] Add Dismissible Message Bar for CMS user #362

Merged

Conversation

vincent-gao
Copy link
Contributor

@vincent-gao vincent-gao commented Jan 16, 2023

Jira

https://digital-vic.atlassian.net/browse/SDPAP-6400

Problem/Motivation

There is currently no way for users to know if a CMS is undergoing maintenance or has upcoming maintenance or content freeze.

Related PRs

https://github.com/dpc-sdp/content-vic-gov-au/pull/1455

Screenshots

CleanShot 2023-02-01 at 10 17 10
CleanShot 2023-02-01 at 10 21 40

TODO

The current suggested labels are hard coded, it may be worth providing a form for admin users in the near future...

@vincent-gao vincent-gao force-pushed the feature/SDPAP-6839-Dismissible-Message-Bar-for-CMS-user branch 2 times, most recently from f37d5f2 to dda4d45 Compare January 19, 2023 02:48
@vincent-gao vincent-gao changed the title SDPAP-6839 Add Dismissible Message Bar for CMS user [SDPAP-6839] Add Dismissible Message Bar for CMS user Jan 31, 2023
@vincent-gao vincent-gao force-pushed the feature/SDPAP-6839-Dismissible-Message-Bar-for-CMS-user branch from a9affd7 to f5cef80 Compare January 31, 2023 23:13
update to override the parent css

lint

Updates

1. Update label options
2. hide severity field
3. set severity to medium
4. css update
5. twig update
6. install the site alert block

Put message next to the label

update site alert theme

fixed the overflow issue

lint
@MdNadimHossain
Copy link
Contributor

wow it is already here, nice one @vincent-gao

Copy link
Contributor

@krakerag krakerag left a comment

Choose a reason for hiding this comment

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

LGTM @vincent-gao. A couple of code suggestions but it is fine the way it is.

if ($value && strpos($value, 'site_alert:') !== FALSE) {
preg_match('#[0-9]+$#', $value, $match);
$site_alert = SiteAlert::load(reset($match));
$build[$key]['#alert']['start'] = date('d/m/Y H:i:s', strtotime($site_alert->getStartTime()));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit of a stickler for DateTimeImmutable since you can trust the time you set on it hasn't changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @krakerag , thanks for the CR.
It is always good to learn new things!
I have made a further change trying to use DateTimeImmutable class. please take a look.

* Implements hook_form_alter().
*/
function tide_site_alert_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id === 'site_alert_add_form' || $form_id === 'site_alert_edit_form') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually better to refactory your if statements so you can return immediately and then have the code nested lower. It's a bit of an anti-pattern to have your entire function nested in an if statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reminds me that I should switch to using another hook!

*/
function tide_site_alert_textfield_callback(&$form, FormStateInterface $form_state) {
$selected = $form_state->getValue('suggested_labels');
if ($selected != 'Other') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like to set something and then only have the if statement. Elses can normally be removed when it's just setting one value or another.

1. change to use DateTimeImmutable()
2. change to use hook_form_FORM_ID_alter hook
@vincent-gao
Copy link
Contributor Author

wow it is already here, nice one @vincent-gao

Thanks for the CR @MdNadimHossain

@@ -29,8 +29,11 @@ public function build() {
if ($value && strpos($value, 'site_alert:') !== FALSE) {
preg_match('#[0-9]+$#', $value, $match);
$site_alert = SiteAlert::load(reset($match));
$build[$key]['#alert']['start'] = date('d/m/Y H:i:s', strtotime($site_alert->getStartTime()));
$build[$key]['#alert']['end'] = date('d/m/Y H:i:s', strtotime($site_alert->getEndTime()));
$dateTimeImmutable = new \DateTimeImmutable();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I think this might not be correct.

DateTimeImmutable should be replacing date() - you're creating a new DateTimeImmutable object to work with, to create a formatted output for your two build variables. It should probably be more like this:

$build[$key]['#alert']['start'] = new \DateTimeImmutable($site_alert->getStartTime())->format('d/m/Y H:i:s');
$build[$key]['#alert']['end'] = new \DateTimeImmutable($site_alert->getEndTime())->format('d/m/Y H:i:s');

With your code, you're creating a new object based on time now(), and then modifying it by your start times/end times.

Does this make sense?

@vincent-gao vincent-gao merged commit b555179 into develop Feb 14, 2023
@vincent-gao vincent-gao deleted the feature/SDPAP-6839-Dismissible-Message-Bar-for-CMS-user branch February 14, 2023 22:26
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.

3 participants