mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-24 06:29:24 +08:00
This particular system test is taking a long time (~20 seconds) on CI because it is doing many full page loads. This commit refactors the test to be more efficient about the number of full page loads triggered by the tests thus reducing the runtime by half. Co-authored-by: Krzysztof Kotlarek <kotlarek.krzysztof@gmail.com>
83 lines
2.2 KiB
Text
Vendored
83 lines
2.2 KiB
Text
Vendored
import Component from "@glimmer/component";
|
|
import { tracked } from "@glimmer/tracking";
|
|
import { action } from "@ember/object";
|
|
import { service } from "@ember/service";
|
|
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 AdminFlagItem from "admin/components/admin-flag-item";
|
|
|
|
export default class AdminConfigAreasFlags extends Component {
|
|
@service site;
|
|
@service siteSettings;
|
|
|
|
@tracked flags = this.site.flagTypes;
|
|
|
|
@bind
|
|
isFirstFlag(flag) {
|
|
return this.flags.indexOf(flag) === 1;
|
|
}
|
|
|
|
@bind
|
|
isLastFlag(flag) {
|
|
return this.flags.indexOf(flag) === this.flags.length - 1;
|
|
}
|
|
|
|
@action
|
|
moveFlagCallback(flag, direction) {
|
|
const fallbackFlags = [...this.flags];
|
|
|
|
const flags = this.flags;
|
|
|
|
const flagIndex = flags.indexOf(flag);
|
|
const targetFlagIndex = direction === "up" ? flagIndex - 1 : flagIndex + 1;
|
|
|
|
const targetFlag = flags[targetFlagIndex];
|
|
|
|
flags[flagIndex] = targetFlag;
|
|
flags[targetFlagIndex] = flag;
|
|
|
|
this.flags = flags;
|
|
|
|
return ajax(`/admin/config/flags/${flag.id}/reorder/${direction}`, {
|
|
type: "PUT",
|
|
}).catch((error) => {
|
|
this.flags = fallbackFlags;
|
|
return popupAjaxError(error);
|
|
});
|
|
}
|
|
|
|
@action
|
|
deleteFlagCallback(flag) {
|
|
return ajax(`/admin/config/flags/${flag.id}`, {
|
|
type: "DELETE",
|
|
})
|
|
.then(() => {
|
|
this.flags.removeObject(flag);
|
|
})
|
|
.catch((error) => popupAjaxError(error));
|
|
}
|
|
|
|
<template>
|
|
<div class="container admin-flags">
|
|
<table class="d-admin-table admin-flags__items">
|
|
<thead>
|
|
<th>{{i18n "admin.config_areas.flags.description"}}</th>
|
|
<th>{{i18n "admin.config_areas.flags.enabled"}}</th>
|
|
</thead>
|
|
<tbody>
|
|
{{#each this.flags as |flag|}}
|
|
<AdminFlagItem
|
|
@flag={{flag}}
|
|
@moveFlagCallback={{this.moveFlagCallback}}
|
|
@deleteFlagCallback={{this.deleteFlagCallback}}
|
|
@isFirstFlag={{this.isFirstFlag flag}}
|
|
@isLastFlag={{this.isLastFlag flag}}
|
|
/>
|
|
{{/each}}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</template>
|
|
}
|