-
Notifications
You must be signed in to change notification settings - Fork 239
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
feat: Added button to execute all query cells in a datadoc after the current cell #1296
base: master
Are you sure you want to change the base?
Changes from all commits
fa47090
0925d12
0ca1252
c17ba0a
0aa1346
eea9a63
259201d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import React, { useCallback, useMemo, useState } from 'react'; | ||
|
||
import { useQueryCells } from 'hooks/dataDoc/useQueryCells'; | ||
import { Message } from 'ui/Message/Message'; | ||
import { ToggleSwitch } from 'ui/ToggleSwitch/ToggleSwitch'; | ||
import { useMakeSelector } from '../../hooks/redux/useMakeSelector'; | ||
import { makeLatestQueryExecutionsSelector } from '../../redux/queryExecutions/selector'; | ||
import { QueryExecutionStatus } from '../../const/queryExecution'; | ||
|
||
interface IProps { | ||
defaultNotification: boolean; | ||
onNotificationChange: (notification: boolean) => void; | ||
hasQueryRunning: boolean; | ||
queryCells: ReturnType<typeof useQueryCells>; | ||
docId: number; | ||
index?: number; | ||
} | ||
|
||
export const DataDocRunAllButtonConfirm: React.FunctionComponent<IProps> = ({ | ||
defaultNotification, | ||
onNotificationChange, | ||
hasQueryRunning, | ||
queryCells, | ||
docId, | ||
index, | ||
}) => { | ||
const [notification, setNotification] = useState(defaultNotification); | ||
|
||
|
@@ -27,6 +30,20 @@ export const DataDocRunAllButtonConfirm: React.FunctionComponent<IProps> = ({ | |
[onNotificationChange, setNotification] | ||
); | ||
|
||
let queryCells = useQueryCells(docId); | ||
if (index !== undefined) { | ||
queryCells = queryCells.slice(index); | ||
} | ||
|
||
Comment on lines
+34
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the index of the query cell in the datadoc, including text cells? e.g. what if there is a text cell before the starting query cell, is the slicing still correct? same for the |
||
const latestQueryExecutions = useMakeSelector( | ||
makeLatestQueryExecutionsSelector, | ||
queryCells.map((c) => c.id) ?? [] | ||
); | ||
const hasQueryRunning = useMemo( | ||
() => latestQueryExecutions.some((q) => QueryExecutionStatus.DONE), | ||
[latestQueryExecutions] | ||
); | ||
|
||
return ( | ||
<div> | ||
{hasQueryRunning && ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { useCallback, useRef } from 'react'; | ||
import { sendConfirm } from '../../lib/querybookUI'; | ||
import { DataDocRunAllButtonConfirm } from '../../components/DataDocRightSidebar/DataDocRunAllButtonConfirm'; | ||
import { trackClick } from '../../lib/analytics'; | ||
import { ComponentType, ElementType } from '../../const/analytics'; | ||
import toast from 'react-hot-toast'; | ||
import { DataDocResource } from '../../resource/dataDoc'; | ||
|
||
export function useRunAllFromIndex(docId: number, index?: number) { | ||
const header = | ||
index === undefined ? 'Run All Cells' : 'Run all cells below'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep the case consistent. |
||
|
||
const notification = useRef(true); | ||
|
||
const onRunAll = useCallback(() => { | ||
sendConfirm({ | ||
header, | ||
message: ( | ||
<DataDocRunAllButtonConfirm | ||
defaultNotification={notification.current} | ||
onNotificationChange={(value) => { | ||
notification.current = value; | ||
}} | ||
docId={docId} | ||
index={index} | ||
/> | ||
), | ||
onConfirm: () => { | ||
trackClick({ | ||
component: ComponentType.DATADOC_PAGE, | ||
element: ElementType.RUN_ALL_FROM_CELL_BUTTON, | ||
}); | ||
toast.promise( | ||
DataDocResource.run(docId, notification.current, index), | ||
{ | ||
loading: null, | ||
success: 'DataDoc execution started!', | ||
error: 'Failed to start the execution', | ||
} | ||
); | ||
}, | ||
confirmText: 'Run', | ||
}); | ||
return null; | ||
}, [docId, notification]); | ||
return onRunAll; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove console.log