Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/new-job-from-file-revisi…
Browse files Browse the repository at this point in the history
…on-' into feat/revision-job
  • Loading branch information
cakeinsauce committed Sep 20, 2024
2 parents 3d48009 + f083b55 commit cc2e021
Show file tree
Hide file tree
Showing 13 changed files with 488 additions and 49 deletions.
1 change: 1 addition & 0 deletions web/src/api/hooks/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type JobVariables = {
files?: string[] | number[] | null;
previous_jobs?: number[] | null;
datasets?: number[] | null;
revisions?: number[] | string[] | null;
pipeline_name?: string | undefined;
pipeline_id?: number;
pipeline_engine?: string;
Expand Down
95 changes: 95 additions & 0 deletions web/src/api/hooks/revisions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// temporary_disabled_rules
/* eslint-disable react-hooks/rules-of-hooks */
import {
FilterWithDocumentExtraOption,
Operators,
PagedResponse,
QueryHookParamsType,
QueryHookType,
Revision,
SearchBody,
SortingDirection
} from 'api/typings';
import { useQuery } from 'react-query';
import { pageSizes } from 'shared/primitives';
import { useBadgerFetch } from './api';

const namespace = process.env.REACT_APP_CATEGORIES_API_NAMESPACE;

export const useRevisions: QueryHookType<QueryHookParamsType<Revision>, PagedResponse<Revision>> = (
params,
options
) => {
const { searchText, sortConfig, size: pageSize, page: pageNum, filters } = params;
return useQuery(
['revisions', searchText, sortConfig, pageSize, pageNum],
() => revisionsFetcher(pageNum, pageSize, searchText, sortConfig, filters),
options
);
};
export function revisionsFetcher(
page = 1,
size = pageSizes._15,
searchText?: string | null,
sortConfig: {
field: keyof Revision;
direction: SortingDirection;
} = {
field: 'revision',
direction: SortingDirection.ASC
},
filters: FilterWithDocumentExtraOption<keyof Revision>[] = []
): Promise<PagedResponse<Revision>> {
if (searchText) {
filters.push({
field: 'revision',
operator: Operators.ILIKE,
value: `%${searchText.trim().toLowerCase()}%`
});
}
const body: SearchBody<Revision> = {
pagination: { page_num: page, page_size: size },
filters,
sorting: [{ direction: sortConfig.direction, field: sortConfig.field }]
};
return useBadgerFetch<PagedResponse<Revision>>({
url: `${namespace}/annotation`,
method: 'post',
withCredentials: true
})(JSON.stringify(body));
}

export function revisionPropFetcher(
propName: keyof Revision,
page = 1,
size = pageSizes._15,
keyword: string = ''
): Promise<PagedResponse<string>> {
const sortConfig = {
field: propName,
direction: SortingDirection.ASC
};
const filters: FilterWithDocumentExtraOption<keyof Revision>[] = [];
filters.push({
field: propName,
operator: Operators.DISTINCT
});
if (keyword) {
filters.push({
field: propName,
operator: Operators.ILIKE,
value: `%${keyword}%`
});
}
const body: SearchBody<Revision> = {
pagination: { page_num: page, page_size: size },
filters,
sorting: [{ direction: sortConfig.direction, field: sortConfig.field as keyof Revision }]
};

return useBadgerFetch<PagedResponse<string>>({
url: `${namespace}/annotation`,
method: 'post',
withCredentials: true
})(JSON.stringify(body));
}
6 changes: 6 additions & 0 deletions web/src/api/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export type Dataset = {
name: string;
};

export type Revision = {
revision: string;
date: string;
id: string | number;
};

export type Preprocessor = {
modelId: string;
name: string;
Expand Down
7 changes: 7 additions & 0 deletions web/src/connectors/edit-job-connector/edit-job-connector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type EditJobConnectorProps = {
files?: number[] | null;
jobs?: number[] | null;
datasets?: number[] | null;
revisions?: number[] | string[] | null;
checkedFiles?: number[];
initialJob?: Job;
showNoExtractionTab?: boolean;
Expand Down Expand Up @@ -79,9 +80,13 @@ const EditJobConnector: FC<EditJobConnectorProps> = ({
files,
jobs,
datasets,
revisions,
initialJob,
showNoExtractionTab
}) => {
const searchParams = new URLSearchParams(document.location.search);
const revisionId = searchParams.get('revisionId') || null;

const getMetadata = (state: JobValues) => {
const { jobType, validationType, pipeline, categories } = state;

Expand Down Expand Up @@ -239,6 +244,7 @@ const EditJobConnector: FC<EditJobConnectorProps> = ({

const jobProps: JobVariables = {
name: jobName,
revisions: revisionId ? [revisionId] : revisions,
datasets,
files,
previous_jobs: jobs,
Expand Down Expand Up @@ -288,6 +294,7 @@ const EditJobConnector: FC<EditJobConnectorProps> = ({
delete editData.files;
delete editData.previous_jobs;
delete editData.datasets;
delete editData.revisions;
await editJobMutation.mutateAsync({
id: initialJob.id,
data: editData
Expand Down
1 change: 1 addition & 0 deletions web/src/connectors/revisions-table-connector/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { RevisionsTableConnector } from './revisions-table-connector';
27 changes: 27 additions & 0 deletions web/src/connectors/revisions-table-connector/revisions-columns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// temporary_disabled_rules
/* eslint-disable @typescript-eslint/no-redeclare, @typescript-eslint/no-unused-vars */
import { DataColumnProps } from '@epam/uui';
import { Revision } from 'api/typings';
import { Text } from '@epam/loveship';
import React from 'react';

export const revisionsColumns: DataColumnProps<Revision>[] = [
{
key: 'revision',
caption: 'REVISION ID',
render: (file) => <Text>{file.revision}</Text>,
grow: 1,
minWidth: 100,
isSortable: true,
width: 150
},
{
key: 'date',
caption: 'CREATED DATE',
render: (file) => <Text>{new Date(file.date).toLocaleDateString()}</Text>,
grow: 0,
minWidth: 100,
isSortable: true,
width: 150
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.title {
padding: 22px 0 12px 0;
}
Loading

0 comments on commit cc2e021

Please sign in to comment.