Skip to content

Commit

Permalink
Address previous PR comments and implement rudimentary delete
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <dxho@amazon.com>
  • Loading branch information
derek-ho committed Sep 18, 2023
1 parent 28201e9 commit 108c172
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export const DataConnection = (props: any) => {
})
)
.catch((err) => {
if (err.body.statusCode === 403) {
setHasAccess(false);
}
setHasAccess(false);
});
}, [chrome, http]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { DataConnectionsHeader } from './data_connections_header';
import { HomeProps } from '../home';
import { DataConnectionsDescription } from './manage_data_connections_description';
import { ChromeStart } from '../../../../../../src/core/public';
import { DATACONNECTIONS_BASE } from '../../../../common/constants/shared';
import { useToast } from '../../../../public/components/common/toast';

interface DataConnection {
connectionType: 'OPENSEARCH' | 'SPARK';
Expand All @@ -31,8 +33,18 @@ interface DataConnection {
export const ManageDataConnectionsTable = (props: HomeProps) => {
const { http, chrome, pplService } = props;

const { setToast } = useToast();

const [data, setData] = useState([]);
const [hasAccess, setHasAccess] = useState(true);

const deleteConnection = (connection: string) => {
http!
.delete(`${DATACONNECTIONS_BASE}/${connection}`)
.then(() => setToast(`Data connection ${connection} deleted successfully`))
.catch((err) => {
setToast(`Data connection $${connection} not deleted. See output for more details.`);
});
};

useEffect(() => {
chrome.setBreadcrumbs([
Expand Down Expand Up @@ -83,17 +95,6 @@ export const ManageDataConnectionsTable = (props: HomeProps) => {
</EuiFlexGroup>
),
},
{
field: 'connectionStatus',
name: 'Connection Status',
sortable: true,
truncateText: true,
render: (value, record) => (
<EuiText data-test-subj={`${record.templateName}DataConnectionHealth`}>
{_.truncate(record.creationDate, { length: 100 })}
</EuiText>
),
},
{
field: 'actions',
name: 'Actions',
Expand All @@ -103,7 +104,7 @@ export const ManageDataConnectionsTable = (props: HomeProps) => {
<EuiIcon
type={'trash'}
onClick={() => {
/* Delete Datasource*/
deleteConnection(record.name);
}}
/>
),
Expand Down
4 changes: 2 additions & 2 deletions public/components/data_connections/components/no_access.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export const NoAccess = () => {
<EuiPage>
<EuiEmptyPrompt
iconType="alert"
title={<h2>{'No permissions to access'}</h2>}
title={<h2>{'No permissions to access or resource does not exist'}</h2>}
body={
<EuiText>
{
'Missing permissions to view connection details. Contact your administrator for permissions.'
'This connection does not exist or you are missing permissions to view connection details. Contact your administrator for permissions.'
}
</EuiText>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { PermissionsConfigurationProps } from '../../../../common/types/data_con
export const QueryPermissionsConfiguration = (props: PermissionsConfigurationProps) => {
const { roles, selectedRoles, setSelectedRoles } = props;

const [selectedRadio, setSelectedRadio] = useState(
const [selectedAccessLevel, setSelectedAccessLevel] = useState(
selectedRoles.length ? QUERY_RESTRICTED : QUERY_ALL
);
const radios = [
const accessLevelOptions = [
{
id: QUERY_RESTRICTED,
label: 'Restricted - accessible by users with specific OpenSearch roles',
Expand Down Expand Up @@ -71,15 +71,15 @@ export const QueryPermissionsConfiguration = (props: PermissionsConfigurationPro
</EuiFlexItem>
<EuiFlexItem>
<EuiRadioGroup
options={radios}
idSelected={selectedRadio}
onChange={(id) => setSelectedRadio(id)}
options={accessLevelOptions}
idSelected={selectedAccessLevel}
onChange={(id) => setSelectedAccessLevel(id)}
name="query-radio-group"
legend={{
children: <span>Access level</span>,
}}
/>
{selectedRadio === QUERY_RESTRICTED && <ConfigureRoles />}
{selectedAccessLevel === QUERY_RESTRICTED && <ConfigureRoles />}
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
13 changes: 13 additions & 0 deletions server/adaptors/ppl_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ export const PPLPlugin = function (Client, config, components) {
method: 'GET',
});

ppl.deleteDataConnection = ca({
url: {
fmt: `${OPENSEARCH_DATACONNECTIONS_API.DATACONNECTION}/<%=dataconnection%>`,
req: {
dataconnection: {
type: 'string',
required: true,
},
},
},
method: 'DELETE',
});

ppl.modifyDataConnection = ca({
url: {
fmt: `${OPENSEARCH_DATACONNECTIONS_API.DATACONNECTION}`,
Expand Down
29 changes: 29 additions & 0 deletions server/routes/data_connections/data_connections_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ export function registerDataConnectionsRoute(router: IRouter) {
}
);

router.delete(
{
path: `${DATACONNECTIONS_BASE}/{name}`,
validate: {
params: schema.object({
name: schema.string(),
}),
},
},
async (context, request, response): Promise<any> => {
try {
const dataConnectionsresponse = await context.observability_plugin.observabilityClient
.asScoped(request)
.callAsCurrentUser('ppl.deleteDataConnection', {
dataconnection: request.params.name,
});
return response.ok({
body: dataConnectionsresponse,
});
} catch (error: any) {
console.error('Issue in deleting data connection:', error);
return response.custom({
statusCode: error.statusCode || 500,
body: error.message,
});
}
}
);

router.put(
{
path: `${DATACONNECTIONS_BASE}`,
Expand Down

0 comments on commit 108c172

Please sign in to comment.