Skip to content

Commit

Permalink
Updated to include individual artifact commands, such as refresh/upda…
Browse files Browse the repository at this point in the history
…te and validate that the artifact is on disk.
  • Loading branch information
linus-berg committed Feb 26, 2024
1 parent d397857 commit fffa49b
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 38 deletions.
39 changes: 33 additions & 6 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions src/api/apc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export const APC_API =
window.location.protocol + '//' + window.location.hostname + ':8004/api';
const APC_ARTIFACTS = '/artifact';
const APC_PROCESSOR = '/processor';
/* Delete */
const DeleteArtifactUrl = (processor: string) =>
`${APC_ARTIFACTS}/${processor}/`;

const axios_ctx = createContext<AxiosInstance>({} as AxiosInstance);

Expand Down Expand Up @@ -64,13 +61,28 @@ export const useApcApi = () => {
};

const DeleteArtifact = ({ id, processor }) => {
return APC.delete(DeleteArtifactUrl(processor), {
return APC.delete(APC_ARTIFACTS, {
data: {
id: id,
processor: processor,
},
});
};

const TrackArtifact = ({ id, processor }) => {
return APC.post(APC_ARTIFACTS + '/track', {
id: id,
processor: processor,
});
};

const ValidateArtifact = ({ id, processor }) => {
return APC.post(APC_ARTIFACTS + '/validate', {
id: id,
processor: processor,
});
};

/* Add */
const AddArtifact = (artifact: Artifact) => {
return APC.post(APC_ARTIFACTS, {
Expand Down Expand Up @@ -109,9 +121,11 @@ export const useApcApi = () => {
UpdateProcessor,
AddArtifact,
TrackAllArtifacts,
TrackArtifact,
DeleteArtifact,
GetAllProcessors,
GetAllProcessorArtifacts,
ValidateAllArtifacts,
ValidateArtifact,
};
};
3 changes: 0 additions & 3 deletions src/app/components/ArtifactTable/InspectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
*
*/
import { Button } from '@blueprintjs/core';
import { useMutation } from '@tanstack/react-query';
import { useApcApi } from 'api/apc';
import React, { memo } from 'react';
import { useKeycloak } from '@react-keycloak-fork/web';
import { Artifact } from 'types';

interface Props {
Expand Down
33 changes: 8 additions & 25 deletions src/app/components/ArtifactTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* ArtifactTable
*
*/
import { ButtonGroup, Button, Checkbox, Spinner, Tag } from '@blueprintjs/core';
import { Button, ButtonGroup, Checkbox, Spinner, Tag } from '@blueprintjs/core';
import _ from 'lodash';
import { Column, Cell, Table2 } from '@blueprintjs/table';
import { Cell, Column, Table2 } from '@blueprintjs/table';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useApcApi } from 'api/apc';
import React, { memo, useState } from 'react';
Expand All @@ -19,6 +19,9 @@ import { InspectButton } from './InspectButton';
import { ArtifactInspector } from 'app/components/ArtifactInspector';
import { AxiosResponse } from 'axios';
import { SearchBar } from './SearchBar';
import { TrackArtifactButton } from '../TrackArtifactButton/Loadable';
import { ValidateArtifactButton } from '../ValidateArtifactButton/Loadable';
import { DeleteArtifactButton } from '../DeleteArtifactButton/Loadable';

interface Props {
processor: Processor;
Expand Down Expand Up @@ -60,8 +63,6 @@ const FilterArtifacts = (

export const ArtifactTable = memo((props: Props) => {
const apc = useApcApi();
const { keycloak } = useKeycloak();
const query_client = useQueryClient();
const [only_roots, SetOnlyRoots] = useState(true);
const [deep_filter, SetDeepFilter] = useState(false);
const [inspect, SetInspect] = useState<null | Artifact>(null);
Expand All @@ -71,16 +72,6 @@ export const ArtifactTable = memo((props: Props) => {
apc.GetAllProcessorArtifacts,
);

const mutation = useMutation({
mutationFn: apc.DeleteArtifact,
onSuccess: (data: AxiosResponse<Artifact>) => {
const artifact = data.data;
query_client.invalidateQueries({
queryKey: ['artifact_table', artifact.processor, true],
});
},
});

if (query.isLoading) {
return <Spinner />;
}
Expand Down Expand Up @@ -132,17 +123,9 @@ export const ArtifactTable = memo((props: Props) => {
<Center>
<ButtonGroup>
<InspectButton artifact={row} onInspect={SetInspect} />
<Button
intent="danger"
disabled={!keycloak.hasResourceRole('Administrator')}
onClick={() =>
mutation.mutate({ id: row.id, processor: row.processor })
}
loading={mutation.isLoading}
small
>
Delete
</Button>
<TrackArtifactButton id={row.id} processor={row.processor} />
<ValidateArtifactButton id={row.id} processor={row.processor} />
<DeleteArtifactButton id={row.id} processor={row.processor} />
</ButtonGroup>
</Center>
),
Expand Down
12 changes: 12 additions & 0 deletions src/app/components/DeleteArtifactButton/Loadable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* Asynchronously loads the component for TrackAllButton
*
*/

import { lazyLoad } from 'utils/loadable';

export const DeleteArtifactButton = lazyLoad(
() => import('./index'),
module => module.DeleteArtifactButton,
);
50 changes: 50 additions & 0 deletions src/app/components/DeleteArtifactButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
*
* TrackAllButton
*
*/
import { Button } from '@blueprintjs/core';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useApcApi } from 'api/apc';
import React, { memo } from 'react';
import { useKeycloak } from '@react-keycloak-fork/web';
import { AxiosResponse } from 'axios';
import { Artifact } from '../../../types';

interface Props {
id: string;
processor: string;
}

export const DeleteArtifactButton = memo((props: Props) => {
const apc = useApcApi();
const { keycloak } = useKeycloak();
const query_client = useQueryClient();
const mutation = useMutation({
mutationFn: apc.DeleteArtifact,
onSuccess: (data: AxiosResponse<Artifact>) => {
const artifact = data.data;
query_client.invalidateQueries({
queryKey: ['artifact_table', artifact.processor, true],
});
},
});

if (!keycloak.hasResourceRole('Administrator')) {
return null;
}

return (
<Button
intent="danger"
disabled={!keycloak.hasResourceRole('Administrator')}
onClick={() => {
if (window.confirm('Do you really want to delete ' + props.id)) {
mutation.mutate({ id: props.id, processor: props.processor });
}
}}
loading={mutation.isLoading}
icon="trash"
></Button>
);
});
12 changes: 12 additions & 0 deletions src/app/components/TrackArtifactButton/Loadable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* Asynchronously loads the component for TrackAllButton
*
*/

import { lazyLoad } from 'utils/loadable';

export const TrackArtifactButton = lazyLoad(
() => import('./index'),
module => module.TrackArtifactButton,
);
31 changes: 31 additions & 0 deletions src/app/components/TrackArtifactButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
*
* TrackAllButton
*
*/
import { Button } from '@blueprintjs/core';
import { useMutation } from '@tanstack/react-query';
import { useApcApi } from 'api/apc';
import React, { memo } from 'react';
import { useKeycloak } from '@react-keycloak-fork/web';

interface Props {
id: string;
processor: string;
}

export const TrackArtifactButton = memo((props: Props) => {
const apc = useApcApi();
const mutation = useMutation(apc.TrackArtifact);

return (
<Button
intent="success"
loading={mutation.isLoading}
onClick={() =>
mutation.mutate({ id: props.id, processor: props.processor })
}
icon={'refresh'}
></Button>
);
});
12 changes: 12 additions & 0 deletions src/app/components/ValidateArtifactButton/Loadable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* Asynchronously loads the component for TrackAllButton
*
*/

import { lazyLoad } from 'utils/loadable';

export const ValidateArtifactButton = lazyLoad(
() => import('./index'),
module => module.ValidateArtifactButton,
);
31 changes: 31 additions & 0 deletions src/app/components/ValidateArtifactButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
*
* TrackAllButton
*
*/
import { Button } from '@blueprintjs/core';
import { useMutation } from '@tanstack/react-query';
import { useApcApi } from 'api/apc';
import React, { memo } from 'react';
import { useKeycloak } from '@react-keycloak-fork/web';

interface Props {
id: string;
processor: string;
}

export const ValidateArtifactButton = memo((props: Props) => {
const apc = useApcApi();
const mutation = useMutation(apc.ValidateArtifact);

return (
<Button
intent="warning"
loading={mutation.isLoading}
onClick={() =>
mutation.mutate({ id: props.id, processor: props.processor })
}
icon={'saved'}
></Button>
);
});

0 comments on commit fffa49b

Please sign in to comment.