-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow users to set status for mitigations and threats. Note: Th…
…is release adds a status key to the schema. Newer Threat Composer deployments can import exports from older releases without this key, but older deployments will receive a schema validation error when importing exports from this release or newer. Close #61. Close #126 (#131) * feat: Allow users to set status for mitigations and threats * chore: Incorporate the status into Threat Model Report * chore: Update insight dashboard * chore: Set initital values for mitigation and threat status * chore: Update the status as per PR feedback * chore: Change wording
- Loading branch information
1 parent
3f23ed0
commit f430b90
Showing
45 changed files
with
996 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/threat-composer/src/components/generic/StatusBadge/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StatusSelectorProps, 'showLabel'> { | ||
statusColorMapping: { | ||
[status: string]: BadgeProps['color']; | ||
}; | ||
} | ||
|
||
const StatusBadge: FC<StatusBadgeProps> = ({ | ||
selectedOption, | ||
setSelectedOption, | ||
options, | ||
statusColorMapping, | ||
}) => { | ||
const ref = useRef<SelectProps.Ref>(); | ||
|
||
const [editMode, setEditMode] = useState(false); | ||
|
||
const editor = useMemo(() => { | ||
return <StatusSelector | ||
ref={ref} | ||
showLabel={false} | ||
options={options} | ||
selectedOption={selectedOption} | ||
setSelectedOption={setSelectedOption} | ||
onBlur={() => setEditMode(false)} | ||
/>; | ||
}, [options, selectedOption, setSelectedOption]); | ||
|
||
return <div>{editMode ? (editor) : | ||
(<button | ||
onClick={() => { | ||
setEditMode(true); | ||
setTimeout(() => ref.current?.focus(), 200); | ||
}} | ||
css={css` | ||
background: none; | ||
color: inherit; | ||
border: none; | ||
padding: 0; | ||
paddingBottom: ${awsui.spaceScaledXxs}; | ||
font: inherit; | ||
cursor: pointer; | ||
outline: inherit; | ||
verticalAlign: middle; | ||
`}> | ||
<Badge color={statusColorMapping[selectedOption || 'NotSet'] || 'grey'}>{selectedOption && options.find(x => x.value === selectedOption)?.label || 'Status Not Set'}</Badge> | ||
</button>)}</div>; | ||
}; | ||
|
||
export default StatusBadge; |
55 changes: 55 additions & 0 deletions
55
packages/threat-composer/src/components/generic/StatusSelector/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<any>; | ||
} | ||
|
||
const StatusSelector: FC<StatusSelectorProps> = React.forwardRef<SelectProps.Ref, StatusSelectorProps>(({ | ||
options, | ||
selectedOption, | ||
setSelectedOption, | ||
showLabel = true, | ||
onFocus, | ||
onBlur, | ||
}, ref) => { | ||
return (<FormField | ||
label={showLabel ? 'Status' : undefined} | ||
> | ||
<Select | ||
ref={ref} | ||
selectedOption={(selectedOption && options?.find(x => x.value === selectedOption)) || null} | ||
onChange={({ detail }) => | ||
detail.selectedOption.value && setSelectedOption?.(detail.selectedOption.value) | ||
} | ||
options={options} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
placeholder='Select status' | ||
/> | ||
</FormField>); | ||
}); | ||
|
||
export default StatusSelector; |
Oops, something went wrong.