fleet/frontend/components/TooltipWrapper/TooltipWrapper.tsx

154 lines
5.3 KiB
TypeScript
Raw Normal View History

import classnames from "classnames";
import React from "react";
2023-11-07 21:15:49 +00:00
import { Tooltip as ReactTooltip5, PlacesType } from "react-tooltip-5";
2023-11-07 21:15:49 +00:00
import { uniqueId } from "lodash";
UI - GitOps Mode: Core abstractions, first batch of applications (#26401) ## For #26229 – Part 1 ![ezgif-6bbe6d60c12ed4](https://github.com/user-attachments/assets/37a04b64-abd7-4605-b4ac-9542836ff562) - This PR contains the core abstractions, routes, API updates, and types for GitOps mode in the UI. Since this work will touch essentially every part of the Fleet UI, it is ripe for merge conflicts. To mitigate such conflicts, I'll be merging this work in a number of iterative PRs. ~To effectively gate any of this work from showing until it is all merged to `main`, [this commit](feedbb2d4c25ec2e304e1f18d409cee62f6752ed) hides the settings section that allows enabling/disabling this setting, effectively feature flagging the entire thing. In the last of these iterative PRs, that commit will be reverted to engage the entire feature. For testing purposes, reviewers can `git revert feedbb2d4c25ec2e304e1f18d409cee62f6752ed` locally~ The new settings section for this feature is feature flagged until all PRs are merged - to show the setting section while testing, run `ALLOW_GITOPS_MODE=true NODE_ENV=development yarn run webpack --progress --watch` in place of `make generate-dev` - Changes file will be added and feature flag removed in the last PR - [x] Settings page with routing, form, API integration (hidden until last PR) - [x] Activities - [x] Navbar indicator - Apply GOM conditional UI to: - [x] Manage enroll secret modal: .5 - Controls > - [x] Scripts: - Setup experience > - [x] Install software > Select software modal - [x] OS Settings > - [x] Custom settings - [x] Disk encryption - [x] OS Updates 2/18/25, added to this PR: - [x] Controls > Setup experience > Run script - [x] Software > - [x] Manage automations modal - [x] Add software > - [x] App Store (VPP) - [x] Custom package - [x] Queries - [x] Manage - [x] Automations modal - [x] New - [x] Edit - [x] Policies - [x] Manage - [x] New - [x] Edit - Manage automations - [x] Calendar events - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-02-20 16:41:07 +00:00
export interface ITooltipWrapper {
2023-11-07 21:15:49 +00:00
children: React.ReactNode;
// default is bottom-start
position?: PlacesType;
/** A boolean or number defining how long to delay showing the tooltip content on hover over the
* element. If a boolean, sets delay to the default below. If a number, sets to that
* many milliseconds. Defaults to `true`, overridden by `delayShowHide` */
delayShow?: boolean | number;
/** A boolean or number defining how long to delay hiding the tooltip content on mouseout from the element. If a boolean, sets delay to the default below. If a number, sets to that
* many milliseconds. Overridden by `delayShowHide` */
delayHide?: boolean | number;
/** A boolean or number defining how long to delay showing and hiding the tooltip content on hover
and mouseout from the element. If a boolean, sets delay to the default below. If a number, sets to that
* many milliseconds. Overrides `delayShow` and `delayHide` */
delayShowHide?: boolean | number;
2025-09-29 17:10:41 +00:00
delayInMs?: number;
2023-11-07 21:15:49 +00:00
underline?: boolean;
// Below two props used here to maintain the API of the old TooltipWrapper
// A clearer system would be to use the 3 below commented props, which describe exactly where they
// will apply, `element` being the element this tooltip will wrap. Associated logic is commented
// out, but ready to be used.
className?: string;
tooltipClass?: string;
2023-11-07 21:15:49 +00:00
// wrapperCustomClass?: string;
// elementCustomClass?: string;
// tipCustomClass?: string;
clickable?: boolean;
tipContent: React.ReactNode;
tipOffset?: number;
Update UI for software self-service features (#19244) Issues https://github.com/fleetdm/fleet/issues/17587, https://github.com/fleetdm/fleet/issues/18836, https://github.com/fleetdm/fleet/issues/18837, https://github.com/fleetdm/fleet/pull/18339, and https://github.com/fleetdm/fleet/pull/18340 # TODOS - Integrate backend - Unit/integration tests - Various todos noted in comments - Cleanup styles and organization of components (de-duplicating and consolidating where possible) - Activity feed updates (if any) # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [ ] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features. - [ ] Added/updated tests - [ ] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [ ] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [ ] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [ ] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [ ] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)). --------- Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
/** If set to `true`, will not show the tooltip. This can be used to dynamically
* disable the tooltip from the parent component.
* @default false
*/
disableTooltip?: boolean;
/** If set to `true`, will show the arrow on the tooltip.
* This can be used to dynamically hide the arrow from the parent component.
* @default false
*/
showArrow?: boolean;
/** Corresponds to the react tooltip 5 `positionStrategy` option - see https://react-tooltip.com/docs/options.
* Setting as `true` will set the tooltip's `positionStrategy` to `"fixed"`. The default strategy is "absolute".
* Do this if you run into issues with `overflow: hidden` on the tooltip parent container
* */
fixedPositionStrategy?: boolean;
isMobileView?: boolean;
}
const baseClass = "component__tooltip-wrapper";
const DEFAULT_DELAY_MS = 250;
const TooltipWrapper = ({
2023-11-07 21:15:49 +00:00
// wrapperCustomClass,
// elementCustomClass,
// tipCustomClass,
children,
tipContent,
tipOffset = 5,
2023-11-07 21:15:49 +00:00
position = "bottom-start",
delayShow = true,
delayHide,
delayShowHide,
2025-09-29 17:10:41 +00:00
delayInMs, // TODO: Apply pattern of delay tooltip for repeated table tooltips
2023-11-07 21:15:49 +00:00
underline = true,
className,
tooltipClass,
2023-11-07 21:15:49 +00:00
clickable = true,
Update UI for software self-service features (#19244) Issues https://github.com/fleetdm/fleet/issues/17587, https://github.com/fleetdm/fleet/issues/18836, https://github.com/fleetdm/fleet/issues/18837, https://github.com/fleetdm/fleet/pull/18339, and https://github.com/fleetdm/fleet/pull/18340 # TODOS - Integrate backend - Unit/integration tests - Various todos noted in comments - Cleanup styles and organization of components (de-duplicating and consolidating where possible) - Activity feed updates (if any) # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [ ] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features. - [ ] Added/updated tests - [ ] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [ ] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [ ] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [ ] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [ ] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)). --------- Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
disableTooltip = false,
showArrow = false,
fixedPositionStrategy = false,
isMobileView = false,
2023-11-07 21:15:49 +00:00
}: ITooltipWrapper) => {
const wrapperClassNames = classnames(baseClass, className, {
"show-arrow": showArrow,
2023-11-07 21:15:49 +00:00
// [`${baseClass}__${wrapperCustomClass}`]: !!wrapperCustomClass,
});
2023-11-07 21:15:49 +00:00
const elementClassNames = classnames(`${baseClass}__element`, {
// [`${baseClass}__${elementCustomClass}`]: !!elementCustomClass,
[`${baseClass}__underline`]: underline,
});
const tipClassNames = classnames(`${baseClass}__tip-text`, tooltipClass, {
// [`${baseClass}__${tipCustomClass}`]: !!tipCustomClass,
});
const tipId = uniqueId();
let delayShowVal;
if (typeof delayShow === "boolean" && delayShow) {
delayShowVal = DEFAULT_DELAY_MS;
} else if (typeof delayShow === "number") {
delayShowVal = delayShow;
}
let delayHideVal;
if ((typeof delayHide === "boolean" && delayHide) || clickable) {
delayHideVal = DEFAULT_DELAY_MS;
} else if (typeof delayHide === "number") {
delayHideVal = delayHide;
}
if (typeof delayShowHide === "boolean" && delayShowHide) {
[delayShowVal, delayHideVal] = [DEFAULT_DELAY_MS, DEFAULT_DELAY_MS];
} else if (typeof delayShowHide === "number") {
[delayShowVal, delayHideVal] = [delayShowHide, delayShowHide];
}
return (
2023-11-07 21:15:49 +00:00
<span className={wrapperClassNames}>
<div
className={elementClassNames}
data-tip
data-tooltip-id={tipId}
style={
isMobileView && !disableTooltip ? { cursor: "pointer" } : undefined
} // With mobile width, show pointer cursor on hover since tooltip won't show on hover
>
{children}
</div>
Update UI for software self-service features (#19244) Issues https://github.com/fleetdm/fleet/issues/17587, https://github.com/fleetdm/fleet/issues/18836, https://github.com/fleetdm/fleet/issues/18837, https://github.com/fleetdm/fleet/pull/18339, and https://github.com/fleetdm/fleet/pull/18340 # TODOS - Integrate backend - Unit/integration tests - Various todos noted in comments - Cleanup styles and organization of components (de-duplicating and consolidating where possible) - Activity feed updates (if any) # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [ ] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features. - [ ] Added/updated tests - [ ] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [ ] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [ ] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [ ] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [ ] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)). --------- Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
{!disableTooltip && (
<ReactTooltip5
className={tipClassNames}
id={tipId}
2025-09-29 17:10:41 +00:00
delayShow={delayShowVal || delayInMs}
delayHide={delayHideVal}
noArrow={!showArrow}
Update UI for software self-service features (#19244) Issues https://github.com/fleetdm/fleet/issues/17587, https://github.com/fleetdm/fleet/issues/18836, https://github.com/fleetdm/fleet/issues/18837, https://github.com/fleetdm/fleet/pull/18339, and https://github.com/fleetdm/fleet/pull/18340 # TODOS - Integrate backend - Unit/integration tests - Various todos noted in comments - Cleanup styles and organization of components (de-duplicating and consolidating where possible) - Activity feed updates (if any) # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [ ] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features. - [ ] Added/updated tests - [ ] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [ ] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [ ] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [ ] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [ ] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)). --------- Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
place={position}
opacity={1}
disableStyleInjection
clickable={clickable}
offset={tipOffset}
positionStrategy={fixedPositionStrategy ? "fixed" : "absolute"}
globalCloseEvents={
isMobileView ? { clickOutsideAnchor: true } : undefined
}
openEvents={isMobileView ? { click: true } : { mouseenter: true }}
closeEvents={isMobileView ? { click: true } : { mouseleave: true }}
Update UI for software self-service features (#19244) Issues https://github.com/fleetdm/fleet/issues/17587, https://github.com/fleetdm/fleet/issues/18836, https://github.com/fleetdm/fleet/issues/18837, https://github.com/fleetdm/fleet/pull/18339, and https://github.com/fleetdm/fleet/pull/18340 # TODOS - Integrate backend - Unit/integration tests - Various todos noted in comments - Cleanup styles and organization of components (de-duplicating and consolidating where possible) - Activity feed updates (if any) # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [ ] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features. - [ ] Added/updated tests - [ ] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [ ] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [ ] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [ ] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [ ] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)). --------- Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
>
{tipContent}
</ReactTooltip5>
)}
2023-11-07 21:15:49 +00:00
</span>
);
};
export default TooltipWrapper;