Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an issue when loading unknown datasource causes page to crash #1947

Closed
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2a2d757
Adds a separate handler for unknown datasource
DarshitChanpura May 9, 2024
9d6aa1d
Fixes linter errors
DarshitChanpura May 9, 2024
60d9910
Merge branch 'main' into unknown-ds-fix
DarshitChanpura May 9, 2024
a45e592
Merge remote-tracking branch 'upstream/main' into unknown-ds-fix
DarshitChanpura May 10, 2024
2775a8c
Changes button text
DarshitChanpura May 10, 2024
3e05fc4
Remove button and adds text to keep better user experience
DarshitChanpura May 10, 2024
ad30c1d
Adds @opensearch-project/oui dependency
DarshitChanpura May 10, 2024
891e1bf
Removes @opensearch-project/oui dependency due to compilation failures
DarshitChanpura May 11, 2024
62f28a9
Fixes unit tests
DarshitChanpura May 11, 2024
e6321b8
Fixes remainder unit tests
DarshitChanpura May 11, 2024
2b37fa5
Adds unit tests to expand code coverage
DarshitChanpura May 11, 2024
7a26e9f
Adds couple more unit tests
DarshitChanpura May 11, 2024
05d8d55
Merge branch 'main' into unknown-ds-fix
DarshitChanpura May 13, 2024
6e8284d
Fixes a call to dataSource id causing test failures
DarshitChanpura May 13, 2024
7d3193c
Merge remote-tracking branch 'origin/unknown-ds-fix' into unknown-ds-fix
DarshitChanpura May 13, 2024
ac06227
Merge branch 'main' into unknown-ds-fix
DarshitChanpura May 15, 2024
76880f8
Removes console logs
DarshitChanpura May 17, 2024
1e314a7
Merge remote-tracking branch 'origin/unknown-ds-fix' into unknown-ds-fix
DarshitChanpura May 17, 2024
a5b09ee
Merge branch 'main' into unknown-ds-fix
DarshitChanpura May 20, 2024
773087f
Fixes unit test broken due to recent commit @a202d48 in main
DarshitChanpura May 21, 2024
86c0b27
Merge remote-tracking branch 'upstream/main' into unknown-ds-fix
DarshitChanpura Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"@hapi/cryptiles": "5.0.0",
"@hapi/wreck": "^17.1.0",
"@opensearch-project/oui": "^1.6.0",
DarshitChanpura marked this conversation as resolved.
Show resolved Hide resolved
"html-entities": "1.3.1",
"zxcvbn": "^4.4.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { setCrossPageToast } from '../../utils/storage-utils';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { DataSourceContext } from '../../app-router';
import { getClusterInfo } from '../../../../utils/datasource-utils';
import { UnknownDataSourcePage } from '../../unknown-datasource';

interface AuditLoggingEditSettingProps extends AppDependencies {
setting: 'general' | 'compliance';
Expand Down Expand Up @@ -76,7 +77,7 @@ export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) {
};

fetchConfig();
}, [props.coreStart.http, dataSource.id]);
}, [props.coreStart.http, dataSource]);
DarshitChanpura marked this conversation as resolved.
Show resolved Hide resolved

const renderSaveAndCancel = () => {
return (
Expand Down Expand Up @@ -248,6 +249,10 @@ export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) {
content = renderComplianceSetting();
}

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}

return (
<div className="panel-restrict-width">
<SecurityPluginTopNavMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ViewSettingGroup } from './view-setting-group';
import { DocLinks } from '../../constants';
import { DataSourceContext } from '../../app-router';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { UnknownDataSourcePage } from '../../unknown-datasource';

interface AuditLoggingProps extends AppDependencies {
fromType: string;
Expand Down Expand Up @@ -135,6 +136,7 @@ export function renderComplianceSettings(config: AuditLoggingSettings) {
}

export function AuditLogging(props: AuditLoggingProps) {
const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled;
const [configuration, setConfiguration] = React.useState<AuditLoggingSettings>({});
const { dataSource, setDataSource } = useContext(DataSourceContext)!;

Expand Down Expand Up @@ -163,7 +165,7 @@ export function AuditLogging(props: AuditLoggingProps) {
};

fetchData();
}, [props.coreStart.http, props.fromType, dataSource.id]);
}, [props.coreStart.http, props.fromType, dataSource]);

const statusPanel = renderStatusPanel(onSwitchChange, configuration.enabled || false);

Expand Down Expand Up @@ -229,6 +231,10 @@ export function AuditLogging(props: AuditLoggingProps) {
);
}

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}

return (
<div className="panel-restrict-width">
<SecurityPluginTopNavMenu
Expand Down
14 changes: 13 additions & 1 deletion public/apps/configuration/panels/auth-view/auth-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import { getSecurityConfig } from '../../utils/auth-view-utils';
import { InstructionView } from './instruction-view';
import { DataSourceContext } from '../../app-router';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { UnknownDataSourcePage } from '../../unknown-datasource';

export function AuthView(props: AppDependencies) {
const [authentication, setAuthentication] = React.useState([]);
const [authorization, setAuthorization] = React.useState([]);
const [loading, setLoading] = useState(false);
const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled;
const { dataSource, setDataSource } = useContext(DataSourceContext)!;

React.useEffect(() => {
Expand All @@ -48,9 +50,16 @@ export function AuthView(props: AppDependencies) {
};

fetchData();
}, [props.coreStart.http, dataSource.id]);
}, [props.coreStart.http, dataSource]);

if (isEmpty(authentication)) {
if (dataSourceEnabled && dataSource === undefined) {
return (
<>
<UnknownDataSourcePage {...props} />
</>
);
}
return (
<>
<SecurityPluginTopNavMenu
Expand All @@ -64,6 +73,9 @@ export function AuthView(props: AppDependencies) {
);
}

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}
return (
<>
<SecurityPluginTopNavMenu
Expand Down
4 changes: 4 additions & 0 deletions public/apps/configuration/panels/get-started.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { createSuccessToast, createUnknownErrorToast, useToastState } from '../u
import { SecurityPluginTopNavMenu } from '../top-nav-menu';
import { DataSourceContext } from '../app-router';
import { getClusterInfo } from '../../../utils/datasource-utils';
import { UnknownDataSourcePage } from '../unknown-datasource';

const addBackendStep = {
title: 'Add backends',
Expand Down Expand Up @@ -173,6 +174,9 @@ export function GetStarted(props: AppDependencies) {
}
const [toasts, addToast, removeToast] = useToastState();

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}
return (
<>
<div className="panel-restrict-width">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { constructErrorMessageAndLog } from '../../../error-utils';
import { BackendRolePanel } from './backend-role-panel';
import { DataSourceContext } from '../../app-router';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { UnknownDataSourcePage } from '../../unknown-datasource';

interface InternalUserEditDeps extends BreadcrumbsPageDependencies {
action: 'create' | 'edit' | 'duplicate';
Expand Down Expand Up @@ -98,7 +99,7 @@ export function InternalUserEdit(props: InternalUserEditDeps) {

fetchData();
}
}, [addToast, props.action, props.coreStart.http, props.sourceUserName, dataSource.id]);
}, [addToast, props.action, props.coreStart.http, props.sourceUserName, dataSource]);

const updateUserHandler = async () => {
try {
Expand Down Expand Up @@ -147,6 +148,10 @@ export function InternalUserEdit(props: InternalUserEditDeps) {
}
};

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { generateResourceName } from '../../utils/resource-utils';
import { DocLinks } from '../../constants';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { DataSourceContext } from '../../app-router';
import { UnknownDataSourcePage } from '../../unknown-datasource';

export function renderBooleanToCheckMark(value: boolean): React.ReactNode {
return value ? <EuiIcon type="check" /> : '';
Expand Down Expand Up @@ -216,11 +217,11 @@ export function PermissionList(props: AppDependencies) {
} finally {
setLoading(false);
}
}, [props.coreStart.http, dataSource.id]);
}, [props.coreStart.http, dataSource]);

React.useEffect(() => {
fetchData();
}, [props.coreStart.http, fetchData, dataSource.id]);
}, [props.coreStart.http, fetchData, dataSource]);

const handleDelete = async () => {
const groupsToDelete: string[] = selection.map((r) => r.name);
Expand Down Expand Up @@ -348,6 +349,10 @@ export function PermissionList(props: AppDependencies) {
createActionGroupMenuItems
);

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down
11 changes: 8 additions & 3 deletions public/apps/configuration/panels/role-edit/role-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { generateResourceName } from '../../utils/resource-utils';
import { NameRow } from '../../utils/name-row';
import { DataSourceContext } from '../../app-router';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { UnknownDataSourcePage } from '../../unknown-datasource';

interface RoleEditDeps extends BreadcrumbsPageDependencies {
action: 'create' | 'edit' | 'duplicate';
Expand Down Expand Up @@ -114,7 +115,7 @@ export function RoleEdit(props: RoleEditDeps) {

fetchData();
}
}, [addToast, props.action, props.coreStart.http, props.sourceRoleName, dataSource.id]);
}, [addToast, props.action, props.coreStart.http, props.sourceRoleName, dataSource]);

const [actionGroups, setActionGroups] = useState<Array<[string, ActionGroupItem]>>([]);
React.useEffect(() => {
Expand All @@ -129,7 +130,7 @@ export function RoleEdit(props: RoleEditDeps) {
};

fetchActionGroupNames();
}, [addToast, props.coreStart.http, dataSource.id]);
}, [addToast, props.coreStart.http, dataSource]);

const [tenantNames, setTenantNames] = React.useState<string[]>([]);
React.useEffect(() => {
Expand All @@ -143,7 +144,7 @@ export function RoleEdit(props: RoleEditDeps) {
};

fetchTenantNames();
}, [addToast, props.coreStart.http, dataSource.id]);
}, [addToast, props.coreStart.http, dataSource]);

const updateRoleHandler = async () => {
try {
Expand Down Expand Up @@ -233,6 +234,10 @@ export function RoleEdit(props: RoleEditDeps) {

const tenantOptions = tenantNames.map(stringToComboBoxOption);

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down
12 changes: 11 additions & 1 deletion public/apps/configuration/panels/role-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { useContextMenuState } from '../utils/context-menu';
import { DocLinks } from '../constants';
import { DataSourceContext } from '../app-router';
import { SecurityPluginTopNavMenu } from '../top-nav-menu';
import { UnknownDataSourcePage } from '../unknown-datasource';

const columns: Array<EuiBasicTableColumn<RoleListing>> = [
{
Expand Down Expand Up @@ -103,6 +104,7 @@ const columns: Array<EuiBasicTableColumn<RoleListing>> = [
];

export function RoleList(props: AppDependencies) {
const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled;
const [roleData, setRoleData] = React.useState<RoleListing[]>([]);
const [errorFlag, setErrorFlag] = React.useState(false);
const [selection, setSelection] = React.useState<RoleListing[]>([]);
Expand All @@ -127,7 +129,7 @@ export function RoleList(props: AppDependencies) {
};

fetchData();
}, [props.coreStart.http, dataSource.id]);
}, [props.coreStart.http, dataSource]);

const handleDelete = async () => {
const rolesToDelete: string[] = selection.map((r) => r.roleName);
Expand Down Expand Up @@ -252,6 +254,14 @@ export function RoleList(props: AppDependencies) {
});
}, [roleData]);

if (dataSourceEnabled && dataSource === undefined) {
return (
<>
<UnknownDataSourcePage {...props} />
</>
);
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { ExternalLink } from '../../utils/display-utils';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { DataSourceContext } from '../../app-router';
import { getClusterInfo } from '../../../../utils/datasource-utils';
import { UnknownDataSourcePage } from '../../unknown-datasource';

interface RoleEditMappedUserProps extends BreadcrumbsPageDependencies {
roleName: string;
Expand Down Expand Up @@ -86,7 +87,7 @@ export function RoleEditMappedUser(props: RoleEditMappedUserProps) {
};

fetchData();
}, [addToast, props.coreStart.http, props.roleName, dataSource.id]);
}, [addToast, props.coreStart.http, props.roleName, dataSource]);

React.useEffect(() => {
const fetchInternalUserNames = async () => {
Expand All @@ -101,7 +102,7 @@ export function RoleEditMappedUser(props: RoleEditMappedUserProps) {
};

fetchInternalUserNames();
}, [addToast, props.coreStart.http, dataSource.id]);
}, [addToast, props.coreStart.http, dataSource]);
const internalUserOptions = userNames.map(stringToComboBoxOption);

const updateRoleMappingHandler = async () => {
Expand Down Expand Up @@ -144,6 +145,10 @@ export function RoleEditMappedUser(props: RoleEditMappedUserProps) {
}
};

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down
7 changes: 6 additions & 1 deletion public/apps/configuration/panels/role-view/role-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { setCrossPageToast } from '../../utils/storage-utils';
import { DataSourceContext } from '../../app-router';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { getClusterInfo } from '../../../../utils/datasource-utils';
import { UnknownDataSourcePage } from '../../unknown-datasource';

interface RoleViewProps extends BreadcrumbsPageDependencies {
roleName: string;
Expand Down Expand Up @@ -147,7 +148,7 @@ export function RoleView(props: RoleViewProps) {
};

fetchData();
}, [addToast, props.coreStart.http, props.roleName, props.prevAction, dataSource.id]);
}, [addToast, props.coreStart.http, props.roleName, props.prevAction, dataSource]);

const handleRoleMappingDelete = async () => {
try {
Expand Down Expand Up @@ -391,6 +392,10 @@ export function RoleView(props: RoleViewProps) {
);
}

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down
8 changes: 7 additions & 1 deletion public/apps/configuration/panels/user-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { showTableStatusMessage } from '../utils/loading-spinner-utils';
import { buildHashUrl } from '../utils/url-builder';
import { DataSourceContext } from '../app-router';
import { SecurityPluginTopNavMenu } from '../top-nav-menu';
import { UnknownDataSourcePage } from '../unknown-datasource';

export function dictView(items: Dictionary<string>) {
if (isEmpty(items)) {
Expand Down Expand Up @@ -99,6 +100,7 @@ export function getColumns(currentUsername: string) {
}

export function UserList(props: AppDependencies) {
const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled;
const [userData, setUserData] = React.useState<InternalUsersListing[]>([]);
const [errorFlag, setErrorFlag] = React.useState(false);
const [selection, setSelection] = React.useState<InternalUsersListing[]>([]);
Expand Down Expand Up @@ -128,7 +130,7 @@ export function UserList(props: AppDependencies) {
};

fetchData();
}, [props.coreStart.http, dataSource.id]);
}, [props.coreStart.http, dataSource]);

const handleDelete = async () => {
const usersToDelete: string[] = selection.map((r) => r.username);
Expand Down Expand Up @@ -200,6 +202,10 @@ export function UserList(props: AppDependencies) {

const [actionsMenu, closeActionsMenu] = useContextMenuState('Actions', {}, actionsMenuItems);

if (dataSourceEnabled && dataSource === undefined) {
return <UnknownDataSourcePage {...props} />;
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down
Loading
Loading