More refactoring
This commit is contained in:
parent
acff1b4cb2
commit
adffa4f448
@ -3,7 +3,6 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import { Paginated } from "../../../../services/Paginated";
|
import { Paginated } from "../../../../services/Paginated";
|
||||||
import { MakeGeneralIdRef } from "../../../../utils/GeneralIdRef";
|
import { MakeGeneralIdRef } from "../../../../utils/GeneralIdRef";
|
||||||
import withRouter, { RouterProps } from "../../../../utils/withRouter";
|
|
||||||
import roleService, {
|
import roleService, {
|
||||||
GetRoleSecurityAccess,
|
GetRoleSecurityAccess,
|
||||||
GetSecurityAccess,
|
GetSecurityAccess,
|
||||||
@ -27,14 +26,11 @@ const initialAccessList: Paginated<GetSecurityAccess> = {
|
|||||||
data: [],
|
data: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
interface RoleAccessEditorProps extends RouterProps {
|
interface RoleAccessEditorProps {
|
||||||
role: any | undefined;
|
role: any | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RoleAccessEditorNoRouter: React.FC<RoleAccessEditorProps> = ({
|
const RoleAccessEditor: React.FC<RoleAccessEditorProps> = ({ role }) => {
|
||||||
role,
|
|
||||||
router,
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
const [accessList, setAccessList] =
|
const [accessList, setAccessList] =
|
||||||
@ -187,6 +183,4 @@ const RoleAccessEditorNoRouter: React.FC<RoleAccessEditorProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const RoleAccessEditor = withRouter(RoleAccessEditorNoRouter);
|
|
||||||
|
|
||||||
export default RoleAccessEditor;
|
export default RoleAccessEditor;
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import Column from "../../../../components/common/columns";
|
import Column from "../../../../components/common/columns";
|
||||||
import { Paginated } from "../../../../services/Paginated";
|
import { Paginated } from "../../../../services/Paginated";
|
||||||
import { MakeGeneralIdRef } from "../../../../utils/GeneralIdRef";
|
import { MakeGeneralIdRef } from "../../../../utils/GeneralIdRef";
|
||||||
import withRouter, { RouterProps } from "../../../../utils/withRouter";
|
import { useParams } from "react-router-dom";
|
||||||
import roleService, { GetRoleResponse } from "../serrvices/rolesService";
|
import roleService, { GetRoleResponse } from "../serrvices/rolesService";
|
||||||
import RolesTable from "./RolesTable";
|
import RolesTable from "./RolesTable";
|
||||||
import Button, { ButtonType } from "../../../../components/common/Button";
|
import Button, { ButtonType } from "../../../../components/common/Button";
|
||||||
@ -18,17 +18,16 @@ const initialPagedData: Paginated<GetRoleResponse> = {
|
|||||||
data: [],
|
data: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
interface RolesEditorProps extends RouterProps {
|
interface RolesEditorProps {
|
||||||
selectedRole?: GetRoleResponse;
|
selectedRole?: GetRoleResponse;
|
||||||
onSelectRole?: (keyValue: any) => void;
|
onSelectRole?: (keyValue: any) => void;
|
||||||
onUnselectRole?: () => void;
|
onUnselectRole?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RolesEditorTabNoRouter: React.FC<RolesEditorProps> = ({
|
const RolesEditor: React.FC<RolesEditorProps> = ({
|
||||||
selectedRole,
|
selectedRole,
|
||||||
onSelectRole,
|
onSelectRole,
|
||||||
onUnselectRole,
|
onUnselectRole,
|
||||||
router,
|
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
@ -43,9 +42,9 @@ const RolesEditorTabNoRouter: React.FC<RolesEditorProps> = ({
|
|||||||
() => new Map<string, string>(),
|
() => new Map<string, string>(),
|
||||||
);
|
);
|
||||||
|
|
||||||
const { domainId } = router.params;
|
const { domainId } = useParams<{ domainId: string }>();
|
||||||
const domainGeneralIdRef = useMemo(
|
const domainGeneralIdRef = useMemo(
|
||||||
() => MakeGeneralIdRef(domainId),
|
() => MakeGeneralIdRef(domainId ? BigInt(domainId) : undefined),
|
||||||
[domainId],
|
[domainId],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -171,6 +170,4 @@ const RolesEditorTabNoRouter: React.FC<RolesEditorProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const RolesEditor = withRouter(RolesEditorTabNoRouter);
|
|
||||||
|
|
||||||
export default RolesEditor;
|
export default RolesEditor;
|
||||||
|
|||||||
@ -2,16 +2,13 @@ import React, { useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import HorizontalTabs from "../../../../components/common/HorizionalTabs";
|
import HorizontalTabs from "../../../../components/common/HorizionalTabs";
|
||||||
import Tab from "../../../../components/common/Tab";
|
import Tab from "../../../../components/common/Tab";
|
||||||
import withRouter, { RouterProps } from "../../../../utils/withRouter";
|
|
||||||
import RoleAccessEditor from "./RoleAccessEditor";
|
import RoleAccessEditor from "./RoleAccessEditor";
|
||||||
import RolesEditor from "./RolesEditor";
|
import RolesEditor from "./RolesEditor";
|
||||||
import UserRoleEditor from "./UserRoleEditor";
|
import UserRoleEditor from "./UserRoleEditor";
|
||||||
import { GetRoleResponse } from "../serrvices/rolesService";
|
import { GetRoleResponse } from "../serrvices/rolesService";
|
||||||
import authentication from "../../../frame/services/authenticationService";
|
import authentication from "../../../frame/services/authenticationService";
|
||||||
|
|
||||||
interface SecurityRolesTabProps extends RouterProps {}
|
const SecurityRolesTab: React.FC = () => {
|
||||||
|
|
||||||
const SecurityRolesTabNoRouter: React.FC<SecurityRolesTabProps> = () => {
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [selectedRole, setSelectedRole] = useState<GetRoleResponse | undefined>(
|
const [selectedRole, setSelectedRole] = useState<GetRoleResponse | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
@ -64,6 +61,4 @@ const SecurityRolesTabNoRouter: React.FC<SecurityRolesTabProps> = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const SecurityRolesTab = withRouter(SecurityRolesTabNoRouter);
|
|
||||||
|
|
||||||
export default SecurityRolesTab;
|
export default SecurityRolesTab;
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { useTranslation } from "react-i18next";
|
|||||||
import Column from "../../../../components/common/columns";
|
import Column from "../../../../components/common/columns";
|
||||||
import { Paginated } from "../../../../services/Paginated";
|
import { Paginated } from "../../../../services/Paginated";
|
||||||
import { MakeGeneralIdRef } from "../../../../utils/GeneralIdRef";
|
import { MakeGeneralIdRef } from "../../../../utils/GeneralIdRef";
|
||||||
import withRouter, { RouterProps } from "../../../../utils/withRouter";
|
|
||||||
import UserRolesTable from "./UserRolesTable";
|
import UserRolesTable from "./UserRolesTable";
|
||||||
import roleService, { RoleUser } from "../serrvices/rolesService";
|
import roleService, { RoleUser } from "../serrvices/rolesService";
|
||||||
import Button, { ButtonType } from "../../../../components/common/Button";
|
import Button, { ButtonType } from "../../../../components/common/Button";
|
||||||
@ -18,14 +17,11 @@ const initialPagedData: Paginated<RoleUser> = {
|
|||||||
data: [],
|
data: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
interface UserRoleEditorProps extends RouterProps {
|
interface UserRoleEditorProps {
|
||||||
role: any | undefined;
|
role: any | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UserRoleEditorNoRouter: React.FC<UserRoleEditorProps> = ({
|
const UserRoleEditor: React.FC<UserRoleEditorProps> = ({ role }) => {
|
||||||
role,
|
|
||||||
router,
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
const [pagedData, setPagedData] =
|
const [pagedData, setPagedData] =
|
||||||
@ -138,6 +134,4 @@ const UserRoleEditorNoRouter: React.FC<UserRoleEditorProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const UserRoleEditor = withRouter(UserRoleEditorNoRouter);
|
|
||||||
|
|
||||||
export default UserRoleEditor;
|
export default UserRoleEditor;
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useParams } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { MakeGeneralIdRef } from "../../../utils/GeneralIdRef";
|
import { MakeGeneralIdRef } from "../../../utils/GeneralIdRef";
|
||||||
import withRouter from "../../../utils/withRouter";
|
|
||||||
import GlossariesTable from "./components/GlossariesTable";
|
import GlossariesTable from "./components/GlossariesTable";
|
||||||
import glossariesService, {
|
import glossariesService, {
|
||||||
Glossary,
|
Glossary,
|
||||||
@ -13,9 +12,9 @@ import Button, { ButtonType } from "../../../components/common/Button";
|
|||||||
import Loading from "../../../components/common/Loading";
|
import Loading from "../../../components/common/Loading";
|
||||||
import Permission from "../../../components/common/Permission";
|
import Permission from "../../../components/common/Permission";
|
||||||
|
|
||||||
const Glossaries: React.FC<any> = (props) => {
|
const Glossaries: React.FC = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const glossaryId = props?.router?.params?.glossaryId;
|
const { glossaryId } = useParams<{ glossaryId: string }>();
|
||||||
|
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
const [data, setData] = useState<Glossary | undefined>(undefined);
|
const [data, setData] = useState<Glossary | undefined>(undefined);
|
||||||
@ -26,7 +25,7 @@ const Glossaries: React.FC<any> = (props) => {
|
|||||||
let parentItem: GeneralIdRef = SystemGlossaries;
|
let parentItem: GeneralIdRef = SystemGlossaries;
|
||||||
|
|
||||||
if (glossaryId !== undefined) {
|
if (glossaryId !== undefined) {
|
||||||
parentItem = MakeGeneralIdRef(glossaryId);
|
parentItem = MakeGeneralIdRef(BigInt(glossaryId));
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await glossariesService.getGlossaryItem(parentItem);
|
const result = await glossariesService.getGlossaryItem(parentItem);
|
||||||
@ -102,7 +101,7 @@ const Glossaries: React.FC<any> = (props) => {
|
|||||||
const table = (
|
const table = (
|
||||||
<div>
|
<div>
|
||||||
{t("Items")}
|
{t("Items")}
|
||||||
<GlossariesTable params={props.params} data={data} onDelete={onDelete} />
|
<GlossariesTable data={data} onDelete={onDelete} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -147,9 +146,7 @@ const Glossaries: React.FC<any> = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const HOCGlossaries = withRouter(Glossaries);
|
export default Glossaries;
|
||||||
|
|
||||||
export default HOCGlossaries;
|
|
||||||
|
|
||||||
function concatinate(args: (unknown | undefined)[], seperator: string): string {
|
function concatinate(args: (unknown | undefined)[], seperator: string): string {
|
||||||
let result = "";
|
let result = "";
|
||||||
|
|||||||
@ -5,14 +5,9 @@ import Table from "../../../../components/common/Table";
|
|||||||
import { Glossary } from "../services/glossaryService";
|
import { Glossary } from "../services/glossaryService";
|
||||||
import authentication from "../../../frame/services/authenticationService";
|
import authentication from "../../../frame/services/authenticationService";
|
||||||
|
|
||||||
export interface GlossaryParams {
|
|
||||||
id: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GlossariesTableProps {
|
interface GlossariesTableProps {
|
||||||
data?: Glossary;
|
data?: Glossary;
|
||||||
onDelete?: (keyValue: any) => void;
|
onDelete?: (keyValue: any) => void;
|
||||||
params: GlossaryParams;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CustomColumn extends Column<customField> {
|
interface CustomColumn extends Column<customField> {
|
||||||
|
|||||||
@ -1,128 +1,165 @@
|
|||||||
import React, { Component } from "react";
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
import Column from "../../../components/common/columns";
|
import Column from "../../../components/common/columns";
|
||||||
import { Paginated } from "../../../services/Paginated";
|
import { Paginated } from "../../../services/Paginated";
|
||||||
import Button, { ButtonType } from "../../../components/common/Button";
|
import Button, { ButtonType } from "../../../components/common/Button";
|
||||||
import withRouter from "../../../utils/withRouter";
|
|
||||||
import siteService, { ReadSite } from "./services/sitessService";
|
import siteService, { ReadSite } from "./services/sitessService";
|
||||||
import SitesTable from "./components/SitesTable";
|
import SitesTable from "./components/SitesTable";
|
||||||
import Loading from "../../../components/common/Loading";
|
import Loading from "../../../components/common/Loading";
|
||||||
import Permission from "../../../components/common/Permission";
|
import Permission from "../../../components/common/Permission";
|
||||||
|
|
||||||
interface SitesState {
|
const initialPagedData: Paginated<ReadSite> = {
|
||||||
loaded: boolean;
|
page: 1,
|
||||||
pagedData: Paginated<ReadSite>;
|
pageSize: 10,
|
||||||
sortColumn: Column<ReadSite>;
|
count: 0,
|
||||||
filters: Map<string, string>;
|
totalPages: 1,
|
||||||
}
|
data: [],
|
||||||
|
};
|
||||||
|
|
||||||
class LocSites extends Component<any, any, SitesState> {
|
const Sites: React.FC = () => {
|
||||||
state = {
|
const { t } = useTranslation();
|
||||||
loaded: false,
|
const { organisationId } = useParams<{ organisationId: string }>();
|
||||||
pagedData: { page: 1, pageSize: 10, count: 0, totalPages: 1, data: [] },
|
|
||||||
sortColumn: { key: "name", label: "Name", order: "asc" },
|
|
||||||
filters: new Map<string, string>(),
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount = async () => {
|
const [loaded, setLoaded] = useState(false);
|
||||||
const { page, pageSize } = this.state.pagedData;
|
const [pagedData, setPagedData] =
|
||||||
await this.changePage(page, pageSize);
|
useState<Paginated<ReadSite>>(initialPagedData);
|
||||||
};
|
const [sortColumn, setSortColumn] = useState<Column<ReadSite>>({
|
||||||
|
key: "name",
|
||||||
|
label: t("Name"),
|
||||||
|
order: "asc",
|
||||||
|
});
|
||||||
|
const [filters, setFilters] = useState<Map<string, string>>(
|
||||||
|
() => new Map<string, string>(),
|
||||||
|
);
|
||||||
|
|
||||||
changePage = async (page: number, pageSize: number) => {
|
const updateFiltersWithOrganisationId = useCallback(
|
||||||
const { sortColumn, filters } = this.state;
|
(nextFilters: Map<string, string>) => {
|
||||||
const { organisationId } = this.props.router.params;
|
const updatedFilters = new Map(nextFilters);
|
||||||
|
if (organisationId) {
|
||||||
|
updatedFilters.set("organisationId", organisationId);
|
||||||
|
}
|
||||||
|
return updatedFilters;
|
||||||
|
},
|
||||||
|
[organisationId],
|
||||||
|
);
|
||||||
|
|
||||||
filters.set("organisationId", organisationId);
|
const changePage = useCallback(
|
||||||
|
async (page: number, pageSize: number) => {
|
||||||
const pagedData = await siteService.getSites(
|
const nextFilters = updateFiltersWithOrganisationId(filters);
|
||||||
page,
|
const pagedDataResult = await siteService.getSites(
|
||||||
pageSize,
|
page,
|
||||||
sortColumn.key,
|
pageSize,
|
||||||
sortColumn.order === "asc",
|
sortColumn.key,
|
||||||
|
sortColumn.order === "asc",
|
||||||
|
nextFilters,
|
||||||
|
);
|
||||||
|
if (pagedDataResult) {
|
||||||
|
setLoaded(true);
|
||||||
|
setFilters(nextFilters);
|
||||||
|
setPagedData(pagedDataResult);
|
||||||
|
} else {
|
||||||
|
setLoaded(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[
|
||||||
filters,
|
filters,
|
||||||
);
|
|
||||||
if (pagedData) {
|
|
||||||
this.setState({ loaded: true, pagedData, filters });
|
|
||||||
} else {
|
|
||||||
this.setState({ loaded: false });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onSort = async (sortColumn: Column<ReadSite>) => {
|
|
||||||
const { page, pageSize } = this.state.pagedData;
|
|
||||||
const { filters } = this.state;
|
|
||||||
|
|
||||||
const { organisationId } = this.props.router.params;
|
|
||||||
filters.set("organisationId", organisationId);
|
|
||||||
|
|
||||||
const pagedData = await siteService.getSites(
|
|
||||||
page,
|
|
||||||
pageSize,
|
|
||||||
sortColumn.key,
|
sortColumn.key,
|
||||||
sortColumn.order === "asc",
|
sortColumn.order,
|
||||||
|
updateFiltersWithOrganisationId,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void changePage(initialPagedData.page, initialPagedData.pageSize);
|
||||||
|
}, [changePage, organisationId]);
|
||||||
|
|
||||||
|
const onSort = useCallback(
|
||||||
|
async (nextSortColumn: Column<ReadSite>) => {
|
||||||
|
const { page, pageSize } = pagedData;
|
||||||
|
const nextFilters = updateFiltersWithOrganisationId(filters);
|
||||||
|
const pagedDataResult = await siteService.getSites(
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
nextSortColumn.key,
|
||||||
|
nextSortColumn.order === "asc",
|
||||||
|
nextFilters,
|
||||||
|
);
|
||||||
|
if (pagedDataResult) {
|
||||||
|
setLoaded(true);
|
||||||
|
setFilters(nextFilters);
|
||||||
|
setPagedData(pagedDataResult);
|
||||||
|
setSortColumn(nextSortColumn);
|
||||||
|
} else {
|
||||||
|
setLoaded(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[filters, pagedData, updateFiltersWithOrganisationId],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onSearch = useCallback(
|
||||||
|
async (name: string, value: string) => {
|
||||||
|
const { page, pageSize } = pagedData;
|
||||||
|
const nextFilters = new Map(filters);
|
||||||
|
nextFilters.set(name, value);
|
||||||
|
const updatedFilters = updateFiltersWithOrganisationId(nextFilters);
|
||||||
|
const pagedDataResult = await siteService.getSites(
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
sortColumn.key,
|
||||||
|
sortColumn.order === "asc",
|
||||||
|
updatedFilters,
|
||||||
|
);
|
||||||
|
if (pagedDataResult) {
|
||||||
|
setLoaded(true);
|
||||||
|
setFilters(updatedFilters);
|
||||||
|
setPagedData(pagedDataResult);
|
||||||
|
} else {
|
||||||
|
setLoaded(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[
|
||||||
filters,
|
filters,
|
||||||
);
|
pagedData,
|
||||||
if (pagedData) {
|
|
||||||
this.setState({ loaded: true, pagedData, sortColumn });
|
|
||||||
} else {
|
|
||||||
this.setState({ loaded: false });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onSearch = async (name: string, value: string) => {
|
|
||||||
const { page, pageSize } = this.state.pagedData;
|
|
||||||
const { sortColumn, filters } = this.state;
|
|
||||||
filters.set(name, value);
|
|
||||||
|
|
||||||
const { organisationId } = this.props.router.params;
|
|
||||||
filters.set("organisationId", organisationId);
|
|
||||||
|
|
||||||
const pagedData = await siteService.getSites(
|
|
||||||
page,
|
|
||||||
pageSize,
|
|
||||||
sortColumn.key,
|
sortColumn.key,
|
||||||
sortColumn.order === "asc",
|
sortColumn.order,
|
||||||
filters,
|
updateFiltersWithOrganisationId,
|
||||||
);
|
],
|
||||||
if (pagedData) {
|
);
|
||||||
this.setState({ loaded: true, filters, pagedData });
|
|
||||||
} else {
|
|
||||||
this.setState({ loaded: false });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onDelete = async (item?: ReadSite) => {
|
const onDelete = useCallback(
|
||||||
await siteService.deleteSite(item?.id, item?.guid);
|
async (item?: ReadSite) => {
|
||||||
|
await siteService.deleteSite(item?.id, item?.guid);
|
||||||
|
await changePage(pagedData.page, pagedData.pageSize);
|
||||||
|
},
|
||||||
|
[changePage, pagedData.page, pagedData.pageSize],
|
||||||
|
);
|
||||||
|
|
||||||
this.componentDidMount();
|
const translatedSortColumn = useMemo(
|
||||||
};
|
() => ({ ...sortColumn, label: t("Name") }),
|
||||||
|
[sortColumn, t],
|
||||||
|
);
|
||||||
|
|
||||||
render(): JSX.Element {
|
return (
|
||||||
const { loaded, pagedData, sortColumn } = this.state;
|
<Loading loaded={loaded}>
|
||||||
|
<Permission privilegeKey="AddSite">
|
||||||
return (
|
<div>
|
||||||
<Loading loaded={loaded}>
|
<Button buttonType={ButtonType.primary} to="add">
|
||||||
<Permission privilegeKey="AddSite">
|
{t("Add")}
|
||||||
<div>
|
</Button>
|
||||||
<Button buttonType={ButtonType.primary} to="add">
|
</div>
|
||||||
Add
|
</Permission>
|
||||||
</Button>
|
<hr />
|
||||||
</div>
|
<SitesTable
|
||||||
</Permission>
|
data={pagedData}
|
||||||
<hr />
|
sortColumn={translatedSortColumn}
|
||||||
<SitesTable
|
onChangePage={changePage}
|
||||||
data={pagedData}
|
onSort={onSort}
|
||||||
sortColumn={sortColumn}
|
onSearch={onSearch}
|
||||||
onChangePage={this.changePage}
|
onDelete={onDelete}
|
||||||
onSort={this.onSort}
|
/>
|
||||||
onSearch={this.onSearch}
|
</Loading>
|
||||||
onDelete={this.onDelete}
|
);
|
||||||
/>
|
};
|
||||||
</Loading>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Sites = withRouter(LocSites);
|
|
||||||
|
|
||||||
export default Sites;
|
export default Sites;
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import React, { Component } from "react";
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
import Column from "../../../components/common/columns";
|
import Column from "../../../components/common/columns";
|
||||||
import { Paginated } from "../../../services/Paginated";
|
import { Paginated } from "../../../services/Paginated";
|
||||||
import Button, { ButtonType } from "../../../components/common/Button";
|
import Button, { ButtonType } from "../../../components/common/Button";
|
||||||
import withRouter from "../../../utils/withRouter";
|
|
||||||
import specificationService, {
|
import specificationService, {
|
||||||
ReadSpecification,
|
ReadSpecification,
|
||||||
} from "./services/specificationService";
|
} from "./services/specificationService";
|
||||||
@ -10,122 +11,155 @@ import SpecificationsTable from "./components/SpecificationsTable";
|
|||||||
import Loading from "../../../components/common/Loading";
|
import Loading from "../../../components/common/Loading";
|
||||||
import Permission from "../../../components/common/Permission";
|
import Permission from "../../../components/common/Permission";
|
||||||
|
|
||||||
interface SpecificationsState {
|
const initialPagedData: Paginated<ReadSpecification> = {
|
||||||
loaded: boolean;
|
page: 1,
|
||||||
pagedData: Paginated<ReadSpecification>;
|
pageSize: 10,
|
||||||
sortColumn: Column<ReadSpecification>;
|
count: 0,
|
||||||
filters: Map<string, string>;
|
totalPages: 1,
|
||||||
}
|
data: [],
|
||||||
|
};
|
||||||
|
|
||||||
class LocSpecifications extends Component<any, any, SpecificationsState> {
|
const Specifications: React.FC = () => {
|
||||||
state = {
|
const { t } = useTranslation();
|
||||||
loaded: false,
|
const { siteId } = useParams<{ siteId: string }>();
|
||||||
pagedData: { page: 1, pageSize: 10, count: 0, totalPages: 1, data: [] },
|
|
||||||
sortColumn: { key: "name", label: "Name", order: "asc" },
|
|
||||||
filters: new Map<string, string>(),
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount = async () => {
|
const [loaded, setLoaded] = useState(false);
|
||||||
const { page, pageSize } = this.state.pagedData;
|
const [pagedData, setPagedData] =
|
||||||
await this.changePage(page, pageSize);
|
useState<Paginated<ReadSpecification>>(initialPagedData);
|
||||||
};
|
const [sortColumn, setSortColumn] = useState<Column<ReadSpecification>>({
|
||||||
|
key: "name",
|
||||||
|
label: t("Name"),
|
||||||
|
order: "asc",
|
||||||
|
});
|
||||||
|
const [filters, setFilters] = useState<Map<string, string>>(
|
||||||
|
() => new Map<string, string>(),
|
||||||
|
);
|
||||||
|
|
||||||
changePage = async (page: number, pageSize: number) => {
|
const updateFiltersWithSiteId = useCallback(
|
||||||
const { sortColumn, filters } = this.state;
|
(nextFilters: Map<string, string>) => {
|
||||||
const { siteId } = this.props.router.params;
|
const updatedFilters = new Map(nextFilters);
|
||||||
filters.set("site.id", siteId);
|
if (siteId) {
|
||||||
|
updatedFilters.set("site.id", siteId);
|
||||||
|
}
|
||||||
|
return updatedFilters;
|
||||||
|
},
|
||||||
|
[siteId],
|
||||||
|
);
|
||||||
|
|
||||||
const pagedData = await specificationService.GetSSpecifications(
|
const changePage = useCallback(
|
||||||
page,
|
async (page: number, pageSize: number) => {
|
||||||
pageSize,
|
const nextFilters = updateFiltersWithSiteId(filters);
|
||||||
sortColumn.key,
|
const pagedDataResult = await specificationService.GetSSpecifications(
|
||||||
sortColumn.order === "asc",
|
page,
|
||||||
|
pageSize,
|
||||||
|
sortColumn.key,
|
||||||
|
sortColumn.order === "asc",
|
||||||
|
nextFilters,
|
||||||
|
);
|
||||||
|
if (pagedDataResult) {
|
||||||
|
setLoaded(true);
|
||||||
|
setFilters(nextFilters);
|
||||||
|
setPagedData(pagedDataResult);
|
||||||
|
} else {
|
||||||
|
setLoaded(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[filters, sortColumn.key, sortColumn.order, updateFiltersWithSiteId],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void changePage(initialPagedData.page, initialPagedData.pageSize);
|
||||||
|
}, [changePage, siteId]);
|
||||||
|
|
||||||
|
const onSort = useCallback(
|
||||||
|
async (nextSortColumn: Column<ReadSpecification>) => {
|
||||||
|
const { page, pageSize } = pagedData;
|
||||||
|
const nextFilters = updateFiltersWithSiteId(filters);
|
||||||
|
const pagedDataResult = await specificationService.GetSSpecifications(
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
nextSortColumn.key,
|
||||||
|
nextSortColumn.order === "asc",
|
||||||
|
nextFilters,
|
||||||
|
);
|
||||||
|
if (pagedDataResult) {
|
||||||
|
setLoaded(true);
|
||||||
|
setFilters(nextFilters);
|
||||||
|
setPagedData(pagedDataResult);
|
||||||
|
setSortColumn(nextSortColumn);
|
||||||
|
} else {
|
||||||
|
setLoaded(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[filters, pagedData, updateFiltersWithSiteId],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onSearch = useCallback(
|
||||||
|
async (name: string, value: string) => {
|
||||||
|
const { page, pageSize } = pagedData;
|
||||||
|
const nextFilters = new Map(filters);
|
||||||
|
nextFilters.set(name, value);
|
||||||
|
const updatedFilters = updateFiltersWithSiteId(nextFilters);
|
||||||
|
const pagedDataResult = await specificationService.GetSSpecifications(
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
sortColumn.key,
|
||||||
|
sortColumn.order === "asc",
|
||||||
|
updatedFilters,
|
||||||
|
);
|
||||||
|
if (pagedDataResult) {
|
||||||
|
setLoaded(true);
|
||||||
|
setFilters(updatedFilters);
|
||||||
|
setPagedData(pagedDataResult);
|
||||||
|
} else {
|
||||||
|
setLoaded(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[
|
||||||
filters,
|
filters,
|
||||||
);
|
pagedData,
|
||||||
if (pagedData) {
|
|
||||||
this.setState({ loaded: true, pagedData, filters });
|
|
||||||
} else {
|
|
||||||
this.setState({ loaded: false });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onSort = async (sortColumn: Column<ReadSpecification>) => {
|
|
||||||
const { page, pageSize } = this.state.pagedData;
|
|
||||||
const { filters } = this.state;
|
|
||||||
|
|
||||||
const { siteId } = this.props.router.params;
|
|
||||||
filters.set("site.id", siteId);
|
|
||||||
|
|
||||||
const pagedData = await specificationService.GetSSpecifications(
|
|
||||||
page,
|
|
||||||
pageSize,
|
|
||||||
sortColumn.key,
|
sortColumn.key,
|
||||||
sortColumn.order === "asc",
|
sortColumn.order,
|
||||||
filters,
|
updateFiltersWithSiteId,
|
||||||
);
|
],
|
||||||
if (pagedData) {
|
);
|
||||||
this.setState({ loaded: true, pagedData, sortColumn });
|
|
||||||
} else {
|
|
||||||
this.setState({ loaded: false });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onSearch = async (name: string, value: string) => {
|
const onDelete = useCallback(
|
||||||
const { page, pageSize } = this.state.pagedData;
|
async (item?: ReadSpecification) => {
|
||||||
const { sortColumn, filters } = this.state;
|
const response = await specificationService.DeleteSpecification(
|
||||||
filters.set(name, value);
|
item?.id,
|
||||||
|
item?.guid,
|
||||||
|
);
|
||||||
|
if (response) {
|
||||||
|
await changePage(pagedData.page, pagedData.pageSize);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[changePage, pagedData.page, pagedData.pageSize],
|
||||||
|
);
|
||||||
|
|
||||||
const { siteId } = this.props.router.params;
|
const translatedSortColumn = useMemo(
|
||||||
filters.set("site.id", siteId);
|
() => ({ ...sortColumn, label: t("Name") }),
|
||||||
|
[sortColumn, t],
|
||||||
|
);
|
||||||
|
|
||||||
const pagedData = await specificationService.GetSSpecifications(
|
return (
|
||||||
page,
|
<Loading loaded={loaded}>
|
||||||
pageSize,
|
<Permission privilegeKey="AddSpecification">
|
||||||
sortColumn.key,
|
<Button buttonType={ButtonType.primary} to="add">
|
||||||
sortColumn.order === "asc",
|
{t("Add")}
|
||||||
filters,
|
</Button>
|
||||||
);
|
</Permission>
|
||||||
if (pagedData) {
|
<hr />
|
||||||
this.setState({ loaded: true, filters, pagedData });
|
<SpecificationsTable
|
||||||
} else {
|
data={pagedData}
|
||||||
this.setState({ loaded: false });
|
sortColumn={translatedSortColumn}
|
||||||
}
|
onChangePage={changePage}
|
||||||
};
|
onSort={onSort}
|
||||||
|
onSearch={onSearch}
|
||||||
onDelete = async (item?: ReadSpecification) => {
|
onDelete={onDelete}
|
||||||
const response = await specificationService.DeleteSpecification(
|
/>
|
||||||
item?.id,
|
</Loading>
|
||||||
item?.guid,
|
);
|
||||||
);
|
};
|
||||||
if (response) {
|
|
||||||
this.componentDidMount();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
render(): JSX.Element {
|
|
||||||
const { loaded, pagedData, sortColumn } = this.state;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Loading loaded={loaded}>
|
|
||||||
<Permission privilegeKey="AddSpecification">
|
|
||||||
<Button buttonType={ButtonType.primary} to="add">
|
|
||||||
Add
|
|
||||||
</Button>
|
|
||||||
</Permission>
|
|
||||||
<hr />
|
|
||||||
<SpecificationsTable
|
|
||||||
data={pagedData}
|
|
||||||
sortColumn={sortColumn}
|
|
||||||
onChangePage={this.changePage}
|
|
||||||
onSort={this.onSort}
|
|
||||||
onSearch={this.onSearch}
|
|
||||||
onDelete={this.onDelete}
|
|
||||||
/>
|
|
||||||
</Loading>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Specifications = withRouter(LocSpecifications);
|
|
||||||
|
|
||||||
export default Specifications;
|
export default Specifications;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user