create terms react query

This commit is contained in:
Nate Kelley 2025-02-13 16:54:30 -07:00
parent b0519d4625
commit cc01b2a03b
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
10 changed files with 149 additions and 99 deletions

View File

@ -1,31 +1,2 @@
export interface BusterTerm {
created_by: {
id: string;
name: string;
};
created_at: string;
datasets: {
id: string;
name: string;
}[];
definition: string;
deleted_at: string | null;
id: string;
name: string;
organization_id: string;
permission: string;
sql_snippet: string;
updated_at: string | null;
updated_by: string | null;
}
export interface BusterTermListItem {
id: string;
name: string;
created_by: {
id: string;
name: string;
};
dataset_count: number;
last_edited: string;
}
export * from './interfaces';
export * from './queryKeys';

View File

@ -0,0 +1,31 @@
export interface BusterTerm {
created_by: {
id: string;
name: string;
};
created_at: string;
datasets: {
id: string;
name: string;
}[];
definition: string;
deleted_at: string | null;
id: string;
name: string;
organization_id: string;
permission: string;
sql_snippet: string;
updated_at: string | null;
updated_by: string | null;
}
export interface BusterTermListItem {
id: string;
name: string;
created_by: {
id: string;
name: string;
};
dataset_count: number;
last_edited: string;
}

View File

@ -0,0 +1,14 @@
import { queryOptions } from '@tanstack/react-query';
import type { BusterTerm, BusterTermListItem } from './interfaces';
export const termsGetList = () =>
queryOptions<BusterTermListItem[]>({
queryKey: ['terms', 'list'] as const,
staleTime: 10 * 1000
});
export const termsGetTerm = (termId: string) =>
queryOptions<BusterTerm>({
queryKey: ['terms', 'get', termId] as const,
staleTime: 10 * 1000
});

View File

@ -3,93 +3,38 @@
*/
import { BusterSocketRequestBase } from '../base_interfaces';
import {
TermsListParams,
TermsGetParams,
TermPostParams,
TermUpdateParams,
TermDeleteParams
} from '../../request_interfaces/terms/interfaces';
/**
* Request type for listing terms with pagination
* @param page - The page number to retrieve
* @param page_size - The number of items per page
*/
export type TermsListRequest = BusterSocketRequestBase<
'/terms/list',
{
/** The page number to retrieve */
page: number;
/** The number of items per page */
page_size: number;
}
>;
export type TermsListRequest = BusterSocketRequestBase<'/terms/list', TermsListParams>;
/**
* Request type for retrieving a specific term by ID
* @param id - The unique identifier of the term
*/
export type TermsGetRequest = BusterSocketRequestBase<
'/terms/get',
{
/** The unique identifier of the term */
id: string;
}
>;
export type TermsGetRequest = BusterSocketRequestBase<'/terms/get', TermsGetParams>;
/**
* Request type for creating a new term
* @param name - The name of the term
* @param definition - The definition or description of the term
* @param sql_snippet - Optional SQL snippet associated with the term
* @param dataset_ids - Array of dataset IDs where this term should be applied
*/
export type TermPostRequest = BusterSocketRequestBase<
'/terms/post',
{
/** The name of the term */
name: string;
/** The definition or description of the term */
definition: string;
/** Optional SQL snippet associated with the term */
sql_snippet?: string;
/** Array of dataset IDs where this term should be applied */
dataset_ids: string[];
}
>;
export type TermPostRequest = BusterSocketRequestBase<'/terms/post', TermPostParams>;
/**
* Request type for updating an existing term
* @param id - The unique identifier of the term to update
* @param name - Optional new name for the term
* @param definition - Optional new definition for the term
* @param sql_snippet - Optional new SQL snippet for the term
* @param add_to_dataset - Optional array of dataset IDs to add this term to
* @param remove_from_dataset - Optional array of dataset IDs to remove this term from
*/
export type TermUpdateRequest = BusterSocketRequestBase<
'/terms/update',
{
/** The unique identifier of the term to update */
id: string;
/** Optional new name for the term */
name?: string;
/** Optional new definition for the term */
definition?: string;
/** Optional new SQL snippet for the term */
sql_snippet?: string;
/** Optional array of dataset IDs to add this term to */
add_to_dataset?: string[];
/** Optional array of dataset IDs to remove this term from */
remove_from_dataset?: string[];
}
>;
export type TermUpdateRequest = BusterSocketRequestBase<'/terms/update', TermUpdateParams>;
/**
* Request type for deleting terms
* @param ids - Array of term IDs to delete
*/
export type TermDeleteRequest = BusterSocketRequestBase<
'/terms/delete',
{
/** Array of term IDs to delete */
ids: string[];
}
>;
export type TermDeleteRequest = BusterSocketRequestBase<'/terms/delete', TermDeleteParams>;
/**
* Union type of all possible term-related requests

View File

@ -0,0 +1,5 @@
/**
* @fileoverview Entry point for terms request interfaces
*/
export * from './interfaces';

View File

@ -0,0 +1,61 @@
/**
* @fileoverview Contains parameter type definitions for Terms API requests
*/
/**
* Parameters for listing terms with pagination
*/
export interface TermsListParams {
/** The page number to retrieve */
page: number;
/** The number of items per page */
page_size: number;
}
/**
* Parameters for retrieving a specific term by ID
*/
export interface TermsGetParams {
/** The unique identifier of the term */
id: string;
}
/**
* Parameters for creating a new term
*/
export interface TermPostParams {
/** The name of the term */
name: string;
/** The definition or description of the term */
definition: string;
/** Optional SQL snippet associated with the term */
sql_snippet?: string;
/** Array of dataset IDs where this term should be applied */
dataset_ids: string[];
}
/**
* Parameters for updating an existing term
*/
export interface TermUpdateParams {
/** The unique identifier of the term to update */
id: string;
/** Optional new name for the term */
name?: string;
/** Optional new definition for the term */
definition?: string;
/** Optional new SQL snippet for the term */
sql_snippet?: string;
/** Optional array of dataset IDs to add this term to */
add_to_dataset?: string[];
/** Optional array of dataset IDs to remove this term from */
remove_from_dataset?: string[];
}
/**
* Parameters for deleting terms
*/
export interface TermDeleteParams {
/** Array of term IDs to delete */
ids: string[];
}

View File

@ -1,7 +1,7 @@
import { BusterTerm, BusterTermListItem } from '@/api/buster_rest';
import React, { useEffect } from 'react';
import { useBusterWebSocket } from '../BusterWebSocket';
import { useMemoizedFn, useMount, useUnmount } from 'ahooks';
import { useMemoizedFn, useUnmount } from 'ahooks';
import { TermPostRequest, TermUpdateRequest } from '@/api/buster_socket/terms';
import { useBusterNotifications } from '../BusterNotifications/BusterNotifications';
import {

View File

@ -1 +1,2 @@
export * from './interfaces';
export * from './BusterTermsProvider';

View File

@ -0,0 +1,19 @@
import { BusterTerm, BusterTermListItem } from '@/api/buster_rest';
import { ContextSelector } from '@fluentui/react-context-selector';
export type UseTermsContextSelector = <T>(selector: ContextSelector<UseTermsHookReturn, T>) => T;
export interface UseTermsHookReturn {
getTermFromList: (termId: string) => BusterTermListItem | undefined;
createTerm: (params: any) => Promise<any>;
subscribeToTerm: ({ id }: { id: string }) => Promise<any>;
termsList: BusterTermListItem[];
loadedTermsList: boolean;
getInitialTerms: () => Promise<void>;
onSetOpenNewTermsModal: (value: boolean) => void;
updateTerm: (params: any) => Promise<any>;
deleteTerm: ({ id }: { id: string }, ignoreConfirm?: boolean) => Promise<any>;
openNewTermsModal: boolean;
unsubscribeFromTerm: (termId: string) => void;
terms: Record<string, BusterTerm>;
}

View File

@ -0,0 +1,3 @@
export const termsGetList = () => ['terms', 'list'] as const;
export const termsGetTerm = (termId: string) => ['terms', 'get', termId] as const;