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: Add share button to workflows list #4681

Merged
merged 2 commits into from
Nov 22, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default mixins(workflowHelpers, titleChange).extend({
if (saved) await this.settingsStore.fetchPromptsData();
},
onShareButtonClick() {
this.uiStore.openModal(WORKFLOW_SHARE_MODAL_KEY);
this.uiStore.openModalWithData({ name: WORKFLOW_SHARE_MODAL_KEY, data: { id: this.currentWorkflowId } });
},
onTagsEditEnable() {
this.$data.appliedTagIds = this.currentWorkflowTagIds;
Expand Down
8 changes: 7 additions & 1 deletion packages/editor-ui/src/components/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@
</ModalRoot>

<ModalRoot :name="WORKFLOW_SHARE_MODAL_KEY">
<WorkflowShareModal />
<template #default="{ modalName, active, data }">
<WorkflowShareModal
:data="data"
:isActive="active"
:modalName="modalName"
/>
</template>
</ModalRoot>

<ModalRoot :name="ONBOARDING_CALL_SIGNUP_MODAL_KEY">
Expand Down
9 changes: 8 additions & 1 deletion packages/editor-ui/src/components/WorkflowCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<script lang="ts">
import mixins from 'vue-typed-mixins';
import {IWorkflowDb, IUser, ITag} from "@/Interface";
import {DUPLICATE_MODAL_KEY, EnterpriseEditionFeature, VIEWS} from '@/constants';
import {DUPLICATE_MODAL_KEY, EnterpriseEditionFeature, VIEWS, WORKFLOW_SHARE_MODAL_KEY} from '@/constants';
import {showMessage} from "@/components/mixins/showMessage";
import {getWorkflowPermissions, IPermissions} from "@/permissions";
import dateformat from "dateformat";
Expand All @@ -74,6 +74,7 @@ import { useWorkflowsStore } from '@/stores/workflows';

export const WORKFLOW_LIST_ITEM_ACTIONS = {
OPEN: 'open',
SHARE: 'share',
DUPLICATE: 'duplicate',
DELETE: 'delete',
};
Expand Down Expand Up @@ -131,6 +132,10 @@ export default mixins(
label: this.$locale.baseText('workflows.item.open'),
value: WORKFLOW_LIST_ITEM_ACTIONS.OPEN,
},
{
label: this.$locale.baseText('workflows.item.share'),
value: WORKFLOW_LIST_ITEM_ACTIONS.SHARE,
},
{
label: this.$locale.baseText('workflows.item.duplicate'),
value: WORKFLOW_LIST_ITEM_ACTIONS.DUPLICATE,
Expand Down Expand Up @@ -183,6 +188,8 @@ export default mixins(
tags: (this.data.tags || []).map((tag: ITag) => tag.id),
},
});
} else if (action === WORKFLOW_LIST_ITEM_ACTIONS.SHARE) {
this.uiStore.openModalWithData({ name: WORKFLOW_SHARE_MODAL_KEY, data: { id: this.data.id } });
} else if (action === WORKFLOW_LIST_ITEM_ACTIONS.DELETE) {
const deleteConfirmed = await this.confirmMessage(
this.$locale.baseText(
Expand Down
17 changes: 14 additions & 3 deletions packages/editor-ui/src/components/WorkflowShareModal.ee.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,23 @@ export default mixins(
components: {
Modal,
},
props: {
data: {
type: Object,
default: () => ({}),
},
},
data() {
const workflowsStore = useWorkflowsStore();
const workflow = this.data.id === PLACEHOLDER_EMPTY_WORKFLOW_ID
? workflowsStore.workflow
: workflowsStore.workflowsById[this.data.id];

return {
WORKFLOW_SHARE_MODAL_KEY,
loading: false,
modalBus: new Vue(),
sharedWith: [...(workflowsStore.workflow.sharedWith || [])] as Array<Partial<IUser>>,
sharedWith: [...(workflow.sharedWith || [])] as Array<Partial<IUser>>,
EnterpriseEditionFeature,
};
},
Expand All @@ -150,7 +159,9 @@ export default mixins(
] as Array<Partial<IUser>>).concat(this.sharedWith || []);
},
workflow(): IWorkflowDb {
return this.workflowsStore.workflow;
return this.data.id === PLACEHOLDER_EMPTY_WORKFLOW_ID
? this.workflowsStore.workflow
: this.workflowsStore.workflowsById[this.data.id];
},
currentUser(): IUser | null {
return this.usersStore.currentUser;
Expand Down Expand Up @@ -221,7 +232,7 @@ export default mixins(
}

if (confirm) {
this.sharedWith = this.sharedWith.filter((sharee: IUser) => {
this.sharedWith = this.sharedWith.filter((sharee: Partial<IUser>) => {
return sharee.id !== user.id;
});
}
Expand Down
10 changes: 9 additions & 1 deletion packages/editor-ui/src/components/mixins/workflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PLACEHOLDER_EMPTY_WORKFLOW_ID,
START_NODE_TYPE,
WEBHOOK_NODE_TYPE,
VIEWS,
VIEWS, EnterpriseEditionFeature,
} from '@/constants';

import {
Expand Down Expand Up @@ -65,6 +65,8 @@ import { IWorkflowSettings } from 'n8n-workflow';
import { useNDVStore } from '@/stores/ndv';
import { useTemplatesStore } from '@/stores/templates';
import { useNodeTypesStore } from '@/stores/nodeTypes';
import useWorkflowsEEStore from "@/stores/workflows.ee";
import {useUsersStore} from "@/stores/users";

let cachedWorkflowKey: string | null = '';
let cachedWorkflow: Workflow | null = null;
Expand All @@ -83,6 +85,8 @@ export const workflowHelpers = mixins(
useRootStore,
useTemplatesStore,
useWorkflowsStore,
useWorkflowsEEStore,
useUsersStore,
useUIStore,
),
},
Expand Down Expand Up @@ -796,6 +800,10 @@ export const workflowHelpers = mixins(
this.workflowsStore.addWorkflow(workflowData);
this.workflowsStore.setWorkflowHash(workflowData.hash);

if (this.settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.WorkflowSharing) && this.usersStore.currentUser) {
this.workflowsEEStore.setWorkflowOwnedBy({ workflowId: workflowData.id, ownedBy: this.usersStore.currentUser });
}

if (openInNewWindow) {
const routeData = this.$router.resolve({name: VIEWS.WORKFLOW, params: {name: workflowData.id}});
window.open(routeData.href, '_blank');
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@
"workflows.menu.my": "My workflows",
"workflows.menu.all": "All workflows",
"workflows.item.open": "Open",
"workflows.item.share": "Share...",
"workflows.item.duplicate": "Duplicate",
"workflows.item.delete": "Delete",
"workflows.item.updated": "Last updated",
Expand Down