Skip to content

Commit 3470d8a

Browse files
awkoyCometActions
andauthored
[OPIK-3836] [FE] Add batchGroupId param for dataset version creation (#4735)
* [OPIK-3836] [FE] Add batchGroupId param for dataset version creation Add batchGroupId parameter to dataset item CRUD operations that bypass draft mode (select all with filters), enabling the backend to create new versions when the dataset versioning feature flag is enabled. Changes: - Add generateBatchGroupId utility function to lib/utils.ts - Update useDatasetItemBatchDeleteMutation to accept and send batchGroupId - Update useDatasetItemBatchUpdateMutation to accept and send batchGroupId - Update DatasetItemsActionsPanel to pass batchGroupId for select all delete - Update AddTagDialog to pass batchGroupId for select all tag updates The batchGroupId is only sent when isAllItemsSelected is true (operations using filters instead of specific IDs). These versioned components are only used when DATASET_VERSIONING_ENABLED feature flag is enabled. * OPIK-3836 invalidate the dataset query --------- Co-authored-by: GitHub Actions Bot <[email protected]>
1 parent 2f094f5 commit 3470d8a

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

apps/opik-frontend/src/api/datasets/useDatasetItemBatchDeleteMutation.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type UseDatasetItemBatchDeleteMutationParams = {
1515
isAllItemsSelected?: boolean;
1616
filters?: Filters;
1717
search?: string;
18+
batchGroupId?: string;
1819
};
1920

2021
const useDatasetItemBatchDeleteMutation = () => {
@@ -28,6 +29,7 @@ const useDatasetItemBatchDeleteMutation = () => {
2829
isAllItemsSelected,
2930
filters = [],
3031
search,
32+
batchGroupId,
3133
}: UseDatasetItemBatchDeleteMutationParams) => {
3234
let payload;
3335

@@ -40,6 +42,7 @@ const useDatasetItemBatchDeleteMutation = () => {
4042
payload = {
4143
dataset_id: datasetId,
4244
filters: processFiltersArray(combinedFilters),
45+
...(batchGroupId && { batch_group_id: batchGroupId }),
4346
};
4447
} else {
4548
payload = { item_ids: ids };
@@ -73,10 +76,13 @@ const useDatasetItemBatchDeleteMutation = () => {
7376
variant: "destructive",
7477
});
7578
},
76-
onSettled: () => {
77-
return queryClient.invalidateQueries({
79+
onSettled: (data, error, variables) => {
80+
queryClient.invalidateQueries({
7881
queryKey: ["dataset-items"],
7982
});
83+
queryClient.invalidateQueries({
84+
queryKey: ["dataset", { datasetId: variables.datasetId }],
85+
});
8086
},
8187
});
8288
};

apps/opik-frontend/src/api/datasets/useDatasetItemBatchUpdateMutation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type UseDatasetItemBatchUpdateMutationParams = {
1919
isAllItemsSelected?: boolean;
2020
filters?: Filters;
2121
search?: string;
22+
batchGroupId?: string;
2223
};
2324

2425
const useDatasetItemBatchUpdateMutation = () => {
@@ -34,6 +35,7 @@ const useDatasetItemBatchUpdateMutation = () => {
3435
isAllItemsSelected,
3536
filters = [],
3637
search,
38+
batchGroupId,
3739
}: UseDatasetItemBatchUpdateMutationParams) => {
3840
let payload;
3941

@@ -48,6 +50,7 @@ const useDatasetItemBatchUpdateMutation = () => {
4850
filters: processFiltersArray(combinedFilters),
4951
update: item,
5052
merge_tags: mergeTags,
53+
...(batchGroupId && { batch_group_id: batchGroupId }),
5154
};
5255
} else {
5356
payload = { ids: itemIds, update: item, merge_tags: mergeTags };
@@ -77,6 +80,9 @@ const useDatasetItemBatchUpdateMutation = () => {
7780
queryClient.invalidateQueries({
7881
queryKey: ["dataset-items", { datasetId: variables.datasetId }],
7982
});
83+
queryClient.invalidateQueries({
84+
queryKey: ["dataset", { datasetId: variables.datasetId }],
85+
});
8086
},
8187
});
8288
};

apps/opik-frontend/src/components/pages/DatasetItemsPage/AddTagDialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
useBulkEditItems,
1717
useIsAllItemsSelected,
1818
} from "@/store/DatasetDraftStore";
19+
import { generateBatchGroupId } from "@/lib/utils";
1920

2021
type AddTagDialogProps = {
2122
datasetId: string;
@@ -77,6 +78,7 @@ const AddTagDialog: React.FunctionComponent<AddTagDialogProps> = ({
7778
isAllItemsSelected,
7879
filters,
7980
search,
81+
batchGroupId: isAllItemsSelected ? generateBatchGroupId() : undefined,
8082
},
8183
{
8284
onSuccess: () => {

apps/opik-frontend/src/components/pages/DatasetItemsPage/DatasetItemsActionsPanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import DatasetExpansionDialog from "./DatasetExpansionDialog";
1212
import GeneratedSamplesDialog from "./GeneratedSamplesDialog";
1313
import AddTagDialog from "./AddTagDialog";
1414
import { DATASET_ITEM_DATA_PREFIX } from "@/constants/datasets";
15-
import { stripColumnPrefix } from "@/lib/utils";
15+
import { stripColumnPrefix, generateBatchGroupId } from "@/lib/utils";
1616
import { useIsFeatureEnabled } from "@/components/feature-toggles-provider";
1717
import { FeatureToggleKeys } from "@/types/feature-toggles";
1818
import { Filters } from "@/types/filters";
@@ -80,6 +80,7 @@ const DatasetItemsActionsPanel: React.FunctionComponent<
8080
isAllItemsSelected,
8181
filters,
8282
search,
83+
batchGroupId: isAllItemsSelected ? generateBatchGroupId() : undefined,
8384
});
8485
}
8586
}, [

apps/opik-frontend/src/lib/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import mapValues from "lodash/mapValues";
1717
import pickBy from "lodash/pickBy";
1818
import { twMerge } from "tailwind-merge";
1919
import isEqual from "fast-deep-equal";
20+
import { v4 as uuidv4 } from "uuid";
2021
import { DEFAULT_WORKSPACE_NAME } from "@/constants/user";
2122
import { JsonNode } from "@/types/shared";
2223

@@ -303,3 +304,5 @@ export const removeUndefinedKeys = <T>(value: T): T => {
303304
export const isLooseEqual = <T>(a: T, b: T): boolean => {
304305
return isEqual(removeUndefinedKeys(a), removeUndefinedKeys(b));
305306
};
307+
308+
export const generateBatchGroupId = (): string => uuidv4();

0 commit comments

Comments
 (0)