discourse/app/assets/javascripts/admin/addon/components/dashboard-new-features.gjs
David Taylor 0ed4b09527
DEV: Move discourse-common/(utils|lib) to discourse/lib (#30733)
`discourse-common` was created in the past to share logic between the
'wizard' app and the main 'discourse' app. Since then, the wizard has
been consolidated into the main app, so the separation of
`discourse-common` is no longer useful.

This commit moves `discourse-common/(lib|utils)/*` into
`discourse/lib/*`, adds shims for the imports, and updates existing
uses in core.
2025-01-13 13:02:49 +00:00

85 lines
2.7 KiB
Plaintext

import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { service } from "@ember/service";
import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { bind } from "discourse/lib/decorators";
import { i18n } from "discourse-i18n";
import AdminConfigAreaCard from "admin/components/admin-config-area-card";
import AdminConfigAreaEmptyList from "admin/components/admin-config-area-empty-list";
import DashboardNewFeatureItem from "admin/components/dashboard-new-feature-item";
export default class DashboardNewFeatures extends Component {
@service currentUser;
@tracked newFeatures = null;
@tracked groupedNewFeatures = null;
@tracked isLoading = true;
constructor() {
super(...arguments);
this.args.onCheckForFeatures(this.loadNewFeatures);
}
@bind
async loadNewFeatures(opts = {}) {
opts.forceRefresh ||= false;
this.isLoading = true;
try {
const json = await ajax(
"/admin/whats-new.json?force_refresh=" + opts.forceRefresh
);
const items = json.new_features.reduce((acc, feature) => {
const key = moment(feature.released_at || feature.created_at).format(
"YYYY-MM"
);
acc[key] = acc[key] || [];
acc[key].push(feature);
return acc;
}, {});
this.groupedNewFeatures = Object.keys(items).map((date) => {
return {
date: moment
.tz(date, this.currentUser.user_option.timezone)
.format("MMMM YYYY"),
features: items[date],
};
});
} catch (err) {
popupAjaxError(err);
} finally {
this.isLoading = false;
}
}
<template>
<div
class="admin-config-area__primary-content"
{{didInsert this.loadNewFeatures}}
>
<ConditionalLoadingSpinner @condition={{this.isLoading}}>
{{#each this.groupedNewFeatures as |groupedFeatures|}}
<AdminConfigAreaCard @translatedHeading={{groupedFeatures.date}}>
<:content>
{{#each groupedFeatures.features as |feature|}}
<DashboardNewFeatureItem @item={{feature}} />
{{/each}}
</:content>
</AdminConfigAreaCard>
{{else}}
<AdminConfigAreaEmptyList
@emptyLabelTranslated={{i18n
"admin.dashboard.new_features.previous_announcements"
url="https://meta.discourse.org/tags/c/announcements/67/release-notes"
}}
/>
{{/each}}
</ConditionalLoadingSpinner>
</div>
</template>
}