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

fix: Fix an issue where the import modal popup when switching workspace #40

Merged
merged 1 commit into from
Aug 30, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import SwitchToExample from '../../../assets/switch-to-example-workspace.gif';
import { useGlobalSetupContext } from '../../../contexts';

const LandingPage: FC = () => {
const { onShowImport, onDefineWorkload } = useGlobalSetupContext();
const { setFileImportModalVisible, onDefineWorkload } = useGlobalSetupContext();
return (
<ContentLayout
header={
Expand All @@ -37,7 +37,7 @@ const LandingPage: FC = () => {
description="A threat modeling tool to help humans to reduce time-to-value when threat modeling"
actions={
<SpaceBetween direction="horizontal" size="s">
<Button onClick={onShowImport}>Import existing</Button>
<Button onClick={() => setFileImportModalVisible(true)}>Import existing</Button>
<Button variant="primary" onClick={onDefineWorkload}>
Define workload or feature
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ButtonDropdown, { ButtonDropdownProps } from '@cloudscape-design/componen
import { CancelableEventHandler, NonCancelableEventHandler } from '@cloudscape-design/components/internal/events';
import Select, { SelectProps } from '@cloudscape-design/components/select';
import SpaceBetween from '@cloudscape-design/components/space-between';
import { FC, useMemo, useState, useCallback, PropsWithChildren, useEffect } from 'react';
import { FC, useMemo, useState, useCallback, PropsWithChildren } from 'react';
import {
DEFAULT_WORKSPACE_ID,
DEFAULT_WORKSPACE_LABEL,
Expand Down Expand Up @@ -51,7 +51,6 @@ const WorkspaceSelector: FC<PropsWithChildren<WorkspaceSelectorProps>> = ({
enabledRemoveAll,
filteredThreats,
}) => {
const [fileImportModalVisible, setFileImportModalVisible] = useState(false);
const [addWorkspaceModalVisible, setAddWorkspaceModalVisible] = useState(false);
const [editWorkspaceModalVisible, setEditWorkspaceModalVisible] = useState(false);
const [removeDataModalVisible, setRemoveDataModalVisible] = useState(false);
Expand All @@ -60,11 +59,14 @@ const WorkspaceSelector: FC<PropsWithChildren<WorkspaceSelectorProps>> = ({

const { importData, exportAll, exportSelectedThreats } = useImportExport();
const { removeData, deleteCurrentWorkspace } = useRemoveData();
const { composerMode, onPreview, onPreviewClose, onImported, showImportUpdate } = useGlobalSetupContext();

useEffect(() => {
showImportUpdate && setFileImportModalVisible(true);
}, [showImportUpdate]);
const {
composerMode,
onPreview,
onPreviewClose,
onImported,
fileImportModalVisible,
setFileImportModalVisible,
} = useGlobalSetupContext();

const {
currentWorkspace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@
See the License for the specific language governing permissions and
limitations under the License.
******************************************************************************************************************** */
import { useContext, createContext } from 'react';
import React, { useContext, createContext } from 'react';
import { ComposerMode, DataExchangeFormat } from '../../customTypes';

export interface GlobalSetupContextApi {
hasVisitBefore: boolean;
showInfoModal: () => void;
composerMode: ComposerMode;
showImportUpdate: number;
onPreview?: (content: DataExchangeFormat) => void;
onPreviewClose?: () => void;
onImported?: () => void;
onShowImport?: () => void;
onDefineWorkload?: () => void;
fileImportModalVisible: boolean;
setFileImportModalVisible: React.Dispatch<React.SetStateAction<boolean>>;
}

const initialState: GlobalSetupContextApi = {
hasVisitBefore: false,
composerMode: 'Full',
showInfoModal: () => { },
showImportUpdate: 0,
fileImportModalVisible: false,
setFileImportModalVisible: () => {},
};

export const GlobalSetupContext = createContext<GlobalSetupContextApi>(initialState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ const GlobalSetupContextProvider: FC<PropsWithChildren<GlobalSetupContextProvide
onImported,
onDefineWorkload,
}) => {
const [fileImportModalVisible, setFileImportModalVisible] = useState(false);

const [hasVisitBefore, setHasVisitBefore] = useLocalStorageState<boolean>(LOCAL_STORAGE_KEY_NEW_VISIT_FLAG, {
defaultValue: false,
});

const [infoModalVisible, setInfoModalVisible] = useState(false);
const [showImportUpdate, setShowImportUpdate] = useState(0);

useEffect(() => {
if (!hasVisitBefore) {
Expand All @@ -61,8 +62,8 @@ const GlobalSetupContextProvider: FC<PropsWithChildren<GlobalSetupContextProvide
onPreview,
onPreviewClose,
onImported,
showImportUpdate,
onShowImport: () => setShowImportUpdate(prev => prev+1),
fileImportModalVisible,
setFileImportModalVisible,
onDefineWorkload,
}}>
{children}
Expand Down