Skip to content

Commit 9279eb3

Browse files
authored
fix: hidden vs disabled (#3914)
1 parent 4d29b54 commit 9279eb3

File tree

5 files changed

+73
-19
lines changed

5 files changed

+73
-19
lines changed

cypress/e2e/shared/flows.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,11 @@ describe('Flows', () => {
510510
},
511511
{
512512
panel: 'table',
513-
menuItems: [...defaultMenuItems],
513+
menuItems: [...defaultMenuItems, 'Download as CSV'],
514514
},
515515
{
516516
panel: 'visualization',
517-
menuItems: [...defaultMenuItems],
517+
menuItems: [...defaultMenuItems, 'Download as CSV'],
518518
},
519519
{
520520
panel: 'markdown',

src/flows/components/Sidebar.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ const Sidebar: FC = () => {
199199
},
200200
{
201201
title: 'Convert to |> Flux',
202-
disable: () => {
202+
hidden: () => {
203203
if (!flow.data.allIDs.includes(id)) {
204204
return true
205205
}
@@ -239,7 +239,7 @@ const Sidebar: FC = () => {
239239
{
240240
title: 'Export to Client Library',
241241
menu: <ClientList />,
242-
disable: () => {
242+
hidden: () => {
243243
if (!flow.data.allIDs.includes(id)) {
244244
return true
245245
}
@@ -255,7 +255,7 @@ const Sidebar: FC = () => {
255255
},
256256
{
257257
title: 'Link to Source',
258-
disable: () => {
258+
hidden: () => {
259259
if (!flow.data.allIDs.includes(id)) {
260260
return true
261261
}
@@ -283,7 +283,7 @@ const Sidebar: FC = () => {
283283
},
284284
{
285285
title: 'Link to Results',
286-
disable: () => {
286+
hidden: () => {
287287
if (!flow.data.allIDs.includes(id)) {
288288
return true
289289
}
@@ -317,19 +317,38 @@ const Sidebar: FC = () => {
317317
.map(section => {
318318
const links = section.actions
319319
.filter(action =>
320-
typeof action.disable === 'function'
321-
? !action.disable()
322-
: !action.disable
320+
typeof action.hidden === 'function'
321+
? !action.hidden()
322+
: !action.hidden
323323
)
324324
.map(action => {
325325
let title
326326

327+
const active =
328+
typeof action.disable === 'function'
329+
? !action.disable()
330+
: !action.disable
331+
327332
if (typeof action.title === 'function') {
328333
title = action.title()
329334
} else {
330335
title = action.title
331336
}
332337

338+
if (!active) {
339+
return (
340+
<Dropdown.Item
341+
title={title}
342+
id={title}
343+
key={title}
344+
testID={`${title}--list-item`}
345+
disabled
346+
>
347+
{title}
348+
</Dropdown.Item>
349+
)
350+
}
351+
333352
if (action.hasOwnProperty('menu')) {
334353
return (
335354
<Dropdown.Item

src/flows/pipes/Schedule/view.tsx

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@influxdata/clockface'
1313
import {parse, format_from_js_file} from '@influxdata/flux-lsp-browser'
1414
import ExportTaskButton from 'src/flows/pipes/Schedule/ExportTaskButton'
15+
import {patchTask, TaskUpdateRequest} from 'src/client'
1516

1617
// Types
1718
import {PipeProp} from 'src/types/flows'
@@ -159,6 +160,12 @@ const Schedule: FC<PipeProp> = ({Context}) => {
159160
) {
160161
offsetError = 'Invalid Time'
161162
}
163+
let latestTask
164+
if (data.task?.id) {
165+
latestTask = data.task
166+
} else if (data.task?.length) {
167+
latestTask = data.task[0]
168+
}
162169

163170
const queryText = getPanelQueries(id)?.source ?? ''
164171
const hasTaskOption = useMemo(
@@ -228,12 +235,6 @@ const Schedule: FC<PipeProp> = ({Context}) => {
228235

229236
return format_from_js_file(ast)
230237
}, [queryText, data.interval, data.offset])
231-
let latestTask
232-
if (data.task?.id) {
233-
latestTask = data.task
234-
} else if (data.task?.length) {
235-
latestTask = data.task[0]
236-
}
237238
const hasChanges = taskText !== latestTask?.flux ?? ''
238239

239240
const updateInterval = evt => {
@@ -300,12 +301,42 @@ const Schedule: FC<PipeProp> = ({Context}) => {
300301
actions: [
301302
{
302303
title: 'View Run History',
303-
menu: <History tasks={data.task.id ? data.task : data.task} />,
304+
menu: <History tasks={data.task.id ? [data.task] : data.task} />,
305+
},
306+
{
307+
title: 'Overwrite Existing Task',
308+
disable: () => !latestTask || !hasChanges,
309+
action: () => {
310+
const _data: TaskUpdateRequest = {
311+
flux: generateTask(),
312+
}
313+
if (
314+
data.interval?.match(/(?:(\d+(y|mo|s|m|w|h){1}))/g)?.join('')
315+
) {
316+
_data.every = data.interval
317+
} else {
318+
_data.cron = data.interval
319+
}
320+
321+
if (data.offset) {
322+
_data.offset = data.offset
323+
}
324+
325+
patchTask({
326+
taskID: latestTask.id,
327+
data: _data,
328+
}).then(() => {
329+
data.task.find(
330+
t => t.id === latestTask.id
331+
).flux = generateTask()
332+
update({task: [...data.task]})
333+
})
334+
},
304335
},
305336
],
306337
},
307338
])
308-
}, [id, data.task])
339+
}, [id, data.task, hasChanges])
309340

310341
const persist = (
311342
<ExportTaskButton

src/flows/pipes/Visualization/view.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,14 @@ const Visualization: FC<PipeProp> = ({Context}) => {
120120
{
121121
title: 'Download as Image',
122122
action: () => downloadAsImage(id),
123-
disable: !isFlagEnabled('pdfImageDownload'),
123+
hidden: !isFlagEnabled('pdfImageDownload'),
124+
disable: !dataExists,
124125
},
125126
{
126127
title: 'Download as PDF',
127128
action: () => downloadAsPDF(id),
128-
disable: !isFlagEnabled('pdfImageDownload'),
129+
hidden: !isFlagEnabled('pdfImageDownload'),
130+
disable: !dataExists,
129131
},
130132
],
131133
},

src/types/flows.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import {AutoRefresh, TimeRange, Variable, Secret} from 'src/types'
55
export interface ControlAction {
66
title: string | (() => string)
77
disable?: boolean | (() => boolean)
8+
hidden?: boolean | (() => boolean)
89
action: () => void
910
}
1011

1112
export interface Submenu {
1213
title: string | (() => string)
1314
disable?: boolean | (() => boolean)
15+
hidden?: boolean | (() => boolean)
1416
menu: ReactNode
1517
}
1618

0 commit comments

Comments
 (0)