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

wip: export schema dialog #5690

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 0 additions & 15 deletions packages/compass-collection/src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,6 @@ store.onActivated = (appRegistry: AppRegistry) => {

// TODO: importing hadron-ipc in unit tests doesn't work right now
if (ipc.on) {
/**
* When `Share Schema as JSON` clicked in menu send event to the active tab.
*/
ipc.on('window:menu-share-schema-json', () => {
const state = store.getState();
if (state.tabs) {
const activeTab = state.tabs.find(
(tab: WorkspaceTabObject) => tab.isActive === true
);
if (activeTab.localAppRegistry) {
activeTab.localAppRegistry.emit('menu-share-schema-json');
}
}
});

ipc.on('compass:open-export', () => {
const state = store.getState();
if (!state.tabs) {
Expand Down
2 changes: 2 additions & 0 deletions packages/compass-schema/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const configureActions = () => {
geoLayerAdded: { sync: true },
geoLayersEdited: { sync: true },
geoLayersDeleted: { sync: true },
openExportSchema: { sync: true },
closeExportSchema: { sync: true },
});
};

Expand Down
16 changes: 16 additions & 0 deletions packages/compass-schema/src/components/compass-schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import {
useDarkMode,
WorkspaceContainer,
lighten,
ConfirmationModal,
InfoModal,
} from '@mongodb-js/compass-components';
import { ExportSchemaModal } from './export-schema/export-schema-modal';

const rootStyles = css`
width: 100%;
Expand Down Expand Up @@ -329,6 +332,7 @@ const Schema: React.FunctionComponent<{
schema?: any;
count?: number;
resultId?: string;
exportSchemaOpened?: boolean;
}> = ({
actions,
store,
Expand All @@ -338,6 +342,7 @@ const Schema: React.FunctionComponent<{
errorMessage,
schema,
resultId,
exportSchemaOpened,
}) => {
useEffect(() => {
if (isActiveTab) {
Expand All @@ -357,6 +362,10 @@ const Schema: React.FunctionComponent<{
actions.startAnalysis();
}, [actions]);

const onExportSchemaClicked = useCallback(() => {
actions.openExportSchema();
}, [actions]);

return (
<div className={rootStyles}>
<WorkspaceContainer
Expand All @@ -365,6 +374,7 @@ const Schema: React.FunctionComponent<{
localAppRegistry={store.localAppRegistry}
onAnalyzeSchemaClicked={onApplyClicked}
onResetClicked={onResetClicked}
onExportSchemaClicked={onExportSchemaClicked}
analysisState={analysisState}
errorMessage={errorMessage || ''}
isOutdated={!!outdated}
Expand All @@ -388,6 +398,12 @@ const Schema: React.FunctionComponent<{
/>
)}
</WorkspaceContainer>

<ExportSchemaModal
schema={schema}
closeExportSchema={actions.closeExportSchema}
exportSchemaOpened={!!exportSchemaOpened}
></ExportSchemaModal>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { Button, css, cx, Icon } from '@mongodb-js/compass-components';
import React, { useCallback, useEffect, useState } from 'react';

const actionButtonStyle = css({
flex: 'none',
});

const actionButtonContentStyle = css({
position: 'relative',
});

const actionButtonIconContainerStyle = css({
opacity: 1,
// leafygreen icon small size
width: 14,
height: 14,
transition: 'opacity .2s linear',
});

const actionButtonIconContainerHiddenStyle = css({
opacity: 0,
});

const actionButtonClickResultIconStyle = css({
position: 'absolute',
// leafygreen icon small size
width: 14,
height: 14,
top: 0,
pointerEvents: 'none',
opacity: 1,
transition: 'opacity .2s linear',
});

const actionButtonClickResultIconHiddenStyle = css({
opacity: 0,
});

const ActionButton: React.FunctionComponent<{
icon: string | React.ReactNode;
label: string;
onClick: (
...args: Parameters<React.MouseEventHandler<HTMLButtonElement>>
) => boolean | void;
}> = ({ label, icon, onClick }) => {
const [clickResult, setClickResult] = useState<'success' | 'error'>(
'success'
);
const [clickResultVisible, setClickResultVisible] = useState(false);

const onButtonClick = useCallback(
(...args: Parameters<React.MouseEventHandler<HTMLButtonElement>>) => {
const result = onClick(...args);
if (typeof result === 'boolean') {
setClickResult(result ? 'success' : 'error');
setClickResultVisible(true);
}
},
[onClick]
);

useEffect(() => {
if (!clickResultVisible) {
return;
}

const timeoutId = setTimeout(() => {
setClickResultVisible(false);
}, 1000);

return () => {
clearTimeout(timeoutId);
};
}, [clickResultVisible]);

return (
<Button
size="xsmall"
aria-label={label}
title={label}
onClick={onButtonClick}
className={actionButtonStyle}
>
<div className={actionButtonContentStyle}>
<div
className={cx(
actionButtonIconContainerStyle,
clickResultVisible && actionButtonIconContainerHiddenStyle
)}
>
{typeof icon === 'string' ? (
<Icon
size="small"
role="presentation"
title={null}
glyph={icon}
></Icon>
) : (
icon
)}
</div>
<div
className={cx(
actionButtonClickResultIconStyle,
!clickResultVisible && actionButtonClickResultIconHiddenStyle
)}
>
<Icon
size="small"
glyph={clickResult === 'success' ? 'Checkmark' : 'X'}
></Icon>
</div>
</div>
</Button>
);
};

export { ActionButton };
Loading