**Related issue:** Resolves #49276 **New features** - Added new "Secondary" (bordered, off-white fill) and "Subdued" (borderless, low-emphasis) button variants to match the Figma spec, alongside the existing Primary style. - Allowed rows to be selected in Controls > OS updates. **Cleanup** - Once nothing referenced the old styles anymore, fully removed the old `text-icon`, `brand-inverse-icon`, `inverse-alert`, `inverse`, and `icon` button variants (type, styles, and Storybook entries) from the shared `Button` component. - Removed the `iconStroke` prop, which had become a no-op once the old variants it supported were gone. - Renamed `ActionsDropdown`'s variants (`button`/`brand-button`/`small-button`) to `subdued`/`primary`/`secondary` to match the same naming used everywhere else. - Replaced a one-off dropdown implementation on the Software title page with the shared `ActionsDropdown` component, instead of maintaining duplicate styling logic. - Changed the button name on Host details > Reports > Report details from "View data for all hosts" to "View report for all hosts" (to match the previous page's Actions drop-down options). # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <img width="1475" height="241" alt="Screenshot 2026-07-21 at 06 35 49" src="https://github.com/user-attachments/assets/7cfbd444-7837-40e8-854e-bc5989d57d85" /> <img width="661" height="306" alt="Screenshot 2026-07-21 at 06 37 18" src="https://github.com/user-attachments/assets/5d0c4873-8179-4089-b115-7e8cd3a53b4d" /> <img width="1427" height="423" alt="Screenshot 2026-07-21 at 06 37 30" src="https://github.com/user-attachments/assets/a4850a60-f44a-4902-b45e-0094f23a52f8" /> <img width="1427" height="640" alt="Screenshot 2026-07-21 at 06 37 46" src="https://github.com/user-attachments/assets/738a4a7f-cd7d-4162-b659-6f649c32204d" /> <img width="1445" height="479" alt="Screenshot 2026-07-22 at 07 03 22" src="https://github.com/user-attachments/assets/4f672dc0-5c6d-4eb8-8465-ed5233fcd1b2" /> <img width="811" height="871" alt="Screenshot 2026-07-21 at 06 41 20" src="https://github.com/user-attachments/assets/5421c96e-2dab-492a-af26-be0e5a7791ca" />
328 lines
11 KiB
TypeScript
328 lines
11 KiB
TypeScript
import React, { useState } from "react";
|
|
import classnames from "classnames";
|
|
import { ISoftwareTitleDetails, IAppStoreApp } from "interfaces/software";
|
|
import { ILabelSummary } from "interfaces/label";
|
|
|
|
import { useQuery } from "react-query";
|
|
|
|
import useGitOpsMode from "hooks/useGitOpsMode";
|
|
|
|
import softwareAPI from "services/entities/software";
|
|
import labelsAPI, { getCustomLabels } from "services/entities/labels";
|
|
|
|
import { notify } from "components/ToastNotification";
|
|
import Card from "components/Card";
|
|
import Modal from "components/Modal";
|
|
import ModalFooter from "components/ModalFooter";
|
|
import Checkbox from "components/forms/fields/Checkbox";
|
|
import { DropdownTargetLabelSelector } from "components/TargetLabelSelector";
|
|
import GitOpsModeTooltipWrapper from "components/GitOpsModeTooltipWrapper";
|
|
|
|
import {
|
|
CUSTOM_TARGET_OPTIONS,
|
|
generateSelectedLabels,
|
|
getCustomTarget,
|
|
getDisplayedSoftwareName,
|
|
generateHelpText,
|
|
getTargetType,
|
|
} from "pages/SoftwarePage/helpers";
|
|
|
|
import InputField from "components/forms/fields/InputField";
|
|
import Button from "components/buttons/Button";
|
|
|
|
import { DEFAULT_USE_QUERY_OPTIONS } from "utilities/constants";
|
|
|
|
import {
|
|
ISoftwareAutoUpdateConfigFormValidation,
|
|
ISoftwareAutoUpdateConfigInputValidation,
|
|
validateFormData,
|
|
} from "./helpers";
|
|
|
|
const baseClass = "edit-auto-update-config-modal";
|
|
const formClass = "edit-auto-update-config-form";
|
|
|
|
// Schema for the form data that will be used in the UI
|
|
// and sent to the API.
|
|
export interface ISoftwareAutoUpdateConfigFormData {
|
|
autoUpdateEnabled: boolean;
|
|
autoUpdateStartTime: string;
|
|
autoUpdateEndTime: string;
|
|
targetType: string;
|
|
customTarget: string;
|
|
labelTargets: Record<string, boolean>;
|
|
}
|
|
|
|
interface EditAutoUpdateConfigModal {
|
|
teamId: number;
|
|
softwareTitle: ISoftwareTitleDetails;
|
|
refetchSoftwareTitle: () => void;
|
|
onExit: () => void;
|
|
}
|
|
|
|
const EditAutoUpdateConfigModal = ({
|
|
softwareTitle,
|
|
teamId,
|
|
refetchSoftwareTitle,
|
|
onExit,
|
|
}: EditAutoUpdateConfigModal) => {
|
|
const { gitOpsModeEnabled } = useGitOpsMode("software");
|
|
|
|
const formClassNames = classnames(formClass, {
|
|
[`edit-auto-update-config-form--disabled`]: gitOpsModeEnabled,
|
|
});
|
|
|
|
const [isUpdatingConfiguration, setIsUpdatingConfiguration] = useState(false);
|
|
const [formData, setFormData] = useState<ISoftwareAutoUpdateConfigFormData>({
|
|
autoUpdateEnabled: softwareTitle.auto_update_enabled || false,
|
|
autoUpdateStartTime: softwareTitle.auto_update_window_start || "",
|
|
autoUpdateEndTime: softwareTitle.auto_update_window_end || "",
|
|
targetType: getTargetType(softwareTitle.app_store_app as IAppStoreApp),
|
|
customTarget: getCustomTarget(softwareTitle.app_store_app as IAppStoreApp),
|
|
labelTargets: generateSelectedLabels(
|
|
softwareTitle.app_store_app as IAppStoreApp
|
|
),
|
|
});
|
|
|
|
// Fetch labels for DropdownTargetLabelSelector
|
|
const { data: labels } = useQuery<ILabelSummary[], Error>(
|
|
["custom_labels"],
|
|
() => labelsAPI.summary(teamId).then((res) => getCustomLabels(res.labels)),
|
|
{
|
|
...DEFAULT_USE_QUERY_OPTIONS,
|
|
}
|
|
);
|
|
|
|
const [
|
|
formValidation,
|
|
setFormValidation,
|
|
] = useState<ISoftwareAutoUpdateConfigFormValidation>(() =>
|
|
validateFormData(formData)
|
|
);
|
|
|
|
// Currently calls the "edit app store app" API.
|
|
// FUTURE: switch endpoint based on software title type?
|
|
const onSubmitForm = async (evt: React.MouseEvent<HTMLFormElement>) => {
|
|
evt.preventDefault();
|
|
|
|
const newValidation = validateFormData(formData, true);
|
|
setFormValidation(newValidation);
|
|
|
|
if (!newValidation.isValid) {
|
|
return false;
|
|
}
|
|
|
|
setIsUpdatingConfiguration(true);
|
|
|
|
try {
|
|
await softwareAPI.editAppStoreApp(softwareTitle.id, teamId, formData);
|
|
|
|
notify.success(
|
|
<>
|
|
<strong>
|
|
{getDisplayedSoftwareName(
|
|
softwareTitle.name,
|
|
softwareTitle.display_name
|
|
)}
|
|
</strong>{" "}
|
|
configuration updated.
|
|
</>
|
|
);
|
|
|
|
refetchSoftwareTitle();
|
|
onExit();
|
|
} catch (e) {
|
|
notify.error(
|
|
"An error occurred while updating the configuration. Please try again.",
|
|
{ response: e }
|
|
);
|
|
}
|
|
setIsUpdatingConfiguration(false);
|
|
return true;
|
|
};
|
|
|
|
const onToggleEnabled = (value: boolean) => {
|
|
const newFormData = { ...formData, autoUpdateEnabled: value };
|
|
setFormData(newFormData);
|
|
setFormValidation(validateFormData(newFormData));
|
|
};
|
|
|
|
const onChangeTimeField = (update: { name: string; value: string }) => {
|
|
// Ensure HH:MM format with proper characters.
|
|
const value = update.value.substring(0, 5).replace(/[^0-9:]/g, "");
|
|
const newFormData = { ...formData, [update.name]: value };
|
|
setFormData(newFormData);
|
|
const newValidation = validateFormData(newFormData);
|
|
// Can be "autoUpdateStartTime" or "autoUpdateEndTime".
|
|
const fieldName = update.name as keyof ISoftwareAutoUpdateConfigFormValidation;
|
|
const fieldValidation = newValidation[
|
|
fieldName
|
|
] as ISoftwareAutoUpdateConfigInputValidation;
|
|
// We don't want to show an error message as the user types.
|
|
// (that will happen on blur instead)
|
|
// We'll just clear any existing error if the field is valid.
|
|
if (fieldValidation?.isValid) {
|
|
setFormValidation(newValidation);
|
|
}
|
|
};
|
|
|
|
const onSelectTargetType = (value: string) => {
|
|
const newData = { ...formData, targetType: value };
|
|
setFormData(newData);
|
|
setFormValidation(validateFormData(newData));
|
|
};
|
|
|
|
const onSelectCustomTargetOption = (value: string) => {
|
|
const newData = { ...formData, customTarget: value };
|
|
setFormData(newData);
|
|
setFormValidation(validateFormData(newData));
|
|
};
|
|
|
|
const onSelectLabel = ({ name, value }: { name: string; value: boolean }) => {
|
|
const newData = {
|
|
...formData,
|
|
labelTargets: { ...formData.labelTargets, [name]: value },
|
|
};
|
|
setFormData(newData);
|
|
setFormValidation(validateFormData(newData));
|
|
};
|
|
|
|
const earliestStartTimeError =
|
|
formValidation.autoUpdateStartTime?.message ||
|
|
(formValidation.windowLength?.message ? "Earliest start time" : undefined);
|
|
|
|
const latestStartTimeError =
|
|
formValidation.autoUpdateEndTime?.message ||
|
|
(formValidation.windowLength?.message ? "Latest start time" : undefined);
|
|
|
|
const updateWindowLabel = formValidation.windowLength?.message || (
|
|
<>Update window (host’s local time)</>
|
|
);
|
|
const updateWindowLabelClass = classnames("form-field__label", {
|
|
"form-field__label--error": !!formValidation.windowLength?.message,
|
|
});
|
|
|
|
return (
|
|
<Modal className={baseClass} title="Schedule auto updates" onExit={onExit}>
|
|
<div className={formClassNames}>
|
|
<div className={`${formClass}__form-frame`}>
|
|
<Card paddingSize="medium" borderRadiusSize="medium">
|
|
<div className={`${formClass}__auto-update-config`}>
|
|
<div className={`form-field`}>
|
|
<div className="form-field__label">Auto updates</div>
|
|
<div className="form-field__subtitle">
|
|
Automatically update{" "}
|
|
<strong>
|
|
{getDisplayedSoftwareName(
|
|
softwareTitle.name,
|
|
softwareTitle.display_name
|
|
)}
|
|
</strong>{" "}
|
|
on all targeted hosts when a new version is available.
|
|
</div>
|
|
<div>
|
|
<Checkbox
|
|
value={formData.autoUpdateEnabled}
|
|
onChange={(newVal: boolean) => onToggleEnabled(newVal)}
|
|
>
|
|
Enable auto updates
|
|
</Checkbox>
|
|
</div>
|
|
</div>
|
|
{formData.autoUpdateEnabled && (
|
|
<>
|
|
<div>
|
|
<div className="form-field">
|
|
<div className={updateWindowLabelClass}>
|
|
{updateWindowLabel}
|
|
</div>
|
|
<div className="form-field__subtitle">
|
|
Times are formatted as HH:MM in 24 hour time (e.g.,
|
|
"13:37").
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div className={`${formClass}__auto-update-schedule-form`}>
|
|
<span className="date-time-inputs">
|
|
<InputField
|
|
value={formData.autoUpdateStartTime}
|
|
onChange={onChangeTimeField}
|
|
onBlur={() =>
|
|
setFormValidation(validateFormData(formData))
|
|
}
|
|
label="Earliest start time"
|
|
name="autoUpdateStartTime"
|
|
parseTarget
|
|
error={earliestStartTimeError}
|
|
/>
|
|
<InputField
|
|
value={formData.autoUpdateEndTime}
|
|
onChange={onChangeTimeField}
|
|
onBlur={() =>
|
|
setFormValidation(validateFormData(formData))
|
|
}
|
|
label="Latest start time"
|
|
name="autoUpdateEndTime"
|
|
parseTarget
|
|
error={latestStartTimeError}
|
|
/>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</Card>
|
|
<Card paddingSize="medium" borderRadiusSize="medium">
|
|
<DropdownTargetLabelSelector
|
|
selectedTargetType={formData.targetType}
|
|
selectedCustomTarget={formData.customTarget}
|
|
selectedLabels={formData.labelTargets}
|
|
customTargetOptions={CUSTOM_TARGET_OPTIONS}
|
|
className={`${formClass}__target`}
|
|
onSelectTargetType={onSelectTargetType}
|
|
onSelectCustomTarget={onSelectCustomTargetOption}
|
|
onSelectLabel={onSelectLabel}
|
|
labels={labels || []}
|
|
dropdownHelpText={
|
|
generateHelpText(false, formData.customTarget) // maps to !automaticInstall help text
|
|
}
|
|
subTitle="Changes to targets will also apply to self-service."
|
|
/>
|
|
</Card>
|
|
</div>
|
|
</div>
|
|
<ModalFooter
|
|
primaryButtons={
|
|
<>
|
|
<Button onClick={onExit} variant="secondary">
|
|
Cancel
|
|
</Button>
|
|
<GitOpsModeTooltipWrapper
|
|
entityType="software"
|
|
position="top"
|
|
tipOffset={8}
|
|
renderChildren={(disableChildren) => (
|
|
<Button
|
|
type="submit"
|
|
onClick={onSubmitForm}
|
|
isLoading={isUpdatingConfiguration}
|
|
disabled={
|
|
!formValidation.isValid ||
|
|
isUpdatingConfiguration ||
|
|
disableChildren
|
|
}
|
|
>
|
|
Save
|
|
</Button>
|
|
)}
|
|
/>
|
|
</>
|
|
}
|
|
/>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default EditAutoUpdateConfigModal;
|