From d31077a5104b53644cb83f68031aeff2d29d3aa7 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Fri, 30 Jun 2023 01:38:48 +0800 Subject: [PATCH] Remove conf values --- web/src/BaseListPage.js | 8 +++----- web/src/Conf.js | 5 ----- web/src/OrganizationEditPage.js | 4 ++-- web/src/OrganizationListPage.js | 5 ++--- web/src/Setting.js | 9 ++++----- web/src/common/select/OrganizationSelect.js | 9 ++++----- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/web/src/BaseListPage.js b/web/src/BaseListPage.js index d3596011..20623cfd 100644 --- a/web/src/BaseListPage.js +++ b/web/src/BaseListPage.js @@ -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() { diff --git a/web/src/Conf.js b/web/src/Conf.js index 0f7fc335..facd254a 100644 --- a/web/src/Conf.js +++ b/web/src/Conf.js @@ -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"; diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index f63076b9..996ac312 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -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}`); } diff --git a/web/src/OrganizationListPage.js b/web/src/OrganizationListPage.js index e7f3d2d6..8091b6a2 100644 --- a/web/src/OrganizationListPage.js +++ b/web/src/OrganizationListPage.js @@ -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}`); } diff --git a/web/src/Setting.js b/web/src/Setting.js index 6219961d..0735e9b2 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -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; } diff --git a/web/src/common/select/OrganizationSelect.js b/web/src/common/select/OrganizationSelect.js index b7102be9..88265cd2 100644 --- a/web/src/common/select/OrganizationSelect.js +++ b/web/src/common/select/OrganizationSelect.js @@ -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", }); }