Skip to content

Commit

Permalink
[editor] Add variable substitution to presentation mode in editor v2
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanAhlen committed Feb 9, 2021
1 parent 3ee5324 commit e66183c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
Expand Up @@ -25,6 +25,11 @@
<i class="fa fa-times fa-fw" />
</hue-button>
</div>
<VariableSubstitution
:locations="locations"
:initial-variables="executor.variables"
@variables-changed="onVariablesChanged"
/>
<div class="presentation-mode-body">
<div
v-for="{ header, statement, executable } of presentationStatements"
Expand All @@ -45,6 +50,9 @@
</template>

<script lang="ts">
import { Variable } from 'apps/editor/components/variableSubstitution/types';
import VariableSubstitution from 'apps/editor/components/variableSubstitution/VariableSubstitution.vue';
import { IdentifierLocation } from 'parse/types';
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop } from 'vue-property-decorator';
Expand All @@ -67,7 +75,7 @@
const headerRegEx = /--(.*)$/m;
@Component({
components: { HueButton, ResultTable, ExecutableActions, SqlText },
components: { VariableSubstitution, HueButton, ResultTable, ExecutableActions, SqlText },
methods: { I18n }
})
export default class PresentationMode extends Vue {
Expand All @@ -77,6 +85,8 @@
title?: string;
@Prop({ required: false })
description?: string;
@Prop()
locations!: IdentifierLocation[];
get presentationStatements(): PresentationStatement[] {
return (this.executor.executables as SqlExecutable[]).map(executable => {
Expand Down Expand Up @@ -104,5 +114,9 @@
this.$emit('before-execute', executable);
this.executor.activeExecutable = executable;
}
onVariablesChanged(variables: Variable[]): void {
this.$emit('variables-changed', variables);
}
}
</script>
Expand Up @@ -24,10 +24,14 @@
:description="description"
@before-execute="onBeforeExecute"
@close="onClose"
@variables-changed="onVariablesChanged"
/>
</template>

<script lang="ts">
import { Variable } from 'apps/editor/components/variableSubstitution/types';
import { IdentifierLocation } from 'parse/types';
import { POST_FROM_LOCATION_WORKER_EVENT } from 'sql/sqlWorkerHandler';
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop } from 'vue-property-decorator';
Expand All @@ -45,9 +49,13 @@
@Prop()
executor: Executor | null = null;
@Prop()
titleObservable: KnockoutObservable<string | undefined>;
titleObservable!: KnockoutObservable<string | undefined>;
@Prop()
descriptionObservable: KnockoutObservable<string | undefined>;
descriptionObservable!: KnockoutObservable<string | undefined>;
@Prop()
initialVariables?: Variable[];
locations: IdentifierLocation[] = [];
title: string | null = null;
description: string | null = null;
Expand All @@ -58,15 +66,25 @@
updated(): void {
if (!this.initialized) {
this.title = this.titleObservable();
this.title = this.titleObservable() || null;
this.subTracker.subscribe(this.titleObservable, (title?: string) => {
this.title = title;
this.title = title || null;
});
this.description = this.descriptionObservable();
this.description = this.descriptionObservable() || null;
this.subTracker.subscribe(this.descriptionObservable, (description?: string) => {
this.description = description;
this.description = description || null;
});
this.subTracker.subscribe(
POST_FROM_LOCATION_WORKER_EVENT,
(e: { data?: { locations?: IdentifierLocation[] } }) => {
if (e.data && e.data.locations) {
this.locations = e.data.locations;
}
}
);
this.initialized = true;
}
}
Expand All @@ -86,6 +104,12 @@
new CustomEvent<void>('close', { bubbles: true })
);
}
onVariablesChanged(variables: Variable[]): void {
this.$el.dispatchEvent(
new CustomEvent<Variable[]>('variables-changed', { bubbles: true, detail: variables })
);
}
}
export const COMPONENT_NAME = 'presentation-mode-ko-bridge';
Expand Down
3 changes: 3 additions & 0 deletions desktop/libs/notebook/src/notebook/templates/editor2.mako
Expand Up @@ -868,6 +868,9 @@
},
'close': function () {
parentNotebook.isPresentationMode(false);
},
'variables-changed': function (event) {
setVariables(event.detail);
}
},
vueKoProps: {
Expand Down

0 comments on commit e66183c

Please sign in to comment.