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

feat(editor): Add template Id to workflow metadata #8088

Merged
merged 5 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 24 additions & 1 deletion cypress/e2e/29-templates.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,35 @@ describe('Templates', () => {
cy.url().then(($url) => {
expect($url).to.include('/workflow/new?templateId=1234');
});

workflowPage.getters.canvasNodes().should('have.length', 4);
workflowPage.getters.stickies().should('have.length', 1);
workflowPage.actions.shouldHaveWorkflowName(OnboardingWorkflow.name);
});

it('should save template id with the workflow', () => {
cy.visit(templatesPage.url);
templatesPage.getters.firstTemplateCard().click();
cy.url().should('include', '/templates/');

cy.url().then(($url) => {
const templateId = $url.split('/').pop();

templatesPage.getters.useTemplateButton().click();
cy.url().should('include', '/workflow/new');
workflowPage.actions.saveWorkflowOnButtonClick();

workflowPage.actions.selectAll();
workflowPage.actions.hitCopy();

cy.grantBrowserPermissions('clipboardReadWrite', 'clipboardSanitizedWrite');
// Check workflow JSON by copying it to clipboard
cy.readClipboard().then((workflowJSON) => {
expect(workflowJSON).to.contain(`"templateId": "${templateId}"`);
});
});
});

it('can open template with images and hides workflow screenshots', () => {
templateWorkflowPage.actions.openTemplate(WorkflowTemplate);

Expand Down
4 changes: 3 additions & 1 deletion cypress/pages/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export class TemplatesPage extends BasePage {
url = '/templates';

getters = {
useTemplateButton: () => cy.get('[data-testid="use-template-button"]'),
useTemplateButton: () => cy.getByTestId('use-template-button'),
templateCards: () => cy.getByTestId('template-card'),
firstTemplateCard: () => this.getters.templateCards().first(),
};

actions = {
Expand Down
7 changes: 4 additions & 3 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export interface IWorkflowData {
tags?: string[];
pinData?: IPinData;
versionId?: string;
meta?: WorkflowMetadata;
}

export interface IWorkflowDataUpdate {
Expand All @@ -243,9 +244,7 @@ export interface IWorkflowDataUpdate {
}

export interface IWorkflowToShare extends IWorkflowDataUpdate {
meta?: {
instanceId: string;
};
meta?: WorkflowMetadata;
}

export interface IWorkflowTemplateNode
Expand Down Expand Up @@ -273,6 +272,8 @@ export interface INewWorkflowData {

export interface WorkflowMetadata {
onboardingId?: string;
templateId?: string;
instanceId?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we adding instance id now to the metadata? we intentionally avoided adding that before when saving.. only to be added when sharing..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not adding instanceId on any new places in this PR, I moved it here so we can re-use this type in IWorkflowToShare and clean up the typing around that a bit more.

}

// Almost identical to cli.Interfaces.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ export default defineComponent({
const exportData: IWorkflowToShare = {
...data,
meta: {
...(this.workflowsStore.workflow.meta || {}),
instanceId: this.rootStore.instanceId,
},
tags: (tags || []).map((tagId) => {
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/mixins/workflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ export const workflowHelpers = defineComponent({
settings: this.workflowsStore.workflow.settings,
tags: this.workflowsStore.workflowTags,
versionId: this.workflowsStore.workflow.versionId,
meta: this.workflowsStore.workflow.meta,
};

const workflowId = this.workflowsStore.workflowId;
Expand Down
12 changes: 12 additions & 0 deletions packages/editor-ui/src/stores/workflows.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
IWorkflowsMap,
WorkflowsState,
NodeMetadataMap,
WorkflowMetadata,
} from '@/Interface';
import { defineStore } from 'pinia';
import type {
Expand Down Expand Up @@ -652,6 +653,17 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
};
},

setWorkflowMetadata(metadata: WorkflowMetadata | undefined): void {
this.workflow.meta = metadata;
},

addToWorkflowMetadata(data: Partial<WorkflowMetadata>): void {
this.workflow.meta = {
...this.workflow.meta,
...data,
};
},

setWorkflow(workflow: IWorkflowDb): void {
this.workflow = workflow;
this.workflow = {
Expand Down
3 changes: 3 additions & 0 deletions packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ export default defineComponent({

await this.addNodes(data.workflow.nodes, data.workflow.connections);
this.workflowData = (await this.workflowsStore.getNewWorkflowData(data.name)) || {};
this.workflowsStore.addToWorkflowMetadata({ templateId });
await this.$nextTick();
this.canvasStore.zoomToFit();
this.uiStore.stateIsDirty = true;
Expand All @@ -1089,6 +1090,7 @@ export default defineComponent({
this.workflowsStore.setWorkflowSettings(workflow.settings || {});
this.workflowsStore.setWorkflowPinData(workflow.pinData || {});
this.workflowsStore.setWorkflowVersionId(workflow.versionId);
this.workflowsStore.setWorkflowMetadata(workflow.meta);

if (workflow.ownedBy) {
this.workflowsEEStore.setWorkflowOwnedBy({
Expand Down Expand Up @@ -1585,6 +1587,7 @@ export default defineComponent({
void this.getNodesToSave(nodes).then((data) => {
const workflowToCopy: IWorkflowToShare = {
meta: {
...(this.workflowsStore.workflow.meta ?? {}),
instanceId: this.rootStore.instanceId,
},
...data,
Expand Down
Loading