-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d59151f
commit acc678f
Showing
25 changed files
with
532 additions
and
154 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
52 changes: 52 additions & 0 deletions
52
...poser/src/contexts/CrossWorkspaceContext/components/LocalStorageContextProvider/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,52 @@ | ||
/** ******************************************************************************************************************* | ||
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 { FC, PropsWithChildren, useCallback } from 'react'; | ||
import { DataExchangeFormat } from '../../../../customTypes'; | ||
import setLocalStorageKey from '../../../../utils/setLocalStorageKey'; | ||
import { getLocalStorageKey as getApplicationInfoLocalStorageKey } from '../../../ApplicationContext/components/LocalStorageContextProvider'; | ||
import { getLocalStorageKey as getArchitectureInfoLocalStorageKey } from '../../../ArchitectureContext/components/LocalStorageContextProvider'; | ||
import { getLocalStorageKey as getAssumptionLinksLocalStorageKey } from '../../../AssumptionLinksContext/components/LocalStorageContextProvider'; | ||
import { getLocalStorageKey as getAssumptionsListLocalStorageKey } from '../../../AssumptionsContext/components/LocalStorageContextProvider'; | ||
import { getLocalStorageKey as getDataflowInfoLocalStorageKey } from '../../../DataflowContext/components/LocalStorageContextProvider'; | ||
import { getLocalStorageKey as getMitigationLinksLocalStorageKey } from '../../../MitigationLinksContext/components/LocalStorageContextProvider'; | ||
import { getLocalStorageKey as getMitigationsLocalStorageKey } from '../../../MitigationsContext/components/LocalStorageContextProvider'; | ||
import { getLocalStorageKey as getThreatsLocalStorageKey } from '../../../ThreatsContext/components/LocalStorageContextProvider'; | ||
import { CrossWorkspaceContext } from '../../context'; | ||
|
||
|
||
const CrossWorkspaceLocalStorageContextProvider: FC<PropsWithChildren<{}>> = ({ | ||
children, | ||
}) => { | ||
const handleCloneWorkspaceData = useCallback(async (targetWorkspaceId: string, data: DataExchangeFormat) => { | ||
data.applicationInfo && setLocalStorageKey(getApplicationInfoLocalStorageKey(targetWorkspaceId), data.applicationInfo); | ||
data.architecture && setLocalStorageKey(getArchitectureInfoLocalStorageKey(targetWorkspaceId), data.architecture); | ||
data.dataflow && setLocalStorageKey(getDataflowInfoLocalStorageKey(targetWorkspaceId), data.dataflow); | ||
data.assumptions && setLocalStorageKey(getAssumptionsListLocalStorageKey(targetWorkspaceId), data.assumptions); | ||
data.threats && setLocalStorageKey(getThreatsLocalStorageKey(targetWorkspaceId), data.threats); | ||
data.mitigations && setLocalStorageKey(getMitigationsLocalStorageKey(targetWorkspaceId), data.mitigations); | ||
data.assumptionLinks && setLocalStorageKey(getAssumptionLinksLocalStorageKey(targetWorkspaceId), data.assumptionLinks); | ||
data.mitigationLinks && setLocalStorageKey(getMitigationLinksLocalStorageKey(targetWorkspaceId), data.mitigationLinks); | ||
}, []); | ||
|
||
return (<CrossWorkspaceContext.Provider value={{ | ||
cloneWorkspaceData: handleCloneWorkspaceData, | ||
}}> | ||
{children} | ||
</CrossWorkspaceContext.Provider>); | ||
}; | ||
|
||
export default CrossWorkspaceLocalStorageContextProvider; | ||
|
29 changes: 29 additions & 0 deletions
29
packages/threat-composer/src/contexts/CrossWorkspaceContext/context.ts
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,29 @@ | ||
/** ******************************************************************************************************************* | ||
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 { useContext, createContext } from 'react'; | ||
import { DataExchangeFormat } from '../../customTypes'; | ||
|
||
export interface CrossWorkspaceContextApi { | ||
cloneWorkspaceData: (targetWorkspaceId: string, data: DataExchangeFormat) => Promise<void>; | ||
} | ||
|
||
const initialState: CrossWorkspaceContextApi = { | ||
cloneWorkspaceData: () => Promise.resolve(), | ||
}; | ||
|
||
export const CrossWorkspaceContext = createContext<CrossWorkspaceContextApi>(initialState); | ||
|
||
export const useCrossWorkspaceContext = () => useContext(CrossWorkspaceContext); |
28 changes: 28 additions & 0 deletions
28
packages/threat-composer/src/contexts/CrossWorkspaceContext/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,28 @@ | ||
/** ******************************************************************************************************************* | ||
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 { FC, PropsWithChildren } from 'react'; | ||
import CrossWorkspaceLocalStorageContextProvider from './components/LocalStorageContextProvider'; | ||
import { useCrossWorkspaceContext } from './context'; | ||
|
||
const CrossWorkspaceContextProvider: FC<PropsWithChildren<{}>> = (props) => { | ||
return (<CrossWorkspaceLocalStorageContextProvider {...props} />); | ||
}; | ||
|
||
export default CrossWorkspaceContextProvider; | ||
|
||
export { | ||
useCrossWorkspaceContext, | ||
}; |
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
Oops, something went wrong.