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

DEV: Modernise csv-uploader component #633

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
66 changes: 66 additions & 0 deletions assets/javascripts/discourse/components/csv-uploader.gjs
Original file line number Diff line number Diff line change
@@ -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;
davidtaylorhq marked this conversation as resolved.
Show resolved Hide resolved
}

<template>
<span>
<label class="btn" disabled={{this.uploadButtonDisabled}}>
{{icon "upload"}}&nbsp;{{this.uploadButtonText}}
<input
{{didInsert this.uppyUpload.setup}}
class="hidden-upload-field"
disabled={{this.uppyUpload.uploading}}
type="file"
accept=".csv"
/>
</label>
{{#if (or this.uppyUpload.uploading this.uppyUpload.processing)}}
<span>{{i18n "upload_selector.uploading"}}
{{this.uppyUpload.uploadProgress}}%</span>
{{/if}}
</span>
</template>
}
12 changes: 0 additions & 12 deletions assets/javascripts/discourse/components/csv-uploader.hbs

This file was deleted.

43 changes: 0 additions & 43 deletions assets/javascripts/discourse/components/csv-uploader.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
<BulkInviteSampleCsvFile />

<CsvUploader
@id="discourse-post-event-csv-uploader"
@uploadUrl={{concat
"/discourse-post-event/events/"
@model.event.id
Expand Down