mirror of https://github.com/buster-so/buster.git
create terms react query
This commit is contained in:
parent
b0519d4625
commit
cc01b2a03b
|
@ -1,31 +1,2 @@
|
||||||
export interface BusterTerm {
|
export * from './interfaces';
|
||||||
created_by: {
|
export * from './queryKeys';
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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
|
||||||
|
});
|
|
@ -3,93 +3,38 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BusterSocketRequestBase } from '../base_interfaces';
|
import { BusterSocketRequestBase } from '../base_interfaces';
|
||||||
|
import {
|
||||||
|
TermsListParams,
|
||||||
|
TermsGetParams,
|
||||||
|
TermPostParams,
|
||||||
|
TermUpdateParams,
|
||||||
|
TermDeleteParams
|
||||||
|
} from '../../request_interfaces/terms/interfaces';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request type for listing terms with pagination
|
* 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<
|
export type TermsListRequest = BusterSocketRequestBase<'/terms/list', TermsListParams>;
|
||||||
'/terms/list',
|
|
||||||
{
|
|
||||||
/** The page number to retrieve */
|
|
||||||
page: number;
|
|
||||||
/** The number of items per page */
|
|
||||||
page_size: number;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request type for retrieving a specific term by ID
|
* Request type for retrieving a specific term by ID
|
||||||
* @param id - The unique identifier of the term
|
|
||||||
*/
|
*/
|
||||||
export type TermsGetRequest = BusterSocketRequestBase<
|
export type TermsGetRequest = BusterSocketRequestBase<'/terms/get', TermsGetParams>;
|
||||||
'/terms/get',
|
|
||||||
{
|
|
||||||
/** The unique identifier of the term */
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request type for creating a new term
|
* 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<
|
export type TermPostRequest = BusterSocketRequestBase<'/terms/post', TermPostParams>;
|
||||||
'/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[];
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request type for updating an existing term
|
* 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<
|
export type TermUpdateRequest = BusterSocketRequestBase<'/terms/update', TermUpdateParams>;
|
||||||
'/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[];
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request type for deleting terms
|
* Request type for deleting terms
|
||||||
* @param ids - Array of term IDs to delete
|
|
||||||
*/
|
*/
|
||||||
export type TermDeleteRequest = BusterSocketRequestBase<
|
export type TermDeleteRequest = BusterSocketRequestBase<'/terms/delete', TermDeleteParams>;
|
||||||
'/terms/delete',
|
|
||||||
{
|
|
||||||
/** Array of term IDs to delete */
|
|
||||||
ids: string[];
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Union type of all possible term-related requests
|
* Union type of all possible term-related requests
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* @fileoverview Entry point for terms request interfaces
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from './interfaces';
|
|
@ -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[];
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
import { BusterTerm, BusterTermListItem } from '@/api/buster_rest';
|
import { BusterTerm, BusterTermListItem } from '@/api/buster_rest';
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useBusterWebSocket } from '../BusterWebSocket';
|
import { useBusterWebSocket } from '../BusterWebSocket';
|
||||||
import { useMemoizedFn, useMount, useUnmount } from 'ahooks';
|
import { useMemoizedFn, useUnmount } from 'ahooks';
|
||||||
import { TermPostRequest, TermUpdateRequest } from '@/api/buster_socket/terms';
|
import { TermPostRequest, TermUpdateRequest } from '@/api/buster_socket/terms';
|
||||||
import { useBusterNotifications } from '../BusterNotifications/BusterNotifications';
|
import { useBusterNotifications } from '../BusterNotifications/BusterNotifications';
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
|
export * from './interfaces';
|
||||||
export * from './BusterTermsProvider';
|
export * from './BusterTermsProvider';
|
||||||
|
|
|
@ -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>;
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
export const termsGetList = () => ['terms', 'list'] as const;
|
||||||
|
|
||||||
|
export const termsGetTerm = (termId: string) => ['terms', 'get', termId] as const;
|
Loading…
Reference in New Issue