Skip to content

Commit 1feb7b2

Browse files
authored
[jk] Reuse callback and conditional blocks (mage-ai#4562)
* [jk] Support drag and drop callback and conditional blocks * [jk] Include callback and conditional blocks in block search * [jk] Do not add upstream blocks when adding to integration pipeline
1 parent 2d0ba80 commit 1feb7b2

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

mage_ai/api/resources/SearchResultResource.py

-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ def filter_results(result: Dict) -> bool:
4242
return False
4343

4444
if block_type in [
45-
BlockType.CALLBACK,
4645
BlockType.CHART,
47-
BlockType.CONDITIONAL,
4846
BlockType.EXTENSION,
4947
]:
5048
return False

mage_ai/frontend/components/FileBrowser/index.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { ThemeContext } from 'styled-components';
1313
import { useMutation } from 'react-query';
1414
import { createPortal } from 'react-dom';
1515

16-
import BlockType, { BlockRequestPayloadType, BlockTypeEnum } from '@interfaces/BlockType';
16+
import BlockType, {
17+
ADD_ON_BLOCK_TYPES,
18+
BlockRequestPayloadType,
19+
BlockTypeEnum,
20+
} from '@interfaces/BlockType';
1721
import FileHeaderMenu from './FileHeaderMenu';
1822
import FileType from '@interfaces/FileType';
1923
import FlyoutMenu from '@oracle/components/FlyoutMenu';
@@ -323,7 +327,10 @@ function FileBrowser({
323327
require_unique_name: false,
324328
},
325329
block => {
326-
if (isIntegrationPipeline && dataExporterBlock) {
330+
if (isIntegrationPipeline
331+
&& dataExporterBlock
332+
&& !ADD_ON_BLOCK_TYPES.includes(block.type)
333+
) {
327334
// @ts-ignore
328335
updateDestinationBlock({
329336
block: {
@@ -411,7 +418,7 @@ function FileBrowser({
411418
const selectedBlock = useMemo(() => selectedFile && getBlockFromFile(selectedFile), [
412419
selectedFile,
413420
]);
414-
const draggingBlock = useMemo(() => draggingFile && getBlockFromFile(draggingFile), [
421+
const draggingBlock = useMemo(() => draggingFile && getBlockFromFile(draggingFile, null, true), [
415422
draggingFile,
416423
]);
417424

mage_ai/frontend/components/FileBrowser/utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import FileType, {
2222
} from '@interfaces/FileType';
2323
import { groupBy, prependArray, removeAtIndex, sortByKey } from '@utils/array';
2424
import { getBlockType } from '@components/FileEditor/utils';
25-
import { dig } from '@utils/hash';
2625
import { cleanName, singularize } from '@utils/string';
2726

2827
export function getFullPath(
@@ -123,7 +122,7 @@ export function getBlockFromFile(
123122
}
124123

125124
const blockTypesToInclude = draggableBlockTypesOnly ? DRAGGABLE_BLOCK_TYPES : BLOCK_TYPES;
126-
if (blockTypesToInclude.concat(BlockTypeEnum.DBT).includes(blockType) && validBlockFileExtension(fileName)) {
125+
if (blockTypesToInclude.includes(blockType) && validBlockFileExtension(fileName)) {
127126
const idx = fileName.lastIndexOf('.');
128127
const extension = fileName.slice(idx + 1);
129128

mage_ai/frontend/components/FileEditor/index.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ import {
4343
getBlockType,
4444
} from './utils';
4545
import { find } from '@utils/array';
46-
import { getBlockFromFile } from '../FileBrowser/utils';
47-
import { getFullPath } from '@utils/files';
48-
import { getNonPythonBlockFromFile } from '@components/FileBrowser/utils';
4946
import { isJsonString } from '@utils/string';
5047
import { errorOrSuccess, onSuccess } from '@api/utils/response';
5148
import { onlyKeysPresent } from '@utils/hooks/keyboardShortcuts/utils';

mage_ai/frontend/components/FileEditor/utils.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as osPath from 'path';
22
import BlockType, {
3+
ADD_ON_BLOCK_TYPES,
34
ALL_BLOCK_TYPES,
45
ALL_BLOCK_TYPES_WITH_SINGULAR_FOLDERS,
56
BlockColorEnum,
@@ -27,7 +28,7 @@ export const getBlockType = (path: string[]): BlockTypeEnum => {
2728
let part2 = part?.toLowerCase();
2829

2930
if (part2 in ALL_BLOCK_TYPES_WITH_SINGULAR_FOLDERS) {
30-
value = part2
31+
value = part2;
3132
} else {
3233
part2 = singularize(part2);
3334
if (part2 in ALL_BLOCK_TYPES) {
@@ -50,7 +51,8 @@ export const getBlockType = (path: string[]): BlockTypeEnum => {
5051
const extensionRegex = new RegExp(`${extensions}$`);
5152
const fileName = path.join(osPath.sep);
5253

53-
if (fileName.match(extensionRegex)) {
54+
if (fileName.match(extensionRegex)
55+
&& (path.includes(BlockTypeEnum.DBT) || path.includes('dbts'))) {
5456
return BlockTypeEnum.DBT;
5557
}
5658
}
@@ -121,7 +123,7 @@ export function buildAddBlockRequestPayload(
121123
blockReqPayload.color = BlockColorEnum.TEAL;
122124
}
123125

124-
if (isIntegrationPipeline) {
126+
if (isIntegrationPipeline && !ADD_ON_BLOCK_TYPES.includes(blockType)) {
125127
const dataLoaderBlock: BlockType = find(pipeline.blocks, ({ type }) => BlockTypeEnum.DATA_LOADER === type);
126128
const transformerBlock: BlockType = find(pipeline.blocks, ({ type }) => BlockTypeEnum.TRANSFORMER === type);
127129
const upstreamBlocks = [];

mage_ai/frontend/interfaces/BlockType.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export const SIDEKICK_BLOCK_TYPES = [
7474
BlockTypeEnum.EXTENSION,
7575
];
7676

77+
export const ADD_ON_BLOCK_TYPES = [
78+
BlockTypeEnum.CALLBACK,
79+
BlockTypeEnum.CONDITIONAL,
80+
];
81+
7782
export enum BlockColorEnum {
7883
BLUE = 'blue',
7984
GREY = 'grey',
@@ -88,19 +93,23 @@ export const BLOCK_TYPES = [
8893
BlockTypeEnum.CUSTOM,
8994
BlockTypeEnum.DATA_EXPORTER,
9095
BlockTypeEnum.DATA_LOADER,
96+
BlockTypeEnum.DBT,
97+
BlockTypeEnum.MARKDOWN,
9198
BlockTypeEnum.SCRATCHPAD,
9299
BlockTypeEnum.SENSOR,
93-
BlockTypeEnum.MARKDOWN,
94100
BlockTypeEnum.TRANSFORMER,
95101
];
96102

97103
export const DRAGGABLE_BLOCK_TYPES = [
104+
BlockTypeEnum.CALLBACK,
105+
BlockTypeEnum.CONDITIONAL,
98106
BlockTypeEnum.CUSTOM,
99107
BlockTypeEnum.DATA_EXPORTER,
100108
BlockTypeEnum.DATA_LOADER,
109+
BlockTypeEnum.DBT,
110+
BlockTypeEnum.MARKDOWN,
101111
BlockTypeEnum.SCRATCHPAD,
102112
BlockTypeEnum.SENSOR,
103-
BlockTypeEnum.MARKDOWN,
104113
BlockTypeEnum.TRANSFORMER,
105114
];
106115

mage_ai/frontend/interfaces/FileType.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const FILE_EXTENSION_PRIORITY = {
7878
[FileExtensionEnum.JSON]: 6,
7979
[FileExtensionEnum.CSV]: 7,
8080
[FileExtensionEnum.SH]: 8,
81-
}
81+
};
8282

8383
export const SUPPORTED_EDITABLE_FILE_EXTENSIONS_REGEX =
8484
new RegExp(SUPPORTED_EDITABLE_FILE_EXTENSIONS.map(ext => `\.${ext}$`).join('|'));

0 commit comments

Comments
 (0)