From 45a2bbb979be2373d6a31ce125fbf51bed20e8fb Mon Sep 17 00:00:00 2001 From: Jessie Wei Date: Tue, 27 Aug 2024 10:15:49 +1000 Subject: [PATCH 1/6] feat: Allow users to set status for mitigations and threats --- .../components/generic/StatusBadge/index.tsx | 72 ++++++++++++++ .../generic/StatusSelector/index.tsx | 55 +++++++++++ .../mitigations/MitigationCard/index.tsx | 13 +++ .../mitigations/MitigationList/index.tsx | 64 +++++++++---- .../threats/MetadataEditor/index.tsx | 14 ++- .../threats/ThreatStatementCard/index.tsx | 17 +++- .../threats/ThreatStatementEditor/index.tsx | 4 + .../threats/ThreatStatementList/index.tsx | 96 +++++++++++++------ .../threat-composer/src/configs/status.ts | 30 ++++++ .../src/customTypes/entities.ts | 2 + .../src/customTypes/mitigations.ts | 9 +- .../src/customTypes/threats.ts | 9 +- .../src/data/status/mitigationStatus.json | 26 +++++ .../src/data/status/threatStatus.json | 20 ++++ .../src/utils/getNewThreatStatement/index.tsx | 1 + 15 files changed, 379 insertions(+), 53 deletions(-) create mode 100644 packages/threat-composer/src/components/generic/StatusBadge/index.tsx create mode 100644 packages/threat-composer/src/components/generic/StatusSelector/index.tsx create mode 100644 packages/threat-composer/src/configs/status.ts create mode 100644 packages/threat-composer/src/data/status/mitigationStatus.json create mode 100644 packages/threat-composer/src/data/status/threatStatus.json diff --git a/packages/threat-composer/src/components/generic/StatusBadge/index.tsx b/packages/threat-composer/src/components/generic/StatusBadge/index.tsx new file mode 100644 index 00000000..a8d4d34a --- /dev/null +++ b/packages/threat-composer/src/components/generic/StatusBadge/index.tsx @@ -0,0 +1,72 @@ +/** ******************************************************************************************************************* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ******************************************************************************************************************** */ +/** @jsxImportSource @emotion/react */ +import Badge, { BadgeProps } from '@cloudscape-design/components/badge'; +import { SelectProps } from '@cloudscape-design/components/select'; +import * as awsui from '@cloudscape-design/design-tokens'; +import { css } from '@emotion/react'; +import { FC, useMemo, useState, useRef } from 'react'; +import StatusSelector, { StatusSelectorProps } from '../StatusSelector'; + +export interface StatusBadgeProps extends Omit { + statusColorMapping: { + [status: string]: BadgeProps['color']; + }; +} + +const StatusBadge: FC = ({ + selectedOption, + setSelectedOption, + options, + statusColorMapping, +}) => { + const ref = useRef(); + + const [editMode, setEditMode] = useState(false); + + const editor = useMemo(() => { + return setEditMode(false)} + />; + }, [options, selectedOption, setSelectedOption]); + + return
{editMode ? (editor) : + ()}
; +}; + +export default StatusBadge; \ No newline at end of file diff --git a/packages/threat-composer/src/components/generic/StatusSelector/index.tsx b/packages/threat-composer/src/components/generic/StatusSelector/index.tsx new file mode 100644 index 00000000..263456bd --- /dev/null +++ b/packages/threat-composer/src/components/generic/StatusSelector/index.tsx @@ -0,0 +1,55 @@ +/** ******************************************************************************************************************* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ******************************************************************************************************************** */ +import FormField from '@cloudscape-design/components/form-field'; +import Select, { SelectProps } from '@cloudscape-design/components/select'; +import React, { FC } from 'react'; + +export interface StatusSelectorProps { + options: SelectProps.Option[]; + selectedOption?: string; + setSelectedOption?: (option: string) => void; + showLabel?: boolean; + onFocus?: () => void; + onBlur?: () => void; + ref?: React.ForwardedRef; +} + +const StatusSelector: FC = React.forwardRef(({ + options, + selectedOption, + setSelectedOption, + showLabel = true, + onFocus, + onBlur, +}, ref) => { + return ( +