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

refactor(editor): Turn showMessage mixin to composable (#6081) #6244

Merged
merged 10 commits into from
May 15, 2023
42 changes: 23 additions & 19 deletions packages/editor-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,43 @@
</template>

<script lang="ts">
import Modals from './components/Modals.vue';
import LoadingView from './views/LoadingView.vue';
import Telemetry from './components/Telemetry.vue';
import { HIRING_BANNER, LOCAL_STORAGE_THEME, VIEWS } from './constants';
import Modals from '@/components/Modals.vue';
import LoadingView from '@/views/LoadingView.vue';
import Telemetry from '@/components/Telemetry.vue';
import { HIRING_BANNER, LOCAL_STORAGE_THEME, VIEWS } from '@/constants';
import mixins from 'vue-typed-mixins';
import { showMessage } from '@/mixins/showMessage';
import { userHelpers } from '@/mixins/userHelpers';
import { loadLanguage } from './plugins/i18n';
import useGlobalLinkActions from '@/composables/useGlobalLinkActions';
import { loadLanguage } from '@/plugins/i18n';
import { useGlobalLinkActions, useToast } from '@/composables';
import { mapStores } from 'pinia';
import { useUIStore } from './stores/ui.store';
import { useSettingsStore } from './stores/settings.store';
import { useUsersStore } from './stores/users.store';
import { useRootStore } from './stores/n8nRoot.store';
import { useTemplatesStore } from './stores/templates.store';
import { useNodeTypesStore } from './stores/nodeTypes.store';
import { useUIStore } from '@/stores/ui.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useUsersStore } from '@/stores/users.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useTemplatesStore } from '@/stores/templates.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useHistoryHelper } from '@/composables/useHistoryHelper';
import { newVersions } from '@/mixins/newVersions';
import { useRoute } from 'vue-router/composables';
import { useVersionControlStore } from '@/stores/versionControl.store';
import { useExternalHooks } from '@/composables';
import { defineComponent } from 'vue';
export default mixins(newVersions, showMessage, userHelpers).extend({
export default defineComponent({
name: 'App',
components: {
LoadingView,
Telemetry,
Modals,
},
setup() {
mixins: [newVersions, userHelpers],
setup(props) {
return {
...useGlobalLinkActions(),
...useHistoryHelper(useRoute()),
...useToast(),
externalHooks: useExternalHooks(),
...newVersions.setup?.(props),
};
},
computed: {
Expand All @@ -86,7 +90,7 @@ export default mixins(newVersions, showMessage, userHelpers).extend({
try {
await this.settingsStore.getSettings();
} catch (e) {
this.$showToast({
this.showToast({
title: this.$locale.baseText('startupError'),
message: this.$locale.baseText('startupError.message'),
type: 'error',
Expand Down Expand Up @@ -188,12 +192,12 @@ export default mixins(newVersions, showMessage, userHelpers).extend({
this.logHiringBanner();
this.authenticate();
this.redirectIfNecessary();
this.checkForNewVersions();
void this.checkForNewVersions();
this.loading = false;
this.trackPage();
this.$externalHooks().run('app.mount');
void this.externalHooks.run('app.mount');
if (this.defaultLocale !== 'en') {
await this.nodeTypesStore.getNodeTranslationHeaders();
Expand Down
19 changes: 12 additions & 7 deletions packages/editor-ui/src/components/ChangePasswordModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@
</template>

<script lang="ts">
import mixins from 'vue-typed-mixins';
import { defineComponent } from 'vue';

import { showMessage } from '@/mixins/showMessage';
import Modal from './Modal.vue';
import { useToast } from '@/composables';
import Modal from '@/components/Modal.vue';
import type { IFormInputs } from '@/Interface';
import { CHANGE_PASSWORD_MODAL_KEY } from '../constants';
import { CHANGE_PASSWORD_MODAL_KEY } from '@/constants';
import { mapStores } from 'pinia';
import { useUsersStore } from '@/stores/users.store';
import { createEventBus } from '@/event-bus';

export default mixins(showMessage).extend({
export default defineComponent({
components: { Modal },
name: 'ChangePasswordModal',
props: {
modalName: {
type: String,
},
},
setup() {
return {
...useToast(),
};
},
data() {
return {
config: null as null | IFormInputs,
Expand Down Expand Up @@ -127,15 +132,15 @@ export default mixins(showMessage).extend({
this.loading = true;
await this.usersStore.updateCurrentUserPassword(values);

this.$showMessage({
this.showMessage({
type: 'success',
title: this.$locale.baseText('auth.changePassword.passwordUpdated'),
message: this.$locale.baseText('auth.changePassword.passwordUpdatedMessage'),
});

this.modalBus.emit('close');
} catch (error) {
this.$showError(error, this.$locale.baseText('auth.changePassword.error'));
this.showError(error, this.$locale.baseText('auth.changePassword.error'));
}
this.loading = false;
},
Expand Down
7 changes: 3 additions & 4 deletions packages/editor-ui/src/components/CommunityPackageCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@
import { useUIStore } from '@/stores/ui.store';
import type { PublicInstalledPackage } from 'n8n-workflow';
import { mapStores } from 'pinia';
import mixins from 'vue-typed-mixins';
import { NPM_PACKAGE_DOCS_BASE_URL, COMMUNITY_PACKAGE_MANAGE_ACTIONS } from '../constants';
import { showMessage } from '@/mixins/showMessage';
import { defineComponent } from 'vue';
import { NPM_PACKAGE_DOCS_BASE_URL, COMMUNITY_PACKAGE_MANAGE_ACTIONS } from '@/constants';
export default mixins(showMessage).extend({
export default defineComponent({
name: 'CommunityPackageCard',
props: {
communityPackage: {
Expand Down
19 changes: 12 additions & 7 deletions packages/editor-ui/src/components/CommunityPackageInstallModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,29 @@
</template>

<script lang="ts">
import Modal from './Modal.vue';
import Modal from '@/components/Modal.vue';
import {
COMMUNITY_PACKAGE_INSTALL_MODAL_KEY,
NPM_KEYWORD_SEARCH_URL,
COMMUNITY_NODES_INSTALLATION_DOCS_URL,
COMMUNITY_NODES_RISKS_DOCS_URL,
} from '../constants';
import mixins from 'vue-typed-mixins';
import { showMessage } from '@/mixins/showMessage';
} from '@/constants';
import { defineComponent } from 'vue';
import { useToast } from '@/composables';
import { mapStores } from 'pinia';
import { useCommunityNodesStore } from '@/stores/communityNodes.store';
import { createEventBus } from '@/event-bus';
export default mixins(showMessage).extend({
export default defineComponent({
name: 'CommunityPackageInstallModal',
components: {
Modal,
},
setup() {
return {
...useToast(),
};
},
data() {
return {
loading: false,
Expand Down Expand Up @@ -144,15 +149,15 @@ export default mixins(showMessage).extend({
await this.communityNodesStore.fetchInstalledPackages();
this.loading = false;
this.modalBus.emit('close');
this.$showMessage({
this.showMessage({
title: this.$locale.baseText('settings.communityNodes.messages.install.success'),
type: 'success',
});
} catch (error) {
if (error.httpStatusCode && error.httpStatusCode === 400) {
this.infoTextErrorMessage = error.message;
} else {
this.$showError(
this.showError(
error,
this.$locale.baseText('settings.communityNodes.messages.install.error'),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@
</template>

<script>
import mixins from 'vue-typed-mixins';
import Modal from './Modal.vue';
import {
COMMUNITY_PACKAGE_CONFIRM_MODAL_KEY,
COMMUNITY_PACKAGE_MANAGE_ACTIONS,
} from '../constants';
import { showMessage } from '@/mixins/showMessage';
import { defineComponent } from 'vue';
import Modal from '@/components/Modal.vue';
import { COMMUNITY_PACKAGE_CONFIRM_MODAL_KEY, COMMUNITY_PACKAGE_MANAGE_ACTIONS } from '@/constants';
import { useToast } from '@/composables';
import { mapStores } from 'pinia';
import { useCommunityNodesStore } from '@/stores/communityNodes.store';
import { createEventBus } from '@/event-bus';
export default mixins(showMessage).extend({
export default defineComponent({
name: 'CommunityPackageManageConfirmModal',
components: {
Modal,
Expand All @@ -64,6 +61,11 @@ export default mixins(showMessage).extend({
type: String,
},
},
setup() {
return {
...useToast(),
};
},
data() {
return {
loading: false,
Expand Down Expand Up @@ -140,12 +142,12 @@ export default mixins(showMessage).extend({
});
this.loading = true;
await this.communityNodesStore.uninstallPackage(this.activePackageName);
this.$showMessage({
this.showMessage({
title: this.$locale.baseText('settings.communityNodes.messages.uninstall.success.title'),
type: 'success',
});
} catch (error) {
this.$showError(
this.showError(
error,
this.$locale.baseText('settings.communityNodes.messages.uninstall.error'),
);
Expand All @@ -167,7 +169,7 @@ export default mixins(showMessage).extend({
this.loading = true;
const updatedVersion = this.activePackage.updateAvailable;
await this.communityNodesStore.updatePackage(this.activePackageName);
this.$showMessage({
this.showMessage({
title: this.$locale.baseText('settings.communityNodes.messages.update.success.title'),
message: this.$locale.baseText(
'settings.communityNodes.messages.update.success.message',
Expand All @@ -181,7 +183,7 @@ export default mixins(showMessage).extend({
type: 'success',
});
} catch (error) {
this.$showError(
this.showError(
error,
this.$locale.baseText('settings.communityNodes.messages.update.error.title'),
);
Expand Down
10 changes: 8 additions & 2 deletions packages/editor-ui/src/components/ContactPromptModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,22 @@ import mixins from 'vue-typed-mixins';
import type { IN8nPromptResponse } from '@/Interface';
import { VALID_EMAIL_REGEX } from '@/constants';
import { workflowHelpers } from '@/mixins/workflowHelpers';
import Modal from './Modal.vue';
import Modal from '@/components/Modal.vue';
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { createEventBus } from '@/event-bus';
import { useToast } from '@/composables';
export default mixins(workflowHelpers).extend({
components: { Modal },
name: 'ContactPromptModal',
props: ['modalName'],
setup() {
return {
...useToast(),
};
},
data() {
return {
email: '',
Expand Down Expand Up @@ -94,7 +100,7 @@ export default mixins(workflowHelpers).extend({
instance_id: this.rootStore.instanceId,
email: this.email,
});
this.$showMessage({
this.showMessage({
title: 'Thanks!',
message: "It's people like you that help make n8n better",
type: 'success',
Expand Down
11 changes: 8 additions & 3 deletions packages/editor-ui/src/components/CopyInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<script lang="ts">
import mixins from 'vue-typed-mixins';
import { copyPaste } from '@/mixins/copyPaste';
import { showMessage } from '@/mixins/showMessage';
import { useToast } from '@/composables';
export default mixins(copyPaste, showMessage).extend({
export default mixins(copyPaste).extend({
props: {
label: {
type: String,
Expand Down Expand Up @@ -56,12 +56,17 @@ export default mixins(copyPaste, showMessage).extend({
default: 'large',
},
},
setup() {
return {
...useToast(),
};
},
methods: {
copy(): void {
this.$emit('copy');
this.copyToClipboard(this.value);
this.$showMessage({
this.showMessage({
title: this.toastTitle,
message: this.toastMessage,
type: 'success',
Expand Down
Loading