diff --git a/web/src/api/asset_interfaces/terms/index.ts b/web/src/api/asset_interfaces/terms/index.ts index 5e260f898..da7c2f52f 100644 --- a/web/src/api/asset_interfaces/terms/index.ts +++ b/web/src/api/asset_interfaces/terms/index.ts @@ -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'; diff --git a/web/src/api/asset_interfaces/terms/interfaces.ts b/web/src/api/asset_interfaces/terms/interfaces.ts new file mode 100644 index 000000000..5e260f898 --- /dev/null +++ b/web/src/api/asset_interfaces/terms/interfaces.ts @@ -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; +} diff --git a/web/src/api/asset_interfaces/terms/queryKeys.ts b/web/src/api/asset_interfaces/terms/queryKeys.ts new file mode 100644 index 000000000..12fb57c23 --- /dev/null +++ b/web/src/api/asset_interfaces/terms/queryKeys.ts @@ -0,0 +1,14 @@ +import { queryOptions } from '@tanstack/react-query'; +import type { BusterTerm, BusterTermListItem } from './interfaces'; + +export const termsGetList = () => + queryOptions({ + queryKey: ['terms', 'list'] as const, + staleTime: 10 * 1000 + }); + +export const termsGetTerm = (termId: string) => + queryOptions({ + queryKey: ['terms', 'get', termId] as const, + staleTime: 10 * 1000 + }); diff --git a/web/src/api/buster_socket/terms/termsRequest.ts b/web/src/api/buster_socket/terms/termsRequest.ts index 2f29184d0..c3a67ae80 100644 --- a/web/src/api/buster_socket/terms/termsRequest.ts +++ b/web/src/api/buster_socket/terms/termsRequest.ts @@ -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 diff --git a/web/src/api/request_interfaces/terms/index.ts b/web/src/api/request_interfaces/terms/index.ts new file mode 100644 index 000000000..26b75adb5 --- /dev/null +++ b/web/src/api/request_interfaces/terms/index.ts @@ -0,0 +1,5 @@ +/** + * @fileoverview Entry point for terms request interfaces + */ + +export * from './interfaces'; diff --git a/web/src/api/request_interfaces/terms/interfaces.ts b/web/src/api/request_interfaces/terms/interfaces.ts new file mode 100644 index 000000000..42bb13603 --- /dev/null +++ b/web/src/api/request_interfaces/terms/interfaces.ts @@ -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[]; +} diff --git a/web/src/context/Terms/BusterTermsProvider.tsx b/web/src/context/Terms/BusterTermsProvider.tsx index a85522316..d3d3e3264 100644 --- a/web/src/context/Terms/BusterTermsProvider.tsx +++ b/web/src/context/Terms/BusterTermsProvider.tsx @@ -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 { diff --git a/web/src/context/Terms/index.ts b/web/src/context/Terms/index.ts index 525600d9c..0e6f06a79 100644 --- a/web/src/context/Terms/index.ts +++ b/web/src/context/Terms/index.ts @@ -1 +1,2 @@ +export * from './interfaces'; export * from './BusterTermsProvider'; diff --git a/web/src/context/Terms/interfaces.ts b/web/src/context/Terms/interfaces.ts new file mode 100644 index 000000000..726f10074 --- /dev/null +++ b/web/src/context/Terms/interfaces.ts @@ -0,0 +1,19 @@ +import { BusterTerm, BusterTermListItem } from '@/api/buster_rest'; +import { ContextSelector } from '@fluentui/react-context-selector'; + +export type UseTermsContextSelector = (selector: ContextSelector) => T; + +export interface UseTermsHookReturn { + getTermFromList: (termId: string) => BusterTermListItem | undefined; + createTerm: (params: any) => Promise; + subscribeToTerm: ({ id }: { id: string }) => Promise; + termsList: BusterTermListItem[]; + loadedTermsList: boolean; + getInitialTerms: () => Promise; + onSetOpenNewTermsModal: (value: boolean) => void; + updateTerm: (params: any) => Promise; + deleteTerm: ({ id }: { id: string }, ignoreConfirm?: boolean) => Promise; + openNewTermsModal: boolean; + unsubscribeFromTerm: (termId: string) => void; + terms: Record; +} diff --git a/web/src/context/Terms/queryKeys.ts b/web/src/context/Terms/queryKeys.ts new file mode 100644 index 000000000..1d3fdfa90 --- /dev/null +++ b/web/src/context/Terms/queryKeys.ts @@ -0,0 +1,3 @@ +export const termsGetList = () => ['terms', 'list'] as const; + +export const termsGetTerm = (termId: string) => ['terms', 'get', termId] as const;