From a7d68415979b775058f822a2e03aca86c6a1683e Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 24 Oct 2024 12:56:09 +0100 Subject: [PATCH 1/2] DEV: Modernise csv-uploader component - remove uppy mixin - native class - glimmer component - gjs file format --- .../discourse/components/csv-uploader.gjs | 66 +++++++++++++++++++ .../discourse/components/csv-uploader.hbs | 12 ---- .../discourse/components/csv-uploader.js | 43 ------------ .../modal/post-event-bulk-invite.hbs | 1 - 4 files changed, 66 insertions(+), 56 deletions(-) create mode 100644 assets/javascripts/discourse/components/csv-uploader.gjs delete mode 100644 assets/javascripts/discourse/components/csv-uploader.hbs delete mode 100644 assets/javascripts/discourse/components/csv-uploader.js diff --git a/assets/javascripts/discourse/components/csv-uploader.gjs b/assets/javascripts/discourse/components/csv-uploader.gjs new file mode 100644 index 000000000..c6e8b22ad --- /dev/null +++ b/assets/javascripts/discourse/components/csv-uploader.gjs @@ -0,0 +1,66 @@ +import Component from "@glimmer/component"; +import { getOwner } from "@ember/owner"; +import didInsert from "@ember/render-modifiers/modifiers/did-insert"; +import { inject as service } from "@ember/service"; +import { or } from "truth-helpers"; +import UppyUpload from "discourse/lib/uppy/uppy-upload"; +import icon from "discourse-common/helpers/d-icon"; +import i18n from "discourse-common/helpers/i18n"; + +export default class CsvUploader extends Component { + @service dialog; + + uppyUpload = new UppyUpload(getOwner(this), { + type: "csv", + id: "discourse-post-event-csv-uploader", + autoStartUploads: false, + uploadUrl: this.args.uploadUrl, + uppyReady: () => { + this.uppyUpload.uppyWrapper.uppyInstance.on("file-added", () => { + this.dialog.confirm({ + message: i18n(`${this.args.i18nPrefix}.confirmation_message`), + didConfirm: () => this.uppyUpload.startUpload(), + didCancel: () => this.uppyUpload.reset(), + }); + }); + }, + uploadDone: () => { + this.dialog.alert(i18n(`${this.args.i18nPrefix}.success`)); + }, + validateUploadedFilesOptions: { + csvOnly: true, + }, + }); + + get uploadButtonText() { + return this.uppyUpload.uploading + ? i18n("uploading") + : i18n(`${this.args.i18nPrefix}.text`); + } + + get uploadButtonDisabled() { + // https://github.com/emberjs/ember.js/issues/10976#issuecomment-132417731 + return this.uppyUpload.uploading || this.uppyUpload.processing + ? true + : null; + } + + +} diff --git a/assets/javascripts/discourse/components/csv-uploader.hbs b/assets/javascripts/discourse/components/csv-uploader.hbs deleted file mode 100644 index f8f76133d..000000000 --- a/assets/javascripts/discourse/components/csv-uploader.hbs +++ /dev/null @@ -1,12 +0,0 @@ - -{{#if (or uploading processing)}} - {{i18n "upload_selector.uploading"}} {{uploadProgress}}% -{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/components/csv-uploader.js b/assets/javascripts/discourse/components/csv-uploader.js deleted file mode 100644 index cf824b1e7..000000000 --- a/assets/javascripts/discourse/components/csv-uploader.js +++ /dev/null @@ -1,43 +0,0 @@ -import Component from "@ember/component"; -import { inject as service } from "@ember/service"; -import UppyUploadMixin from "discourse/mixins/uppy-upload"; -import discourseComputed from "discourse-common/utils/decorators"; -import I18n from "I18n"; - -export default Component.extend(UppyUploadMixin, { - type: "csv", - tagName: "span", - dialog: service(), - uploadUrl: null, - i18nPrefix: null, - autoStartUploads: false, - - validateUploadedFilesOptions() { - return { csvOnly: true }; - }, - - @discourseComputed("uploading") - uploadButtonText(uploading) { - return uploading ? I18n.t("uploading") : I18n.t(`${this.i18nPrefix}.text`); - }, - - @discourseComputed("uploading", "processing") - uploadButtonDisabled(uploading, processing) { - // https://github.com/emberjs/ember.js/issues/10976#issuecomment-132417731 - return uploading || processing ? true : null; - }, - - uploadDone() { - this.dialog.alert(I18n.t(`${this.i18nPrefix}.success`)); - }, - - _uppyReady() { - this._uppyInstance.on("file-added", () => { - this.dialog.confirm({ - message: I18n.t(`${this.i18nPrefix}.confirmation_message`), - didConfirm: () => this._startUpload(), - didCancel: () => this._reset(), - }); - }); - }, -}); diff --git a/assets/javascripts/discourse/components/modal/post-event-bulk-invite.hbs b/assets/javascripts/discourse/components/modal/post-event-bulk-invite.hbs index e3d45e266..dd4e7a96e 100644 --- a/assets/javascripts/discourse/components/modal/post-event-bulk-invite.hbs +++ b/assets/javascripts/discourse/components/modal/post-event-bulk-invite.hbs @@ -84,7 +84,6 @@ Date: Thu, 24 Oct 2024 20:48:06 +0100 Subject: [PATCH 2/2] Update assets/javascripts/discourse/components/csv-uploader.gjs Co-authored-by: Jarek Radosz --- assets/javascripts/discourse/components/csv-uploader.gjs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/components/csv-uploader.gjs b/assets/javascripts/discourse/components/csv-uploader.gjs index c6e8b22ad..0ab8e5ec6 100644 --- a/assets/javascripts/discourse/components/csv-uploader.gjs +++ b/assets/javascripts/discourse/components/csv-uploader.gjs @@ -40,9 +40,7 @@ export default class CsvUploader extends Component { get uploadButtonDisabled() { // https://github.com/emberjs/ember.js/issues/10976#issuecomment-132417731 - return this.uppyUpload.uploading || this.uppyUpload.processing - ? true - : null; + return this.uppyUpload.uploading || this.uppyUpload.processing || null; }