Skip to content

Commit bf2b548

Browse files
authored
feat: inject pipe-forward operator only when necessary (#4546)
* feat: only add |> sign for fluxtypes with <- * fix: prettier * fix: target <- with String.startsWith() * fix: prettier * test: remove pipe-forward operator
1 parent 1a24896 commit bf2b548

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

cypress/e2e/cloud/explorer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('DataExplorer', () => {
6060
cy.getByTestID('flux--microsecond--inject').click()
6161

6262
getTimeMachineText().then(text => {
63-
const expected = 'import "date" |> date.microsecond(t: )'
63+
const expected = 'import "date" date.microsecond(t: )'
6464
cy.fluxEqual(text, expected).should('be.true')
6565
})
6666
})

src/flows/pipes/RawFluxEditor/view.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,17 @@ const Query: FC<PipeProp> = ({Context}) => {
7676
const injectIntoEditor = useCallback(
7777
(fn): void => {
7878
let text = ''
79-
if (fn.name === 'from' || fn.name === 'union') {
80-
text = `${fn.example}`
79+
if (CLOUD && isFlagEnabled('fluxDynamicDocs')) {
80+
// only fluxTypes with <- sign require a pipe forward sign
81+
text = fn.fluxType.startsWith('<-', 1)
82+
? ` |> ${fn.example}`
83+
: `${fn.example}`
8184
} else {
82-
text = ` |> ${fn.example}`
85+
if (fn.name === 'from' || fn.name === 'union') {
86+
text = `${fn.example}`
87+
} else {
88+
text = ` |> ${fn.example}`
89+
}
8390
}
8491

8592
const getHeader = fn => {
@@ -88,7 +95,11 @@ const Query: FC<PipeProp> = ({Context}) => {
8895
// universe packages are loaded by deafult. Don't need import statement
8996
if (fn.package && fn.package !== 'universe') {
9097
importStatement = `import "${fn.package}"`
91-
if (isFlagEnabled('fluxDynamicDocs') && fn.path.includes('/')) {
98+
if (
99+
CLOUD &&
100+
isFlagEnabled('fluxDynamicDocs') &&
101+
fn.path.includes('/')
102+
) {
92103
importStatement = `import "${fn.path}"`
93104
}
94105
}

src/timeMachine/components/TimeMachineFluxEditor.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,22 @@ const TimeMachineFluxEditor: FC = () => {
104104

105105
let text = ''
106106
if (shouldInsertOnNextLine) {
107-
text = `\n |> ${func.example}`
107+
if (CLOUD && isFlagEnabled('fluxDynamicDocs')) {
108+
// only fluxTypes with <- sign require a pipe forward sign
109+
text = func.fluxType.startsWith('<-', 1)
110+
? `\n |> ${func.example}`
111+
: `\n ${func.example}`
112+
} else {
113+
text = `\n |> ${func.example}`
114+
}
108115
} else {
109-
text = ` |> ${func.example}\n`
116+
if (CLOUD && isFlagEnabled('fluxDynamicDocs')) {
117+
text = func.fluxType.startsWith('<-', 1)
118+
? ` |> ${func.example}\n`
119+
: ` ${func.example}\n`
120+
} else {
121+
text = ` |> ${func.example}\n`
122+
}
110123
}
111124

112125
if (functionRequiresNewLine(func.name)) {

0 commit comments

Comments
 (0)