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

[jk] Data loader templates UI #658

Merged
merged 7 commits into from
Jul 15, 2022
Merged
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
Prev Previous commit
Next Next commit
[jk] Add data loader based on type of data source
  • Loading branch information
johnson-mage committed Jul 14, 2022
commit 47219525a2f9b995b7ddc68b03eb52433e020eda
65 changes: 47 additions & 18 deletions mage_ai/frontend/components/PipelineDetail/AddNewBlocks/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
import BlockType, { BlockTypeEnum } from '@interfaces/BlockType';
import { useRef, useState } from 'react';

import FlexContainer from '@oracle/components/FlexContainer';
import FlyoutMenuWrapper from '@oracle/components/FlyoutMenu/FlyoutMenuWrapper';
import KeyboardShortcutButton from '@oracle/elements/Button/KeyboardShortcutButton';
import Spacing from '@oracle/elements/Spacing';
import { Add } from '@oracle/icons';
import { BlockRequestPayloadType, BlockTypeEnum } from '@interfaces/BlockType';
import {
DATA_SOURCE_TYPES,
DATA_SOURCE_TYPE_HUMAN_READABLE_NAME_MAPPING,
DataSourceTypeEnum,
} from '@interfaces/DataSourceType';
import {
ICON_SIZE,
IconContainerStyle,
} from './index.style';

type AddNewBlocksProps = {
addNewBlock: (block: BlockType) => void;
addNewBlock: (block: BlockRequestPayloadType) => void;
compact?: boolean;
};

function AddNewBlocks({
addNewBlock,
compact,
}: AddNewBlocksProps) {
const [buttonMenuOpenIndex, setButtonMenuOpenIndex] = useState(null);
const dataLoaderButtonRef = useRef(null);
const sharedProps = {
compact,
inline: true,
};

const dataLoaderMenuItems = DATA_SOURCE_TYPES.map((sourceType: DataSourceTypeEnum) => ({
label: () => DATA_SOURCE_TYPE_HUMAN_READABLE_NAME_MAPPING[sourceType],
onClick: () => {
addNewBlock({
config: {
data_source: sourceType,
},
type: BlockTypeEnum.DATA_LOADER,
});
},
uuid: sourceType,
}));

return (
<FlexContainer inline>
<KeyboardShortcutButton
Expand All @@ -44,23 +67,29 @@ function AddNewBlocks({

<Spacing ml={1} />

<KeyboardShortcutButton
{...sharedProps}
beforeElement={
<IconContainerStyle blue compact={compact}>
<Add size={compact ? ICON_SIZE / 2 : ICON_SIZE} />
</IconContainerStyle>
}
onClick={(e) => {
e.preventDefault();
addNewBlock({
type: BlockTypeEnum.DATA_LOADER,
});
}}
uuid="AddNewBlocks/Data_loader"
<FlyoutMenuWrapper
items={dataLoaderMenuItems}
onClickOutside={() => setButtonMenuOpenIndex(null)}
open={buttonMenuOpenIndex === 1}
parentRef={dataLoaderButtonRef}
uuid="data_loader_button"
>
Data loader
</KeyboardShortcutButton>
<KeyboardShortcutButton
{...sharedProps}
beforeElement={
<IconContainerStyle blue compact={compact}>
<Add size={compact ? ICON_SIZE / 2 : ICON_SIZE} />
</IconContainerStyle>
}
onClick={(e) => {
e.preventDefault();
setButtonMenuOpenIndex(val => (val === 1) ? null : 1);
}}
uuid="AddNewBlocks/Data_loader"
>
Data loader
</KeyboardShortcutButton>
</FlyoutMenuWrapper>

<Spacing ml={1} />

Expand Down