Remove conf values

This commit is contained in:
Yang Luo
2023-06-30 01:38:48 +08:00
parent eee9b8b9fe
commit d31077a510
6 changed files with 15 additions and 25 deletions

View File

@ -18,8 +18,6 @@ import {SearchOutlined} from "@ant-design/icons";
import Highlighter from "react-highlight-words";
import i18next from "i18next";
import * as Setting from "./Setting";
import * as Conf from "./Conf";
import {DefaultOrganization} from "./Conf";
class BaseListPage extends React.Component {
constructor(props) {
@ -44,14 +42,14 @@ class BaseListPage extends React.Component {
};
componentDidMount() {
window.addEventListener(Conf.StorageOrganizationChangedEvent, this.handleOrganizationChange);
window.addEventListener("storageOrganizationChanged", this.handleOrganizationChange);
if (!Setting.isAdminUser(this.props.account)) {
Setting.setOrganization(DefaultOrganization);
Setting.setOrganization("All");
}
}
componentWillUnmount() {
window.removeEventListener(Conf.StorageOrganizationChangedEvent, this.handleOrganizationChange);
window.removeEventListener("storageOrganizationChanged", this.handleOrganizationChange);
}
UNSAFE_componentWillMount() {

View File

@ -32,8 +32,3 @@ export const ThemeDefault = {
};
export const CustomFooter = null;
export const DefaultOrganization = "All"; // i18next.t("organization:All")
export const StorageOrganizationChangedEvent = "storageOrganizationChanged";
export const StorageOrganizationsChangedEvent = "storageOrganizationsChanged";

View File

@ -427,7 +427,7 @@ class OrganizationEditPage extends React.Component {
this.setState({
organizationName: this.state.organization.name,
});
window.dispatchEvent(new Event(Conf.StorageOrganizationsChangedEvent));
window.dispatchEvent(new Event("storageOrganizationsChanged"));
if (willExist) {
this.props.history.push("/organizations");
@ -449,7 +449,7 @@ class OrganizationEditPage extends React.Component {
.then((res) => {
if (res.status === "ok") {
this.props.history.push("/organizations");
window.dispatchEvent(new Event(Conf.StorageOrganizationsChangedEvent));
window.dispatchEvent(new Event("storageOrganizationsChanged"));
} else {
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
}

View File

@ -21,7 +21,6 @@ import * as OrganizationBackend from "./backend/OrganizationBackend";
import i18next from "i18next";
import BaseListPage from "./BaseListPage";
import PopconfirmModal from "./common/modal/PopconfirmModal";
import * as Conf from "./Conf";
class OrganizationListPage extends BaseListPage {
newOrganization() {
@ -84,7 +83,7 @@ class OrganizationListPage extends BaseListPage {
if (res.status === "ok") {
this.props.history.push({pathname: `/organizations/${newOrganization.name}`, mode: "add"});
Setting.showMessage("success", i18next.t("general:Successfully added"));
window.dispatchEvent(new Event(Conf.StorageOrganizationsChangedEvent));
window.dispatchEvent(new Event("storageOrganizationsChanged"));
} else {
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
}
@ -105,7 +104,7 @@ class OrganizationListPage extends BaseListPage {
...this.state.pagination,
total: this.state.pagination.total - 1},
});
window.dispatchEvent(new Event(Conf.StorageOrganizationsChangedEvent));
window.dispatchEvent(new Event("storageOrganizationsChanged"));
} else {
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
}

View File

@ -25,7 +25,6 @@ import {Helmet} from "react-helmet";
import * as Conf from "./Conf";
import * as phoneNumber from "libphonenumber-js";
import moment from "moment";
import {DefaultOrganization} from "./Conf";
const {Option} = Select;
@ -1168,24 +1167,24 @@ export function inIframe() {
export function getOrganization() {
const organization = localStorage.getItem("organization");
return organization !== null ? organization : DefaultOrganization;
return organization !== null ? organization : "All";
}
export function setOrganization(organization) {
localStorage.setItem("organization", organization);
window.dispatchEvent(new Event(Conf.StorageOrganizationChangedEvent));
window.dispatchEvent(new Event("storageOrganizationChanged"));
}
export function getRequestOrganization(account) {
if (isAdminUser(account)) {
return getOrganization() === DefaultOrganization ? account.owner : getOrganization();
return getOrganization() === "All" ? account.owner : getOrganization();
}
return account.owner;
}
export function isDefaultOrganizationSelected(account) {
if (isAdminUser(account)) {
return getOrganization() === DefaultOrganization;
return getOrganization() === "All";
}
return false;
}

View File

@ -17,7 +17,6 @@ import {Select} from "antd";
import i18next from "i18next";
import * as OrganizationBackend from "../../backend/OrganizationBackend";
import * as Setting from "../../Setting";
import * as Conf from "../../Conf";
function OrganizationSelect(props) {
const {onChange, initValue, style, onSelect, withAll, className} = props;
@ -28,9 +27,9 @@ function OrganizationSelect(props) {
if (props.organizations === undefined) {
getOrganizations();
}
window.addEventListener(Conf.StorageOrganizationsChangedEvent, getOrganizations);
window.addEventListener("storageOrganizationsChanged", getOrganizations);
return function() {
window.removeEventListener(Conf.StorageOrganizationsChangedEvent, getOrganizations);
window.removeEventListener("storageOrganizationsChanged", getOrganizations);
};
}, [value]);
@ -59,8 +58,8 @@ function OrganizationSelect(props) {
if (withAll) {
items.unshift({
label: i18next.t(`organization:${Conf.DefaultOrganization}`),
value: Conf.DefaultOrganization,
label: i18next.t("organization:All"),
value: "All",
});
}