Skip to content

UI: Add macOS settings (profiles) indicator and modal with data table#9809

Merged
jacobshandling merged 26 commits intofleetdm:mainfrom
jacobshandling:add-macOS-settings-items
Feb 22, 2023
Merged

UI: Add macOS settings (profiles) indicator and modal with data table#9809
jacobshandling merged 26 commits intofleetdm:mainfrom
jacobshandling:add-macOS-settings-items

Conversation

@jacobshandling
Copy link
Copy Markdown
Contributor

@jacobshandling jacobshandling commented Feb 13, 2023

Addresses #9413

Implements

https://www.loom.com/share/d1b66a3076b94bf2add4fcf8666649a4

  • macOS settings indicator on host details and device user pages. Only displayed if (1) the host is enrolled in a Fleet MDM server and (2) the host has at least one setting (profile) enforced.
  • macOS settings modal, toggled by clicking on above indicator. Contains a data table with the name, status, and error messages, if any, of each enforced macOS setting on the host.

Notes

Checklist

  • Changes file added
  • Manual QA
  • Updated testing inventory

Copy link
Copy Markdown
Contributor

@gillespi314 gillespi314 Feb 14, 2023

Choose a reason for hiding this comment

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

Do you need to use a callback here? Maybe try this instead:

setShowMacSettingsModal((prevState) => !prevState)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this was just a pattern I saw elsewhere and followed in lieu of any other input. I'll do that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gillespi314 I'm actually now remembering, @ghernandez345 doesn't like directly passing set{State} s to other components and prefers a handler of some sort, so this is in line with that. I am curious as to why he prefers that though?

Copy link
Copy Markdown
Contributor

@gillespi314 gillespi314 Feb 14, 2023

Choose a reason for hiding this comment

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

Yeah, I've seen both approaches and defer to Gabe if his preference is to always define handlers.

In that case you can still avoid the useCallback, I think.

const toggleMacSettingsModal = () => setShowMacSettingsModal((prevState) => !prevState);

Copy link
Copy Markdown
Contributor

@gillespi314 gillespi314 Feb 14, 2023

Choose a reason for hiding this comment

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

useState guarantees that the setter is referentially stable.

React guarantees that setState function identity is stable and won’t change on re-renders. This is why it’s safe to omit from the useEffect or useCallback dependency list.

But the toggleMacSettingsModal handler function will get recreated each render. And I see that it get passed as a prop to child components. This type of set up can result in performance problems when the child component needs intensive calculations to render. https://beta.reactjs.org/reference/react/useCallback#skipping-re-rendering-of-components. So you can add useCallback here to cache this particular handler prop although it might be overkill. Also note that other prop changes can still trigger the child to re-render so this alone isn't a silver bullet for performance problems if the other props aren't being tightly controlled as well. If you do go with useCallback on the handler here, you can use [] for the dependencies if you use the prevState updater function that I suggested.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See related comment to DeviceUserPage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since these are basically static (i.e. there are no parameters to this function), you can eliminate the function and just export the tableHeaders constant.

Copy link
Copy Markdown
Contributor

@gillespi314 gillespi314 Feb 14, 2023

Choose a reason for hiding this comment

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

Based on the API mock, I don't think you will need this since it doesn't look like you need to do any transformation of the data.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You might want to use the all caps format here: SETTINGS_STATUS_OPTIONS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This might be a good candidate for its own React component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For sure. I have a MacSettingsIndicator component for the DataTable cells, which is pretty much the same format as this and I'll use here too.

Could also be combined with the "StatusIndicator" component that's used elsewhere, but that's blowing this up a bit much, perhaps.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this could still be undefined based on the IHostSummaryProps? I wonder if we should try to tighten up that interface definition.

Fun fact, optional chaining works with functions: toggleOSPolicyModal?.()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Copy Markdown
Contributor

@gillespi314 gillespi314 Feb 14, 2023

Choose a reason for hiding this comment

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

I'm not sure if we want to use type="submit" when there is no form being submitted? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type

@jacobshandling jacobshandling force-pushed the add-macOS-settings-items branch from b46d3e8 to 161eb55 Compare February 16, 2023 18:54
@jacobshandling jacobshandling marked this pull request as ready for review February 16, 2023 19:47
@jacobshandling jacobshandling requested a review from a team as a code owner February 16, 2023 19:47
@jacobshandling jacobshandling changed the title WIP - Add mac os settings items UI: Add macOS settings (profiles) indicator and modal with data table Feb 16, 2023
@jacobshandling jacobshandling force-pushed the add-macOS-settings-items branch from e8e109d to 74f1127 Compare February 17, 2023 21:02
@lukeheath
Copy link
Copy Markdown
Member

@gillespi314 Thanks for your review! I'll defer to you on this review since you had some feedback implemented.

@jacobshandling jacobshandling force-pushed the add-macOS-settings-items branch from 36d02f1 to 5ca43c3 Compare February 21, 2023 00:49
ghernandez345
ghernandez345 previously approved these changes Feb 21, 2023
@jacobshandling jacobshandling merged commit a578e20 into fleetdm:main Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants