Revert "Migrating the admin_definition.jsx file to typescript (#24658)" (#24869)

This reverts commit a1bf8504a8.
Этот коммит содержится в:
Jesús Espino
2023-10-10 22:33:24 +02:00
коммит произвёл GitHub
родитель 88954c651a
Коммит 6274faeda8
18 изменённых файлов: 7470 добавлений и 7331 удалений

Просмотреть файл

@@ -4,8 +4,8 @@
import React from 'react';
import {Route, Switch, Redirect} from 'react-router-dom';
import type {CloudState} from '@mattermost/types/cloud';
import type {AdminConfig, EnvironmentConfig} from '@mattermost/types/config';
import type {CloudState, Product} from '@mattermost/types/cloud';
import type {AdminConfig, EnvironmentConfig, ClientLicense} from '@mattermost/types/config';
import type {Role} from '@mattermost/types/roles';
import type {DeepPartial} from '@mattermost/types/utilities';
@@ -26,7 +26,6 @@ import {LhsItemType} from 'types/store/lhs';
import AdminSidebar from './admin_sidebar';
import Highlight from './highlight';
import type {AdminDefinitionSubSection, AdminDefinitionSection} from './types';
import type {PropsFromRedux} from './index';
@@ -53,6 +52,22 @@ type ExtraProps = {
isCurrentUserSystemAdmin: boolean;
}
type ConsoleAccess = {
read: Record<string, boolean>;
write: Record<string, boolean>;
}
type Item = {
isHidden?: (config?: Record<string, any>, state?: Record<string, any>, license?: Record<string, any>, buildEnterpriseReady?: boolean, consoleAccess?: ConsoleAccess, cloud?: CloudState, isCurrentUserSystemAdmin?: boolean) => boolean;
isDisabled?: (config?: Record<string, any>, state?: Record<string, any>, license?: Record<string, any>, buildEnterpriseReady?: boolean, consoleAccess?: ConsoleAccess, cloud?: CloudState, isCurrentUserSystemAdmin?: boolean) => boolean;
schema: Record<string, any>;
url: string;
restrictedIndicator?: {
value: (cloud: CloudState) => React.ReactNode;
shouldDisplay: (license: ClientLicense, subscriptionProduct?: Product) => boolean;
};
}
export default class AdminConsole extends React.PureComponent<Props, State> {
public constructor(props: Props) {
super(props);
@@ -101,22 +116,30 @@ export default class AdminConsole extends React.PureComponent<Props, State> {
private renderRoutes = (extraProps: ExtraProps) => {
const {adminDefinition, config, license, buildEnterpriseReady, consoleAccess, cloud, isCurrentUserSystemAdmin} = this.props;
const schemas: AdminDefinitionSubSection[] = Object.values(adminDefinition).flatMap((section: AdminDefinitionSection) => {
const schemas: Item[] = Object.values(adminDefinition).reduce((acc, section) => {
let items: Item[] = [];
let isSectionHidden = false;
if (typeof section.isHidden === 'function') {
isSectionHidden = section.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud, isCurrentUserSystemAdmin);
} else {
isSectionHidden = Boolean(section.isHidden);
Object.entries(section).find(([key, value]) => {
if (key === 'isHidden') {
if (typeof value === 'function') {
isSectionHidden = value(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud, isCurrentUserSystemAdmin);
} else {
isSectionHidden = Boolean(value);
}
}
return null;
});
if (!isSectionHidden) {
items = Object.values(section).filter((item: Item) => Boolean(item.schema));
}
if (isSectionHidden) {
return [];
}
return Object.values(section.subsections);
});
return acc.concat(items);
}, [] as Item[]);
let defaultUrl = '';
const schemaRoutes = schemas.map((item: AdminDefinitionSubSection, index: number) => {
const schemaRoutes = schemas.map((item: Item, index: number) => {
if (typeof item.isHidden !== 'undefined') {
const isHidden = (typeof item.isHidden === 'function') ? item.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud, isCurrentUserSystemAdmin) : Boolean(item.isHidden);
if (isHidden) {