Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI – Calendar events modal #17717

Merged
merged 23 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/__mocks__/configMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const DEFAULT_CONFIG_MOCK: IConfig = {
integrations: {
jira: [],
zendesk: [],
google_calendar: [],
},
logging: {
debug: false,
Expand Down
1 change: 1 addition & 0 deletions frontend/__mocks__/policyMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DEFAULT_POLICY_MOCK: IPolicyStats = {
webhook: "Off",
has_run: true,
next_update_ms: 3600000,
calendar_events_enabled: true,
};

const createMockPolicy = (overrides?: Partial<IPolicyStats>): IPolicyStats => {
Expand Down
8 changes: 7 additions & 1 deletion frontend/components/forms/FormField/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classnames from "classnames";
import { isEmpty } from "lodash";

import TooltipWrapper from "components/TooltipWrapper";
import { PlacesType } from "react-tooltip-5";

// all form-field styles are defined in _global.scss, which apply here and elsewhere
const baseClass = "form-field";
Expand All @@ -16,6 +17,7 @@ export interface IFormFieldProps {
name: string;
type: string;
tooltip?: React.ReactNode;
labelTooltipPosition?: PlacesType;
}

const FormField = ({
Expand All @@ -27,6 +29,7 @@ const FormField = ({
name,
type,
tooltip,
labelTooltipPosition,
}: IFormFieldProps): JSX.Element => {
const renderLabel = () => {
const labelWrapperClasses = classnames(`${baseClass}__label`, {
Expand All @@ -45,7 +48,10 @@ const FormField = ({
>
{error ||
(tooltip ? (
<TooltipWrapper tipContent={tooltip}>
<TooltipWrapper
tipContent={tooltip}
position={labelTooltipPosition || "top-start"}
>
{label as string}
</TooltipWrapper>
) : (
Expand Down
3 changes: 3 additions & 0 deletions frontend/components/forms/fields/InputField/InputField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class InputField extends Component {
]).isRequired,
parseTarget: PropTypes.bool,
tooltip: PropTypes.string,
labelTooltipPosition: PropTypes.string,
helpText: PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string),
Expand All @@ -55,6 +56,7 @@ class InputField extends Component {
value: "",
parseTarget: false,
tooltip: "",
labelTooltipPosition: "",
helpText: "",
enableCopy: false,
ignore1password: false,
Expand Down Expand Up @@ -124,6 +126,7 @@ class InputField extends Component {
"error",
"name",
"tooltip",
"labelTooltipPosition",
]);

const copyValue = (e) => {
Expand Down
5 changes: 4 additions & 1 deletion frontend/components/forms/fields/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import FormField from "components/forms/FormField";
import { IFormFieldProps } from "components/forms/FormField/FormField";

interface ISliderProps {
onChange: () => void;
onChange: (newValue?: {
name: string;
value: string | number | boolean;
}) => void;
value: boolean;
inactiveText: string;
activeText: string;
Expand Down
1,184 changes: 1,184 additions & 0 deletions frontend/components/graphics/CalendarEventPreview.tsx

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/components/graphics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import EmptyTeams from "./EmptyTeams";
import EmptyPacks from "./EmptyPacks";
import EmptySchedule from "./EmptySchedule";
import CollectingResults from "./CollectingResults";
import CalendarEventPreview from "./CalendarEventPreview";

export const GRAPHIC_MAP = {
// Empty state graphics
Expand All @@ -41,6 +42,7 @@ export const GRAPHIC_MAP = {
"file-pem": FilePem,
// Other graphics
"collecting-results": CollectingResults,
"calendar-event-preview": CalendarEventPreview,
};

export type GraphicNames = keyof typeof GRAPHIC_MAP;
36 changes: 36 additions & 0 deletions frontend/hooks/useCheckboxListStateManagement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useState } from "react";

import { IPolicy } from "interfaces/policy";

interface ICheckedPolicy {
name?: string;
id: number;
isChecked: boolean;
}

const useCheckboxListStateManagement = (
allPolicies: IPolicy[],
automatedPolicies: number[] | undefined
) => {
const [policyItems, setPolicyItems] = useState<ICheckedPolicy[]>(() => {
return allPolicies.map(({ name, id }) => ({
name,
id,
isChecked: !!automatedPolicies?.includes(id),
}));
});

const updatePolicyItems = (policyId: number) => {
setPolicyItems((prevItems) =>
prevItems.map((policy) =>
policy.id !== policyId
? policy
: { ...policy, isChecked: !policy.isChecked }
)
);
};

return { policyItems, updatePolicyItems };
};

export default useCheckboxListStateManagement;
4 changes: 2 additions & 2 deletions frontend/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
IWebhookFailingPolicies,
IWebhookSoftwareVulnerabilities,
} from "interfaces/webhook";
import { IIntegrations } from "./integration";
import { IGlobalIntegrations } from "./integration";

export interface ILicense {
tier: string;
Expand Down Expand Up @@ -175,7 +175,7 @@ export interface IConfig {
// databases_path: string;
// };
webhook_settings: IWebhookSettings;
integrations: IIntegrations;
integrations: IGlobalIntegrations;
logging: {
debug: boolean;
json: boolean;
Expand Down
24 changes: 24 additions & 0 deletions frontend/interfaces/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,31 @@ export interface IIntegrationFormErrors {
enableSoftwareVulnerabilities?: boolean;
}

export interface IGlobalCalendarIntegration {
email: string;
Copy link
Member

@RachelElysia RachelElysia Mar 20, 2024

Choose a reason for hiding this comment

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

api_key_json: string | null
domain: string | null

private_key: string;
domain: string;
}

interface ITeamCalendarSettings {
enable_calendar_events: boolean;
webhook_url: string;
}

// zendesk and jira fields are coupled – if one is present, the other needs to be present. If
// one is present and the other is null/missing, the other will be nullified. google_calendar is
// separated – it can be present without the other 2 without nullifying them.
// TODO: Update these types to reflect this.

export interface IIntegrations {
zendesk: IZendeskIntegration[];
jira: IJiraIntegration[];
}

export interface IGlobalIntegrations extends IIntegrations {
google_calendar?: IGlobalCalendarIntegration[] | null;
}

export interface ITeamIntegrations extends IIntegrations {
google_calendar?: ITeamCalendarSettings | null;
}
2 changes: 2 additions & 0 deletions frontend/interfaces/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface IPolicy {
created_at: string;
updated_at: string;
critical: boolean;
calendar_events_enabled: boolean;
}

// Used on the manage hosts page and other places where aggregate stats are displayed
Expand Down Expand Up @@ -90,6 +91,7 @@ export interface IPolicyFormData {
query?: string | number | boolean | undefined;
team_id?: number;
id?: number;
calendar_events_enabled?: boolean;
}

export interface IPolicyNew {
Expand Down
4 changes: 2 additions & 2 deletions frontend/interfaces/team.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from "prop-types";
import { IConfigFeatures, IWebhookSettings } from "./config";
import enrollSecretInterface, { IEnrollSecret } from "./enroll_secret";
import { IIntegrations } from "./integration";
import { ITeamIntegrations } from "./integration";
import { UserRole } from "./user";

export default PropTypes.shape({
Expand Down Expand Up @@ -82,7 +82,7 @@ export type ITeamWebhookSettings = Pick<
*/
export interface ITeamAutomationsConfig {
webhook_settings: ITeamWebhookSettings;
integrations: IIntegrations;
integrations: ITeamIntegrations;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,104 +1,9 @@
.host-actions-dropdown {
.form-field {
margin: 0;
@include button-dropdown;
.Select-multi-value-wrapper {
width: 55px;
}

.Select {
position: relative;
border: 0;
height: auto;

&.is-focused,
&:hover {
border: 0;
}

&.is-focused:not(.is-open) {
.Select-control {
background-color: initial;
}
}

.Select-control {
display: flex;
background-color: initial;
height: auto;
justify-content: space-between;
border: 0;
cursor: pointer;

&:hover {
box-shadow: none;
}

&:hover .Select-placeholder {
color: $core-vibrant-blue;
}

.Select-placeholder {
color: $core-fleet-black;
font-size: 14px;
line-height: normal;
padding-left: 0;
margin-top: 1px;
}

.Select-input {
height: auto;
}

.Select-arrow-zone {
display: flex;
}
}

.Select-multi-value-wrapper {
width: 55px;
}

.Select-placeholder {
display: flex;
align-items: center;
}

.Select-menu-outer {
margin-top: $pad-xsmall;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
border-radius: $border-radius;
z-index: 6;
overflow: hidden;
border: 0;
width: 188px;
left: unset;
top: unset;
max-height: none;
padding: $pad-small;
position: absolute;
left: -120px;

.Select-menu {
max-height: none;
}
}

.Select-arrow {
transition: transform 0.25s ease;
}

&:not(.is-open) {
.Select-control:hover .Select-arrow {
content: url("../assets/images/[email protected]");
}
}

&.is-open {
.Select-control .Select-placeholder {
color: $core-vibrant-blue;
}

.Select-arrow {
transform: rotate(180deg);
}
}
.Select > .Select-menu-outer {
left: -120px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { QueryContext } from "context/query";
import { NotificationContext } from "context/notification";

import activitiesAPI, {
IActivitiesResponse,
IPastActivitiesResponse,
IUpcomingActivitiesResponse,
} from "services/entities/activities";
Expand Down
Loading
Loading