Skip to content
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

4754 notebook re run notifications #5162

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
context="dataset"
@submitQuery="onSubmitQuery"
@add-code-cell="onAddCodeCell"
@run-all-cells="onRunAllCells"
@keydown.stop
/>
<span class="flex-auto"></span>
Expand Down Expand Up @@ -126,7 +127,7 @@ import TeraInputText from '@/components/widgets/tera-input-text.vue';
import { useToastService } from '@/services/toast';
import { IModel } from '@jupyterlab/services/lib/session/session';
import type { CsvAsset, NotebookSession } from '@/types/Types';
import { AssetType } from '@/types/Types';
import { AssetType, EventType } from '@/types/Types';
import TeraJupyterChat from '@/components/llm/tera-jupyter-chat.vue';
import { IKernelConnection } from '@jupyterlab/services/lib/kernel/kernel';
import {
Expand Down Expand Up @@ -476,6 +477,11 @@ const onAddCodeCell = () => {
}
};

const onRunAllCells = () => {
const event = new Event(EventType.RunAllCells);
window.dispatchEvent(event);
};

/* Download dataset feature has been removed, but keeping this code here in case it returns */
// const downloadDataset = () => {
// const session = jupyterSession.session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { computed, onMounted, onBeforeUnmount, ref } from 'vue';
import { VAceEditor } from 'vue3-ace-editor';
import { VAceEditorInstance } from 'vue3-ace-editor/types';
import { SessionContext } from '@jupyterlab/apputils';
import { INotebookItem, JupyterMessage, renderMime } from '@/services/jupyter';
import Button from 'primevue/button';
import { CodeCell, CodeCellModel } from '@jupyterlab/cells';
import { useConfirm } from 'primevue/useconfirm';
import { EventType } from '@/types/Types';

const props = defineProps<{
jupyterMessage: JupyterMessage;
jupyterSession: SessionContext;
notebookItem: INotebookItem;
lang: string;
index: Number;
}>();

const emit = defineEmits(['deleteRequested']);
Expand Down Expand Up @@ -96,6 +98,15 @@ onMounted(() => {
if (props.notebookItem.autoRun) {
runCell();
}
window.addEventListener(EventType.RunAllCells, () => {
setTimeout(() => {
runCell();
}, 1000 * props.index.valueOf()); // ensures the cells are run in the correct order
});
});

onBeforeUnmount(() => {
window.removeEventListener(EventType.RunAllCells, runCell); // Clean up listener
});

defineExpose({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,27 @@
size="small"
outlined
:disabled="props.kernelIsBusy"
class="white-space-nowrap"
style="margin-top: 1px; height: 31px; width: 10rem"
class="white-space-nowrap action-button"
title="Add a code cell to the notebook"
@click="addCodeCell"
>
<span class="pi pi-plus p-button-icon p-button-icon-left"></span>
<span class="p-button-text">Add a cell</span>
</Button>
<Button
ref="rerunCellsButton"
severity="secondary"
size="small"
outlined
:disabled="props.kernelIsBusy"
class="white-space-nowrap action-button"
style="width: 13rem"
title="Rerun all cells"
@click="runAllCells"
>
<span class="pi pi-refresh p-button-icon p-button-icon-left"></span>
<span class="p-button-text">Rerun all cells</span>
</Button>
<ProgressBar v-if="props.kernelIsBusy" mode="indeterminate" class="busy-bar"></ProgressBar>
</div>
</div>
Expand All @@ -51,7 +64,7 @@ import * as EventService from '@/services/event';
import { EventType } from '@/types/Types';
import { useProjects } from '@/composables/project';

const emit = defineEmits(['submit-query', 'add-code-cell']);
const emit = defineEmits(['submit-query', 'add-code-cell', 'run-all-cells']);

const props = defineProps({
placeholderMessage: {
Expand Down Expand Up @@ -92,7 +105,11 @@ const submitQuery = () => {

const addCodeCell = () => {
emit('add-code-cell');
EventService.create(EventType.AddCodeCell, useProjects().activeProject.value?.id);
EventService.create(EventType.AddCodeCell);
};

const runAllCells = () => {
emit('run-all-cells');
};

onMounted(() => {
Expand Down Expand Up @@ -181,4 +198,10 @@ const autoGrow = () => {
position: relative;
top: -4px;
}
.action-button {
margin-left: var(--gap-2);
margin-top: 1px;
height: 31px;
width: 10rem;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
tabindex="0"
class="message-container"
>
<div v-if="showRerunMessage" class="rerun-message">
Re-run all the cells to restore the context if you need to make any changes or use them downstream.
<Button class="close-mask" icon="pi pi-times" text rounded aria-label="Close" @click="hideRerunMessage" />
</div>
mloppie marked this conversation as resolved.
Show resolved Hide resolved
<tera-jupyter-response
@keydown.stop
v-for="(msg, index) in filteredNotebookItems"
Expand Down Expand Up @@ -61,6 +65,7 @@ const selectedCellId = ref();
const filteredNotebookItems = computed<INotebookItem[]>(() =>
notebookItems.value.filter((item) => !isEmpty(item.messages))
);
const showRerunMessage = ref(true);

const emit = defineEmits([
'new-message',
Expand Down Expand Up @@ -109,6 +114,7 @@ const onKeyPress = (event) => {
case 'a':
addCodeCell(false, false);
nextTick(() => {
// notebookCells.vla
scrollToCell(notebookCells.value.find((item) => item.$props.msg.query_id === selectedCellId.value));
});
break;
Expand Down Expand Up @@ -236,6 +242,7 @@ const reRunPrompt = (queryId: string, query?: string) => {
isExecutingCode.value = true;
};

// here
const addCodeCell = (isDefaultCell: boolean = false, isNextCell: boolean = true) => {
const msgId = createMessageId('code_cell');
const date = new Date().toISOString();
Expand Down Expand Up @@ -403,6 +410,10 @@ const clearOutputs = () => {
}
};

const hideRerunMessage = () => {
showRerunMessage.value = false;
};

onUnmounted(() => {
messagesHistory.value = [];
});
Expand Down Expand Up @@ -452,8 +463,9 @@ watch(
defineExpose({
clearHistory,
clearOutputs,
submitQuery,
addCodeCell
submitQuery

// here
});
</script>

Expand Down Expand Up @@ -489,4 +501,11 @@ section {
height: calc(100% - 3.5rem);
overflow-y: auto;
}
.rerun-message {
display: flex;
background-color: var(--surface-warning);
justify-content: space-between;
align-items: center;
padding: 0.5rem;
mloppie marked this conversation as resolved.
Show resolved Hide resolved
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
:notebook-item="msg"
:jupyter-message="m"
:lang="language"
:index="index"
@deleteRequested="onDeleteRequested(m.header.msg_id)"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="5"
:disabled="!kernelState"
/>
<Button label="Save for reuse" severity="secondary" outlined :disabled="!kernelState" @click="onSave" />
<Button label="Save for reuse" severity="secondary" outlined :disabled="disableSaveForReuse" @click="onSave" />
</div>
</template>
<div class="background">
Expand All @@ -40,7 +40,7 @@
<script setup lang="ts">
// Proxy to use tera-dataset via a workflow context

import { WorkflowNode, WorkflowPortStatus } from '@/types/workflow';
import { OperatorStatus, WorkflowNode, WorkflowPortStatus } from '@/types/workflow';
import TeraDatasetJupyterPanel from '@/components/dataset/tera-dataset-jupyter-panel.vue';
import { computed, onMounted, ref } from 'vue';
import { createNotebookSession, getNotebookSessionById } from '@/services/notebook-session';
Expand Down Expand Up @@ -71,6 +71,9 @@ const assets = computed(() =>
name: useProjects().getAssetName(inputNode.value![0])
}))
);
const disableSaveForReuse = computed(
() => !kernelState.value || props.node.status === OperatorStatus.INVALID || props.node.status === OperatorStatus.ERROR
);

const kernelState = ref(null);
const jupyterPanel = ref();
Expand Down