Skip to content

Commit

Permalink
Add timestamp for code block start
Browse files Browse the repository at this point in the history
  • Loading branch information
DanFitzgibbon authored and lucasfcosta committed Nov 1, 2024
1 parent fe8ee7f commit 4ec0491
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
2 changes: 2 additions & 0 deletions apps/api/src/yjs/v2/executors/blocks/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export class PythonExecutor implements IPythonExecutor {

await this.executionQueue.add(
async ({ signal }) => {
block.setAttribute('startQueryTime', new Date().toISOString())

logger().trace(
{
workspaceId: this.workspaceId,
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/yjs/v2/executors/blocks/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export class SQLExecutor implements ISQLExecutor {

await this.executionQueue.add(
async ({ signal }) => {
block.setAttribute('startQueryTime', new Date().toISOString())

logger().trace(
{
workspaceId: this.workspaceId,
Expand Down
22 changes: 18 additions & 4 deletions apps/web/src/components/ExecutionStatusText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
Cog8ToothIcon,
} from '@heroicons/react/20/solid'

type StartExecutionStatusTextProps = {
startExecutionTime: string
}

type LastExecutedStatusTextProps = {
lastExecutionTime: string
}
Expand All @@ -23,11 +27,16 @@ export const QuerySucceededText = ({
)
}

export const LoadingQueryText = () => {
export const LoadingQueryText = ({
startExecutionTime,
}: StartExecutionStatusTextProps) => {
return (
<span className="font-syne text-gray-400 text-xs flex items-center select-none">
<CloudArrowDownIcon className="w-4 h-4 mr-1" />
<span className="pt-0.5">Executing query...</span>
<span className="pt-0.5">
Executing query, started at{' '}
{format(new Date(startExecutionTime), "h:mm a 'on' do MMM, yyyy")}
</span>
</span>
)
}
Expand All @@ -41,11 +50,16 @@ export const LoadingEnvText = () => {
)
}

export const ExecutingPythonText = () => {
export const ExecutingPythonText = ({
startExecutionTime,
}: StartExecutionStatusTextProps) => {
return (
<span className="font-syne text-gray-400 text-xs flex items-center select-none">
<CloudArrowDownIcon className="w-4 h-4 mr-1" />
<span className="pt-0.5">Executing Python code...</span>
<span className="pt-0.5">
Executing Python code, started at{' '}
{format(new Date(startExecutionTime), "h:mm a 'on' do MMM, yyyy")}
</span>
</span>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ function PythonBlock(props: Props) {

const { source } = getPythonAttributes(props.block)
const lastQuery = props.block.getAttribute('lastQuery')
const startQueryTime = props.block.getAttribute('startQueryTime')
const lastQueryTime = props.block.getAttribute('lastQueryTime')
const queryStatusText = useMemo(() => {
if (status === 'running' || status === 'running-suggestion') {
if (envStatus === 'Starting') {
return <LoadingEnvText />
} else {
return <ExecutingPythonText />
return <ExecutingPythonText startExecutionTime={startQueryTime} />
}
}

Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/v2Editor/customBlocks/sql/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function SQLBlock(props: Props) {

const { source, configuration } = getSQLAttributes(props.block, props.blocks)
const lastQuery = props.block.getAttribute('lastQuery')
const startQueryTime = props.block.getAttribute('startQueryTime')
const lastQueryTime = props.block.getAttribute('lastQueryTime')
const queryStatusText = useMemo(() => {
switch (execStatus) {
Expand All @@ -229,7 +230,7 @@ function SQLBlock(props: Props) {
if (envStatus === 'Starting') {
return <LoadingEnvText />
} else {
return <LoadingQueryText />
return <LoadingQueryText startExecutionTime={startQueryTime} />
}
}
}, [execStatus, lastQuery, lastQueryTime, source, envStatus])
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/blocks/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type PythonBlock = BaseBlock<BlockType.Python> & {
isCodeHidden: boolean
lastQuery: string
lastQueryTime: string
startQueryTime: string
editWithAIPrompt: Y.Text
isEditWithAIPromptOpen: boolean
aiSuggestions: Y.Text | null
Expand Down Expand Up @@ -61,6 +62,7 @@ export const makePythonBlock = (
isCodeHidden: false,
lastQuery: '',
lastQueryTime: '',
startQueryTime: '',
editWithAIPrompt: new Y.Text(''),
isEditWithAIPromptOpen: false,
aiSuggestions: null,
Expand All @@ -87,6 +89,7 @@ export function getPythonAttributes(
isCodeHidden: getAttributeOr(block, 'isCodeHidden', false),
lastQuery: getAttributeOr(block, 'lastQuery', ''),
lastQueryTime: getAttributeOr(block, 'lastQueryTime', ''),
startQueryTime: getAttributeOr(block, 'startQueryTime', ''),
editWithAIPrompt: getPythonBlockEditWithAIPrompt(block),
isEditWithAIPromptOpen: isPythonBlockEditWithAIPromptOpen(block),
aiSuggestions: getPythonAISuggestions(block),
Expand All @@ -110,6 +113,7 @@ export function duplicatePythonBlock(
isCodeHidden: options?.noState ? false : prevAttributes.isCodeHidden,
lastQuery: options?.noState ? '' : prevAttributes.lastQuery,
lastQueryTime: options?.noState ? '' : prevAttributes.lastQueryTime,
startQueryTime: options?.noState ? '' : prevAttributes.startQueryTime,
editWithAIPrompt: options?.noState
? new Y.Text()
: duplicateYText(prevAttributes.editWithAIPrompt),
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/blocks/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type SQLBlock = BaseBlock<BlockType.SQL> & {
result: RunQueryResult | null
lastQuery: string | null
lastQueryTime: string | null
startQueryTime: string | null
isCodeHidden: boolean
isResultHidden: boolean
editWithAIPrompt: Y.Text
Expand Down Expand Up @@ -80,6 +81,7 @@ export const makeSQLBlock = (
result: null,
lastQuery: null,
lastQueryTime: null,
startQueryTime: null,
isCodeHidden: false,
isResultHidden: false,
editWithAIPrompt: new Y.Text(''),
Expand Down Expand Up @@ -115,6 +117,7 @@ export function getSQLAttributes(
result: getAttributeOr(block, 'result', null),
lastQuery: getAttributeOr(block, 'lastQuery', null),
lastQueryTime: getAttributeOr(block, 'lastQueryTime', null),
startQueryTime: getAttributeOr(block, 'startQueryTime', null),
isCodeHidden: getAttributeOr(block, 'isCodeHidden', false),
isResultHidden: getAttributeOr(block, 'isResultHidden', false),
editWithAIPrompt: getSQLBlockEditWithAIPrompt(block),
Expand Down Expand Up @@ -154,6 +157,7 @@ export function duplicateSQLBlock(
result: options?.noState ? null : clone(prevAttributes.result),
lastQuery: options?.noState ? null : prevAttributes.lastQuery,
lastQueryTime: options?.noState ? null : prevAttributes.lastQueryTime,
startQueryTime: options?.noState ? null : prevAttributes.startQueryTime,
isCodeHidden: options?.noState ? false : prevAttributes.isCodeHidden,
isResultHidden: options?.noState ? false : prevAttributes.isResultHidden,
editWithAIPrompt: options?.noState
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type SQLComponentAttrs = Omit<
| 'result'
| 'lastQuery'
| 'lastQueryTime'
| 'startQueryTime'
| 'isCodeHidden'
| 'isResultHidden'
| 'editWithAIPrompt'
Expand All @@ -80,6 +81,7 @@ type PythonComponentAttrs = Omit<
| 'isCodeHidden'
| 'lastQuery'
| 'lastQueryTime'
| 'startQueryTime'
| 'editWithAIPrompt'
| 'isEditWithAIPromptOpen'
| 'aiSuggestions'
Expand Down

0 comments on commit 4ec0491

Please sign in to comment.