fleet/frontend
2022-08-24 15:45:32 +01:00
..
__mocks__ add prettier and have it format all fleet application code (#625) 2021-04-12 14:32:25 +01:00
components remove unused code and change copy (#7376) 2022-08-24 15:45:32 +01:00
context Add expiry time warning in sandbox mode (#6830) 2022-07-26 13:05:57 +01:00
docs add UI patterns documentation (#6878) 2022-07-27 18:36:39 +01:00
hooks Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00
interfaces orbit: rename unified_log table from extension to macadmins_unified_log (#7295) 2022-08-19 07:29:14 +05:30
layouts Fleet UI: Small screen overlay (#7023) 2022-08-03 09:12:07 -04:00
pages remove unused code and change copy (#7376) 2022-08-24 15:45:32 +01:00
router Fleet UI: Add back to packs links (#7350) 2022-08-23 08:28:48 -07:00
services Handle errors for duplicate os records (#7294) 2022-08-22 14:34:00 -05:00
styles fix fleet setup styles (#6909) 2022-07-27 14:43:13 +01:00
templates add google analytics to sandbox instances (#6941) 2022-08-01 11:27:12 +01:00
test chore(test): remove enzyme from the package.json (#5359) 2022-04-25 20:28:41 -05:00
typings Select all matching hosts (#1226) 2021-07-10 10:29:27 -07:00
utilities Adding first set of CIS benchmark policies for macOS (#7296) 2022-08-22 19:23:09 +00: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 Update osquery tables to report corrected platforms (#6554) 2022-07-08 12:01:03 -04:00
public-path.js add prettier and have it format all fleet application code (#625) 2021-04-12 14:32:25 +01:00
README_deprecated.md Remove numbers from documentation filenames in Fleet repo (#4313) 2022-02-23 12:17:55 -06:00
README.md add UI patterns documentation (#6878) 2022-07-27 18:36:39 +01:00

Fleet front-end

The Fleet front-end 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.

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.

As mentioned, there are two key times Storybook should be used:

  1. When building new features

As we create new features, we re-use Fleet components often. Running Storybook before implementing new UI elements can clarify if new components need to be created or already exist. This helps us avoid duplicating code.

  1. Testing components

After creating a component, 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.

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
  ├── index.ts
  • _styles.scss: The component css styles
  • ComponentName.tsx: The React component
  • 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.

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.

Deprecated

These directories and files are still used (as of 4/22/22) but are being replaced by newer code:

To view the deprecated documentation, click here.

Patterns

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