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

[Feature] Data sources associated objects tab #1470

Merged
merged 8 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export interface PermissionsConfigurationProps {
hasSecurityAccess: boolean;
}

export interface AssociatedObject {
id: string;
name: string;
database: string;
type: string;
createdByIntegration: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if createdByIntegration is a field that AssociatedObject would contain, I'd expect this to be queried from the integrations that store all the contained object information. Do you see us modifying Integrations to add fields like this to arbitrary objects? If so, it might be worth adding this requirement in #1442

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transferring some of the discussion over here: for now, since we should able to have this field with the source of integration, lets have this field for now for this skeleton PR. We can sync up on this again when we actually do the connection of actual data content.

accelerations: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would any of these fields be a smaller type than string, or all of them can be arbitrary strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now they should be all strings.

}

export type Role = EuiComboBoxOptionOption;

export type DatasourceType = 'S3GLUE' | 'PROMETHEUS';
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,48 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
Connection configuration
</span>
</button>
<button
aria-controls="random_html_id"
aria-selected="false"
class="euiTab"
id="associated_objects"
role="tab"
type="button"
>
<span
class="euiTab__content"
>
Associated Objects
</span>
</button>
<button
aria-controls="random_html_id"
aria-selected="false"
class="euiTab"
id="accelerations"
role="tab"
type="button"
>
<span
class="euiTab__content"
>
Accelerations
</span>
</button>
<button
aria-controls="random_html_id"
aria-selected="false"
class="euiTab"
id="installed_integrations"
role="tab"
type="button"
>
<span
class="euiTab__content"
>
Installed integrations
</span>
</button>
</div>
<div
aria-labelledby="access_control"
Expand Down Expand Up @@ -782,6 +824,48 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
Connection configuration
</span>
</button>
<button
aria-controls="random_html_id"
aria-selected="false"
class="euiTab"
id="associated_objects"
role="tab"
type="button"
>
<span
class="euiTab__content"
>
Associated Objects
</span>
</button>
<button
aria-controls="random_html_id"
aria-selected="false"
class="euiTab"
id="accelerations"
role="tab"
type="button"
>
<span
class="euiTab__content"
>
Accelerations
</span>
</button>
<button
aria-controls="random_html_id"
aria-selected="false"
class="euiTab"
id="installed_integrations"
role="tab"
type="button"
>
<span
class="euiTab__content"
>
Installed integrations
</span>
</button>
</div>
<div
aria-labelledby="access_control"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiCallOut } from '@elastic/eui';
import React from 'react';

export const AccelerationsRecommendationCallout = () => {
return (

Check warning on line 10 in public/components/datasources/components/manage/accelerations_recommendation_callout.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations_recommendation_callout.tsx#L10

Added line #L10 was not covered by tests
<EuiCallOut
title="Accelerations recommended for tables. Setup acceleration or configure integrations"
iconType="iInCircle"
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect, useState } from 'react';
import {
EuiInMemoryTable,
EuiLink,
EuiPanel,
EuiFlexGroup,
EuiFlexItem,
EuiText,
EuiHorizontalRule,
EuiButton,
EuiSpacer,
EuiEmptyPrompt,
} from '@elastic/eui';
import { AssociatedObject } from 'common/types/data_connections';
import { AccelerationsRecommendationCallout } from './accelerations_recommendation_callout';

interface AssociatedObjectsTabProps {
associatedObjects: AssociatedObject[];
}

export const AssociatedObjectsTab: React.FC<AssociatedObjectsTabProps> = ({
associatedObjects,
}) => {
const [lastUpdated, setLastUpdated] = useState('');

Check warning on line 29 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L28-L29

Added lines #L28 - L29 were not covered by tests

// TODO: FINISH THE REFRESH LOGIC
const fetchAssociatedObjects = async () => {

Check warning on line 32 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L32

Added line #L32 was not covered by tests
// Placeholder for data fetching logic
// After fetching data:
// setAssociatedObjects(fetchedData);
const now = new Date();
setLastUpdated(now.toUTCString()); // Update last updated time

Check warning on line 37 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L36-L37

Added lines #L36 - L37 were not covered by tests
};

useEffect(() => {
fetchAssociatedObjects();

Check warning on line 41 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L40-L41

Added lines #L40 - L41 were not covered by tests
}, []);

const AssociatedObjectsHeader = () => {
return (

Check warning on line 45 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L44-L45

Added lines #L44 - L45 were not covered by tests
<EuiFlexGroup direction="row">
<EuiFlexItem>
<EuiText size="m">
<h2 className="panel-title">Associated objects</h2>
Manage objects associated with this data sources.
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<div style={{ textAlign: 'right' }}>
<EuiText color="subdued" style={{ fontSize: 'small' }}>
Last updated at:
</EuiText>
<EuiText color="subdued" style={{ fontSize: 'small' }}>
{lastUpdated}
</EuiText>
</div>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="freshButton"
iconType="refresh"
onClick={fetchAssociatedObjects}
>
Refresh
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
);
};

const noDataMessage = (
<EuiEmptyPrompt

Check warning on line 77 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L77

Added line #L77 was not covered by tests
title={<h2>You have no associated objects</h2>}
body={<p>Add or config tables from your data source or use Query Workbench.</p>}
actions={
<EuiButton
color="primary"
fill
onClick={() => window.open('https://example.com', '_blank')}

Check warning on line 84 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L84

Added line #L84 was not covered by tests
iconType="popout"
iconSide="left"
>
Query Workbench
</EuiButton>
}
/>
);

const columns = [

Check warning on line 94 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L94

Added line #L94 was not covered by tests
{
field: 'name',
name: 'Name',
sortable: true,
'data-test-subj': 'nameCell',
render: (name: string) => (
<EuiLink href="https://example.com" target="_blank">

Check warning on line 101 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L101

Added line #L101 was not covered by tests
{name}
</EuiLink>
),
},
{
field: 'database',
name: 'Database',
truncateText: true,
render: (database: string) => (
<EuiLink href="https://example.com" target="_blank">

Check warning on line 111 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L111

Added line #L111 was not covered by tests
{database}
</EuiLink>
),
},
{
field: 'type',
name: 'Type',
sortable: true,
},
{
field: 'createdByIntegration',
name: 'Created by Integration',
sortable: true,
},
{
field: 'accelerations',
name: 'Accelerations',
sortable: true,
},
{
name: 'Actions',
actions: [
{
name: 'Edit',
description: 'Edit this object',
type: 'icon',
icon: 'discoverApp',
onClick: (item: AssociatedObject) => console.log('Edit', item),

Check warning on line 139 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L139

Added line #L139 was not covered by tests
},
{
name: 'Delete',
description: 'Delete this object',
type: 'icon',
icon: 'bolt',
onClick: (item: AssociatedObject) => console.log('Delete', item),

Check warning on line 146 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L146

Added line #L146 was not covered by tests
},
],
},
];

const search = {

Check warning on line 152 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L152

Added line #L152 was not covered by tests
box: {
incremental: true,
schema: {
fields: { name: { type: 'string' }, database: { type: 'string' } },
},
},
};

const pagination = {

Check warning on line 161 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L161

Added line #L161 was not covered by tests
initialPageSize: 10,
pageSizeOptions: [10, 25, 50],
};

const sorting = {

Check warning on line 166 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L166

Added line #L166 was not covered by tests
sort: {
field: 'name',
direction: 'asc',
},
};

return (

Check warning on line 173 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L173

Added line #L173 was not covered by tests
<>
<EuiSpacer />
<EuiPanel>
<AssociatedObjectsHeader />
<EuiHorizontalRule />
<AccelerationsRecommendationCallout />
<EuiSpacer />
{associatedObjects.length > 0 ? (
<EuiInMemoryTable

Check warning on line 182 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L182

Added line #L182 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would there be a case that associatedObjects gets large and doesn't fit in memory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I think for the memory fitting issue, we may need to do something like virtualization with react-window to limit the size of the list. However, since this this is a skeleton for now, and lets just leave like this. I will test it when we connect the actual data content, so that we can decide which approaches we need for addressing the memory issue. I will not resolve this comment btw until we have a concrete solution on this.

items={associatedObjects}
columns={columns}
search={search}
pagination={pagination}
sorting={sorting}
noItemsMessage={associatedObjects.length === 0 ? noDataMessage : undefined}
/>
) : (
noDataMessage

Check warning on line 191 in public/components/datasources/components/manage/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects_tab.tsx#L191

Added line #L191 was not covered by tests
)}
</EuiPanel>
<EuiSpacer />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import { ConnectionDetails } from './connection_details';
import { DatasourceType } from '../../../../../common/types/data_connections';
import { DatasourceTypeToDisplayName } from '../../../../../common/constants/data_connections';
import { AssociatedObjectsTab } from './associated_objects_tab';

interface DatasourceDetails {
allowedRoles: string[];
Expand All @@ -51,7 +52,7 @@
'prometheus.uri': string;
}

export const DataConnection = (props: any) => {

Check warning on line 55 in public/components/datasources/components/manage/data_connection.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const { dataSource } = props;
const [datasourceDetails, setDatasourceDetails] = useState<DatasourceDetails>({
allowedRoles: [],
Expand Down Expand Up @@ -132,10 +133,10 @@
properties: data.properties,
});
})
.catch((err) => {
.catch((_err) => {

Check warning on line 136 in public/components/datasources/components/manage/data_connection.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/data_connection.tsx#L136

Added line #L136 was not covered by tests
setHasAccess(false);
});
}, [chrome, http]);

Check warning on line 139 in public/components/datasources/components/manage/data_connection.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'dataSource'. Either include it or remove the dependency array

const tabs = [
{
Expand Down Expand Up @@ -165,6 +166,37 @@
/>
),
},
{
id: 'associated_objects',
name: 'Associated Objects',
disabled: false,
content: (
<AssociatedObjectsTab
associatedObjects={
[
// {
// id: '1',
// name: 'Table_name_1',
// database: 'db1',
// type: 'Table',
// createdByIntegration: 'xx',
// accelerations: 'xxx_skipping',
// },
]
}
/>
),
},
{
id: 'accelerations',
name: 'Accelerations',
disabled: false,
},
{
id: 'installed_integrations',
name: 'Installed integrations',
disabled: false,
},
];

const QueryOrAccelerateData = () => {
Expand Down
Loading