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

start consolidating events #2292

Merged
merged 9 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/client/hmi-client/src/utils/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,4 @@ export class EventEmitter {
});
return true;
}

emitNodeStateChange(payload: { workflowId: string; nodeId: string; state: any }) {
this.emit('node-state-change', payload);
}

emitNodeRefresh(payload: { workflowId: string; nodeId: string }) {
this.emit('node-refresh', payload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ import InputNumber from 'primevue/inputnumber';
import { setupModelInput, setupDatasetInput } from '@/services/calibrate-workflow';
import { ChartConfig, RunResults } from '@/types/SimulateConfig';
import { WorkflowNode } from '@/types/workflow';
import { workflowEventBus } from '@/services/workflow';
import TeraSimulateChart from '@/workflow/tera-simulate-chart.vue';
import SelectButton from 'primevue/selectbutton';
import { CalibrationOperationStateCiemss, CalibrateMap } from './calibrate-operation';

const props = defineProps<{
node: WorkflowNode<CalibrationOperationStateCiemss>;
}>();
const emit = defineEmits(['append-output-port', 'update-state']);

enum CalibrationView {
Input = 'Input',
Expand Down Expand Up @@ -183,22 +183,14 @@ const chartConfigurationChange = (index: number, config: ChartConfig) => {
const state = _.cloneDeep(props.node.state);
state.chartConfigs[index] = config;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

const addChart = () => {
const state = _.cloneDeep(props.node.state);
state.chartConfigs.push(_.last(state.chartConfigs) as ChartConfig);

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

// Used from button to add new entry to the mapping object
Expand All @@ -212,11 +204,7 @@ function addMapping() {
const state = _.cloneDeep(props.node.state);
state.mapping = mapping.value;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
}
// Set up model config + dropdown names
// Note: Same as calibrate-node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ import {
} from '@/services/models/simulation-service';
import { setupModelInput, setupDatasetInput } from '@/services/calibrate-workflow';
import { ChartConfig, RunResults } from '@/types/SimulateConfig';
import { workflowEventBus } from '@/services/workflow';
import _ from 'lodash';
import { Poller, PollerState } from '@/api/api';
import TeraSimulateChart from '@/workflow/tera-simulate-chart.vue';
Expand Down Expand Up @@ -317,22 +316,14 @@ const chartConfigurationChange = (index: number, config: ChartConfig) => {
const state = _.cloneDeep(props.node.state);
state.chartConfigs[index] = config;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

const addChart = () => {
const state = _.cloneDeep(props.node.state);
state.chartConfigs.push(_.last(state.chartConfigs) as ChartConfig);

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

// Set up model config + dropdown names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ import { ref, shallowRef, computed, watch } from 'vue';
import { getRunResultCiemss } from '@/services/models/simulation-service';
import { getModelConfigurationById } from '@/services/model-configurations';
import { WorkflowNode } from '@/types/workflow';
import { workflowEventBus } from '@/services/workflow';
import Button from 'primevue/button';
import AccordionTab from 'primevue/accordiontab';
import Accordion from 'primevue/accordion';
Expand All @@ -228,6 +227,7 @@ const dataLabelPlugin = [ChartDataLabels];
const props = defineProps<{
node: WorkflowNode<CalibrateEnsembleCiemssOperationState>;
}>();
const emit = defineEmits(['append-output-port', 'update-state']);

enum CalibrateView {
Input = 'Input',
Expand Down Expand Up @@ -283,11 +283,7 @@ const chartConfigurationChange = (index: number, config: ChartConfig) => {
const state = _.cloneDeep(props.node.state);
state.chartConfigs[index] = config;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

const calculateWeights = () => {
Expand Down Expand Up @@ -315,11 +311,7 @@ function addMapping() {
const state = _.cloneDeep(props.node.state);
state.mapping = ensembleConfigs.value;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
}

const setBarChartData = () => {
Expand Down Expand Up @@ -384,11 +376,7 @@ const addChart = () => {
const state = _.cloneDeep(props.node.state);
state.chartConfigs.push({ selectedVariable: [], selectedRun: '' } as ChartConfig);

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

// assume only one run for now
Expand Down Expand Up @@ -458,11 +446,7 @@ watch(
const state = _.cloneDeep(props.node.state);
state.mapping = ensembleConfigs.value;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
},
{ immediate: true }
);
Expand All @@ -473,11 +457,7 @@ watch(
const state = _.cloneDeep(props.node.state);
state.extra = extra.value;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
},
{ immediate: true }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import { ref, shallowRef, watch, computed, ComputedRef, onMounted, onUnmounted }
// import { getRunResult } from '@/services/models/simulation-service';
import { ProgressState, WorkflowNode, OperatorStatus } from '@/types/workflow';
// import { getModelConfigurationById } from '@/services/model-configurations';
import { workflowEventBus } from '@/services/workflow';
import { CsvAsset, EnsembleCalibrationCiemssRequest, EnsembleModelConfigs } from '@/types/Types';
import {
makeEnsembleCiemssCalibration,
Expand Down Expand Up @@ -171,23 +170,15 @@ const chartConfigurationChange = (index: number, config: ChartConfig) => {
const state = _.cloneDeep(props.node.state);
state.chartConfigs[index] = config;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

// TODO: This is repeated every single node that uses a chart. Hope to refactor if the state manip allows for it easily
const addChart = () => {
const state = _.cloneDeep(props.node.state);
state.chartConfigs.push({ selectedRun: '', selectedVariable: [] } as ChartConfig);

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

// Set up csv + dropdown names
Expand Down Expand Up @@ -220,11 +211,7 @@ watch(
const state = _.cloneDeep(props.node.state);
state.modelConfigIds = modelConfigIds.value;
state.mapping = mapping;
workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
}
},
{ immediate: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ import InputNumber from 'primevue/inputnumber';
import { setupModelInput, setupDatasetInput, renderLossGraph } from '@/services/calibrate-workflow';
import { ChartConfig, RunResults, RunType } from '@/types/SimulateConfig';
import { WorkflowNode } from '@/types/workflow';
import { workflowEventBus } from '@/services/workflow';
import TeraSimulateChart from '@/workflow/tera-simulate-chart.vue';
import SelectButton from 'primevue/selectbutton';
import { getRunResultJulia } from '@/services/models/simulation-service';
Expand All @@ -157,6 +156,7 @@ import { CalibrationOperationStateJulia, CalibrateMap } from './calibrate-operat
const props = defineProps<{
node: WorkflowNode<CalibrationOperationStateJulia>;
}>();
const emit = defineEmits(['append-output-port', 'update-state']);

enum CalibrationView {
Input = 'Input',
Expand Down Expand Up @@ -206,11 +206,7 @@ const chartConfigurationChange = (index: number, config: ChartConfig) => {
const state = _.cloneDeep(props.node.state);
state.calibrateConfigs.chartConfigs[index] = config.selectedVariable;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

onMounted(() => {
Expand All @@ -228,11 +224,7 @@ const addChart = () => {
const state = _.cloneDeep(props.node.state);
state.calibrateConfigs.chartConfigs.push([]);

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

// Used from button to add new entry to the mapping object
Expand All @@ -246,11 +238,7 @@ function addMapping() {
const state = _.cloneDeep(props.node.state);
state.mapping = mapping.value;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
}
// Set up model config + dropdown names
// Note: Same as calibrate-node
Expand Down Expand Up @@ -288,11 +276,7 @@ const handleSelectedRunChange = () => {
state.calibrateConfigs.runConfigs[runId].active = runId === selectedRun.value.runId;
});

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};
watch(() => selectedRun.value, handleSelectedRunChange, { immediate: true });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ import {
import { setupModelInput, setupDatasetInput, renderLossGraph } from '@/services/calibrate-workflow';
import { ChartConfig, RunResults, RunType } from '@/types/SimulateConfig';
import { csvParse } from 'd3';
import { workflowEventBus } from '@/services/workflow';
import _ from 'lodash';
import InputNumber from 'primevue/inputnumber';
import InputText from 'primevue/inputtext';
Expand Down Expand Up @@ -440,11 +439,7 @@ const watchCompletedRunList = async (runIdList: string[]) => {
active: true,
loss: lossValues
};
workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);

// clear out intermediate values for next run
lossValues = [];
Expand All @@ -465,22 +460,14 @@ const chartConfigurationChange = (index: number, config: ChartConfig) => {
const state = _.cloneDeep(props.node.state);
state.calibrateConfigs.chartConfigs[index] = config.selectedVariable;

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

const addChart = () => {
const state = _.cloneDeep(props.node.state);
state.calibrateConfigs.chartConfigs.push([]);

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};

// Set up model config + dropdown names
Expand Down Expand Up @@ -522,11 +509,7 @@ const handleSelectedRunChange = () => {
state.calibrateConfigs.runConfigs[runId].active = runId === selectedRun.value.runId;
});

workflowEventBus.emitNodeStateChange({
workflowId: props.node.workflowId,
nodeId: props.node.id,
state
});
emit('update-state', state);
};
watch(() => selectedRun.value, handleSelectedRunChange, { immediate: true });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { WorkflowNode, WorkflowPortStatus } from '@/types/workflow';
import TeraDatasetJupyterPanel from '@/components/dataset/tera-dataset-jupyter-panel.vue';
import { computed, onMounted, ref } from 'vue';
import { workflowEventBus } from '@/services/workflow';
import { createNotebookSession, getNotebookSessionById } from '@/services/notebook-session';
import { NotebookSession } from '@/types/Types';
import { cloneDeep } from 'lodash';
Expand All @@ -28,6 +27,8 @@ import { DatasetTransformerState } from './dataset-transformer-operation';
const props = defineProps<{
node: WorkflowNode<DatasetTransformerState>;
}>();
const emit = defineEmits(['append-output-port', 'update-state']);

const showKernels = ref(<boolean>false);
const showChatThoughts = ref(<boolean>false);
const assetIds = computed(() =>
Expand Down Expand Up @@ -55,20 +56,19 @@ onMounted(async () => {
if (notebookSessionId) {
// update the node state with the notebook session id
state.notebookSessionId = notebookSessionId;
workflowEventBus.emit('update-state', {
node: props.node,
state
});
emit('update-state', state);
}
}

notebookSession.value = await getNotebookSessionById(notebookSessionId!);
});

const addOutputPort = (data) => {
workflowEventBus.emit('append-output-port', {
node: props.node,
port: { id: data.id, label: data.name, type: 'datasetId', value: data.id }
const addOutputPort = (data: any) => {
emit('append-output-port', {
id: data.id,
label: data.name,
type: 'datasetId',
value: data.id
});
};
</script>
Expand Down
Loading