Skip to content

Commit e92aec5

Browse files
authored
fix(bug): use path property to import nested package (#4527)
* feat(notebooks): use func.path if package is nested * feat: use func.path to import nested package * fix: prettier * chore: clean up * empty
1 parent 8b772b5 commit e92aec5

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/flows/pipes/RawFluxEditor/view.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,22 @@ const Query: FC<PipeProp> = ({Context}) => {
8282
text = ` |> ${fn.example}`
8383
}
8484

85+
const getHeader = fn => {
86+
let importStatement = null
87+
88+
if (fn.package) {
89+
importStatement = `import "${fn.package}"`
90+
if (isFlagEnabled('fluxDynamicDocs') && fn.path.includes('/')) {
91+
importStatement = `import "${fn.path}"`
92+
}
93+
}
94+
return importStatement
95+
}
96+
8597
const options = {
8698
text,
8799
type: InjectionType.OnOwnLine,
88-
header: !!fn.package ? `import "${fn.package}"` : null,
100+
header: getHeader(fn),
89101
}
90102
inject(options)
91103
},

src/timeMachine/components/TimeMachineFluxEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ const TimeMachineFluxEditor: FC = () => {
143143
]
144144
const importStatement = generateImport(
145145
func.package,
146-
editorInstance.getValue()
146+
editorInstance.getValue(),
147+
func as FluxFunction
147148
)
148149
if (importStatement) {
149150
edits.unshift({

src/timeMachine/utils/insertFunction.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// Constants
2+
import {CLOUD} from 'src/shared/constants'
23
import {FROM, UNION} from 'src/shared/constants/fluxFunctions'
34

5+
// Types
6+
import {FluxFunction} from 'src/types/shared'
7+
8+
// Utils
9+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
10+
411
export const functionRequiresNewLine = (funcName: string): boolean => {
512
switch (funcName) {
613
case FROM.name:
@@ -14,9 +21,19 @@ export const functionRequiresNewLine = (funcName: string): boolean => {
1421

1522
export const generateImport = (
1623
funcPackage: string,
17-
script: string
18-
): false | string => {
19-
const importStatement = `import "${funcPackage}"`
24+
script: string,
25+
func?: FluxFunction
26+
): false | string | FluxFunction => {
27+
let importStatement
28+
29+
importStatement = `import "${funcPackage}"`
30+
31+
if (CLOUD && isFlagEnabled('fluxDynamicDocs')) {
32+
// if package is nested, use func.path to import.
33+
if (func.path.includes('/')) {
34+
importStatement = `import "${func.path}"`
35+
}
36+
}
2037

2138
if (!funcPackage || script.includes(importStatement)) {
2239
return false

0 commit comments

Comments
 (0)