fleet/frontend
Jacob Shandling c17c7b2b57
UI: Add missing step to manual Turn on MDM modal (#10232)
<img width="752" alt="Screenshot 2023-03-01 at 3 04 49 PM"
src="https://user-images.githubusercontent.com/61553566/222286958-56cd0bac-0354-47ef-81c7-9ccd41626e2e.png">


**Checklist for submitter**

- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-03-02 09:15:55 -08:00
..
__mocks__ check disk encryption key from host details page (#9691) 2023-02-14 17:00:36 +00:00
components Fleet UI: Show query button added to policy results page (#10164) 2023-02-28 12:55:56 -05:00
context Fleet UI: Default policies preselect targeted platforms only (#9861) 2023-02-17 08:48:40 -05:00
docs Fleet UI: URL routes for dashboard platforms (#8689) 2022-11-17 10:45:35 -05:00
hooks Fleet UI: Default policies preselect targeted platforms only (#9861) 2023-02-17 08:48:40 -05:00
interfaces Reconcile API integration for MDM profile statuses in host details (#10045) 2023-02-23 10:27:00 -03:00
layouts 9349 new controls page (#9431) 2023-01-26 11:33:54 -08:00
pages UI: Add missing step to manual Turn on MDM modal (#10232) 2023-03-02 09:15:55 -08:00
router update location of macOS updates page section (#9977) 2023-02-22 11:15:22 +00:00
services Fleet UI: Fix host count for hosts filtered by operating system version (#10070) 2023-02-23 13:50:11 -05:00
styles UI: Add macOS settings (profiles) indicator and modal with data table (#9809) 2023-02-22 08:13:12 -08:00
templates add pendo to sandbox instances (#9191) 2023-01-06 14:57:32 +00:00
test Add readonly MDM.EnabledAndConfigured to app config and device responses (#9575) 2023-02-01 14:47:52 -03:00
typings Feat/update live query states (#8122) 2022-10-10 15:39:49 +01:00
utilities Fleet UI: Use currentTeam.id from app context to set teamId for API calls on Manage host page (#10053) 2023-02-23 11:37:09 -05:00
index.jsx add prettier and have it format all fleet application code (#625) 2021-04-12 14:32:25 +01:00
index.scss New tooltips! (#4326) 2022-02-28 13:25:06 -08:00
osquery_tables.json Fleet UI: Consistent URL validation (#9806) 2023-02-22 09:05:38 -05:00
public-path.js add prettier and have it format all fleet application code (#625) 2021-04-12 14:32:25 +01:00
README.md Frontend testing documentation (#8936) 2022-12-14 13:56:56 -05:00
requestCSRdata.ts UI: Settings modals mdm (#9156) 2023-01-10 12:19:46 -08:00

Fleet frontend

The Fleet frontend is a Single Page Application using React with Typescript and Hooks.

Table of contents

Running the Fleet web app

For details instruction on building and serving the Fleet web application consult the Contributing documentation.

Testing

Visit the overview of Fleet UI testing for more information on our testing strategy, philosophies, and tools.

To run unit or integration tests in ComponentName.tests.tsx, run yarn test -- ComponentName.tests.tsx. To test all Javascript components run yarn test.

To run E2E tests, visit our Cypress testing documentation.

For more information on how our front-end tests work, visit our frontend test directory.

Directory structure

Component directories in the Fleet front-end application encapsulate the entire component, including files for the component and its styles. The typical directory structure for a component is as follows:

└── ComponentName
  ├── _styles.scss
  ├── ComponentName.tsx
  |-- ComponentName.tests.tsx
  ├── index.ts
  • _styles.scss: The component css styles
  • ComponentName.tsx: The React component
  • ComponentName.tests.tsx: The React component unit/integration tests
  • index.ts: Exports the React component
    • This file is helpful as it allows other components to import the component by it's directory name. Without this file the component name would have to be duplicated during imports (components/ComponentName vs. components/ComponentName/ComponentName).

components

The component directory contains global React components rendered by pages, receiving props from their parent components to render data and handle user interactions.

context

The context directory contains the React Context API pattern for various entities. Only entities that are needed across the app has a global context. For example, the logged in user (currentUser) has multiple pages and components where its information is pulled.

interfaces

Files in the interfaces directory are used to specify the Typescript interface for a reusable Fleet entity. This is designed to DRY up the code and increase re-usability. These interfaces are imported in to component files and implemented when defining the component's props.

Additionally, local interfaces are used for props of local components.

layouts

The Fleet application has only 1 layout, the Core Layout. The Layout is rendered from the router and are used to set up the general app UI (header, sidebar) and render child components. The child components rendered by the layout are typically page components.

pages

Page components are React components typically rendered from the router. React Router passed props to these pages in case they are needed. Examples include the router, location, and params objects.

router

The router directory is where the react router lives. The router decides which component will render at a given URL. Components rendered from the router are typically located in the pages directory. The router directory also holds a paths file which holds the application paths as string constants for reference throughout the app. These paths are typically referenced from the App Constants object.

services

CRUD functions for all Fleet entities (e.g. query) that link directly to the Fleet API.

styles

The styles directory contains the general app style setup and variables. It includes variables for the app color hex codes, fonts (families, weights and sizes), and padding.

templates

The templates directory contains the HTML file that renders the React application via including the bundle.js and bundle.css files. The HTML page also includes the HTML element in which the React application is mounted.

test

The test directory includes test helpers, API request mocks, and stubbed data entities for use in test files. More on test helpers, stubs, and request mocks here.

utilities

The utilities directory contains re-usable functions and constants for use throughout the application. The functions include helpers to convert an array of objects to CSV, debounce functions to prevent multiple form submissions, format API errors, etc.

Patterns

The list of patterns used in the Fleet UI codebase can be found here.

Storybook

Storybook is a tool to document and visualize components, and we use it to capture our global components used across Fleet. Storybook is key when developing new features and testing components before release. It runs a separate server exposed on port 6006. To run this server, do the following:

  • Go to your root fleet project directory
  • Run make deps
  • Run yarn storybook

The URL localhost:6006 should automatically show in your browser. If not, visit it manually.

Running Storybook before implementing new UI elements can clarify if new components need to be created or already exist. When creating a component, you can create a new file, component.stories.tsx, within its directory. Then, fill it with the appropriate Storybook code to create a new Storybook entry. You will be able to visualize the component within Storybook to determine if it looks and behaves as expected.