Skip to content

Commit

Permalink
feat(editor): Load workflow sharedWith info only when opening share m…
Browse files Browse the repository at this point in the history
…odal (#5125)

* feat(editor): load workflow sharedWith info only when opening share modal

* fix(editor): update workflow share modal loading state at the end of initialize fn
  • Loading branch information
alexgrozav authored Jan 11, 2023
1 parent 044b153 commit bfc6ddd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/editor-ui/src/api/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export async function getNewWorkflow(context: IRestApiContext, name?: string) {
};
}

export async function getWorkflow(context: IRestApiContext, id: string, filter?: object) {
const sendData = filter ? { filter } : undefined;

return await makeRestApiRequest(context, 'GET', `/workflows/${id}`, sendData);
}

export async function getWorkflows(context: IRestApiContext, filter?: object) {
const sendData = filter ? { filter } : undefined;

Expand Down
37 changes: 29 additions & 8 deletions packages/editor-ui/src/components/WorkflowShareModal.ee.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ import { useWorkflowsStore } from '@/stores/workflows';
import { useWorkflowsEEStore } from '@/stores/workflows.ee';
import { ITelemetryTrackProperties } from 'n8n-workflow';
import { useUsageStore } from '@/stores/usage';
import { BaseTextKey } from '@/plugins/i18n';
export default mixins(showMessage).extend({
name: 'workflow-share-modal',
Expand All @@ -175,7 +176,7 @@ export default mixins(showMessage).extend({
return {
WORKFLOW_SHARE_MODAL_KEY,
loading: false,
loading: true,
modalBus: new Vue(),
sharedWith: [...(workflow.sharedWith || [])] as Array<Partial<IUser>>,
EnterpriseEditionFeature,
Expand All @@ -199,8 +200,9 @@ export default mixins(showMessage).extend({
modalTitle(): string {
return this.$locale.baseText(
this.isSharingEnabled
? this.uiStore.contextBasedTranslationKeys.workflows.sharing.title
: this.uiStore.contextBasedTranslationKeys.workflows.sharing.unavailable.title,
? (this.uiStore.contextBasedTranslationKeys.workflows.sharing.title as BaseTextKey)
: (this.uiStore.contextBasedTranslationKeys.workflows.sharing.unavailable
.title as BaseTextKey),
{
interpolate: { name: this.workflow.name },
},
Expand Down Expand Up @@ -380,7 +382,7 @@ export default mixins(showMessage).extend({
},
),
this.$locale.baseText('workflows.shareModal.list.delete.confirm.title', {
interpolate: { name: user.fullName },
interpolate: { name: user.fullName as string },
}),
null,
this.$locale.baseText('workflows.shareModal.list.delete.confirm.confirmButtonText'),
Expand Down Expand Up @@ -437,18 +439,37 @@ export default mixins(showMessage).extend({
});
},
goToUpgrade() {
let linkUrl = this.$locale.baseText(this.uiStore.contextBasedTranslationKeys.upgradeLinkUrl);
let linkUrl = this.$locale.baseText(
this.uiStore.contextBasedTranslationKeys.upgradeLinkUrl as BaseTextKey,
);
if (linkUrl.includes('subscription')) {
linkUrl = `${this.usageStore.viewPlansUrl}&source=workflow_sharing`;
}
window.open(linkUrl, '_blank');
},
async initialize() {
if (this.isSharingEnabled) {
await this.loadUsers();
if (
this.workflow.id !== PLACEHOLDER_EMPTY_WORKFLOW_ID &&
!this.workflow.sharedWith?.length // Sharing info already loaded
) {
await this.workflowsStore.fetchWorkflow(this.workflow.id);
}
}
this.loading = false;
},
},
mounted() {
if (this.isSharingEnabled) {
this.loadUsers();
}
this.initialize();
},
watch: {
workflow(workflow) {
this.sharedWith = workflow.sharedWith;
},
},
});
</script>
Expand Down
8 changes: 8 additions & 0 deletions packages/editor-ui/src/stores/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
getExecutionData,
getFinishedExecutions,
getNewWorkflow,
getWorkflow,
getWorkflows,
} from '@/api/workflows';
import { useUIStore } from './ui';
Expand Down Expand Up @@ -254,6 +255,13 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
return workflows;
},

async fetchWorkflow(id: string): Promise<IWorkflowDb> {
const rootStore = useRootStore();
const workflow = await getWorkflow(rootStore.getRestApiContext, id);
this.addWorkflow(workflow);
return workflow;
},

async getNewWorkflowData(name?: string): Promise<INewWorkflowData> {
const workflowsEEStore = useWorkflowsEEStore();

Expand Down

0 comments on commit bfc6ddd

Please sign in to comment.