Skip to content

Commit

Permalink
fix: Hide Download/Export buttons for IDE Extension mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieweiyi committed May 16, 2024
1 parent 9d972ea commit d8dd7ff
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ import ThreatModelReport from '../../../ThreatModelReport';
const TEMP_PREVIEW_DATA_KEY = 'ThreatStatementGenerator.TempPreviewData';

const defaultHref = process.env.PUBLIC_URL || '/';
const appMode = process.env.REACT_APP_APP_MODE;
const appModeEnv = process.env.REACT_APP_APP_MODE;

const appMode = appModeEnv === APP_MODE_BROWSER_EXTENSION ?
APP_MODE_BROWSER_EXTENSION :
(appModeEnv === APP_MODE_IDE_EXTENSION ?
APP_MODE_IDE_EXTENSION : undefined);

const AppInner: FC<{
setWorkspaceId: React.Dispatch<React.SetStateAction<string>>;
Expand Down Expand Up @@ -203,6 +208,7 @@ const Full: FC = () => {

return (
<ContextAggregator
appMode={appMode}
composerMode='Full'
onWorkspaceChanged={handleWorkspaceChanged}
onApplicationInfoView={() => handleNavigationView(ROUTE_APPLICATION_INFO)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const styles = {

export interface ThreatModelViewProps extends ViewNavigationEvent {
isPreview?: boolean;
showPrintDownloadButtons?: boolean;
composerMode: string;
data: DataExchangeFormat;
downloadFileName?: string;
Expand All @@ -66,6 +67,7 @@ export interface ThreatModelViewProps extends ViewNavigationEvent {
const ThreatModelView: FC<ThreatModelViewProps> = ({
data,
isPreview = false,
showPrintDownloadButtons = true,
composerMode,
downloadFileName,
onPrintButtonClick,
Expand Down Expand Up @@ -150,11 +152,11 @@ const ThreatModelView: FC<ThreatModelViewProps> = ({
Copy as Markdown
</Button>
</Popover>
{downloadFileName && <Button
{downloadFileName && showPrintDownloadButtons && <Button
onClick={handleDownloadMarkdown}>
Download as Markdown File
</Button>}
<Button variant="primary" onClick={onPrintButtonClick || (() => window.print())}>Print</Button>
{showPrintDownloadButtons && <Button variant="primary" onClick={onPrintButtonClick || (() => window.print())}>Print</Button>}
</SpaceBetween>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
******************************************************************************************************************** */
import { FC, useMemo } from 'react';
import ThreatModelView from './components/ThreatModelView';
import { APP_MODE_IDE_EXTENSION } from '../../../configs/appMode';
import { useGlobalSetupContext, useWorkspacesContext } from '../../../contexts';
import useImportExport from '../../../hooks/useExportImport';
import useHasContent from '../../../hooks/useHasContent';
Expand All @@ -30,7 +31,7 @@ const ThreatModel: FC<ThreatModelProps> = ({
...props
}) => {
const { getWorkspaceData } = useImportExport();
const { composerMode } = useGlobalSetupContext();
const { composerMode, appMode } = useGlobalSetupContext();
const [_, hasContentDetails] = useHasContent();
const { currentWorkspace } = useWorkspacesContext();

Expand All @@ -49,6 +50,7 @@ const ThreatModel: FC<ThreatModelProps> = ({
return <ThreatModelView
{...props}
onPrintButtonClick={onPrintButtonClick}
showPrintDownloadButtons={appMode !== APP_MODE_IDE_EXTENSION}
composerMode={composerMode}
data={getWorkspaceData()}
downloadFileName={downloadFileName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import Select, { SelectProps } from '@cloudscape-design/components/select';
import SpaceBetween from '@cloudscape-design/components/space-between';
import { FC, useMemo, useState, useCallback, PropsWithChildren } from 'react';
import { APP_MODE_IDE_EXTENSION } from '../../../configs';
import {
DEFAULT_WORKSPACE_ID,
DEFAULT_WORKSPACE_LABEL,
Expand Down Expand Up @@ -83,6 +84,7 @@ const WorkspaceSelector: FC<PropsWithChildren<WorkspaceSelectorProps>> = ({
const { removeData, deleteWorkspace } = useRemoveData();

const {
appMode,
composerMode,
onPreview,
onPreviewClose,
Expand Down Expand Up @@ -238,7 +240,7 @@ const WorkspaceSelector: FC<PropsWithChildren<WorkspaceSelectorProps>> = ({
const buttonDropdownItems = useMemo(() => {
const items: ButtonDropdownProps.Item[] = [];

if (singletonMode && singletonPrimaryActionButtonConfig) {
if (singletonMode && singletonPrimaryActionButtonConfig && appMode !== APP_MODE_IDE_EXTENSION) {
// If primary action button is not specified, use Export data as primary action button in Singleton app mode.
items.push({
id: 'exportAll',
Expand Down Expand Up @@ -330,8 +332,7 @@ const WorkspaceSelector: FC<PropsWithChildren<WorkspaceSelectorProps>> = ({
controlId="WorkspacesSelect"
selectedOption={{
value: currentWorkspace?.id || DEFAULT_WORKSPACE_ID,
label: `Workspace: ${
currentWorkspace?.name || DEFAULT_WORKSPACE_LABEL
label: `Workspace: ${currentWorkspace?.name || DEFAULT_WORKSPACE_LABEL
}`,
}}
options={workspacesOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
limitations under the License.
******************************************************************************************************************** */
import { FC, PropsWithChildren } from 'react';
import { ComposerMode, DataExchangeFormat, ViewNavigationEvent } from '../../customTypes';
import { AppMode, ComposerMode, DataExchangeFormat, ViewNavigationEvent } from '../../customTypes';
import GlobalSetupContextProvider from '../GlobalSetupContext';
import WorkspaceContextAggregator from '../WorkspaceContextAggregator';
import WorkspaceExamplesContext from '../WorkspaceExamplesContext';
import WorkspacesContextProvider, { WorkspacesContextProviderProps } from '../WorkspacesContext';

export interface ContextAggregatorProps extends ViewNavigationEvent {
composerMode?: ComposerMode;
appMode?: AppMode;
features?: string[];
onWorkspaceChanged?: WorkspacesContextProviderProps['onWorkspaceChanged'];
onPreview?: (content: DataExchangeFormat) => void;
Expand All @@ -33,6 +34,7 @@ export interface ContextAggregatorProps extends ViewNavigationEvent {
const ContextAggregator: FC<PropsWithChildren<ContextAggregatorProps>> = ({
children,
onWorkspaceChanged,
appMode,
composerMode = 'Full',
features,
onPreview,
Expand All @@ -48,6 +50,7 @@ const ContextAggregator: FC<PropsWithChildren<ContextAggregatorProps>> = ({
onImported={onImported}
features={features}
onDefineWorkload={onDefineWorkload}
appMode={appMode}
composerMode={composerMode}>
<WorkspaceExamplesContext>
<WorkspacesContextProvider
Expand Down

0 comments on commit d8dd7ff

Please sign in to comment.