feat: add tianji-client-react package and useTianjiSurvey hooks which can easy to get survey info

This commit is contained in:
moonrailgun 2024-05-04 18:54:17 +08:00
parent a596011960
commit 0fc112fc32
15 changed files with 139 additions and 31 deletions

View File

@ -17,7 +17,7 @@
"build:server": "cd src/server && pnpm build",
"build:tracker": "ts-node scripts/build-tracker.ts",
"build:geo": "ts-node scripts/build-geo.ts",
"build:openapi": "ts-node --project ./tsconfig.base.json ./scripts/build-openapi-schema.ts",
"build:openapi": "ts-node --project ./tsconfig.base.json ./scripts/build-openapi-schema.ts && cd packages/client-sdk && pnpm generate:client",
"check:type": "pnpm -r check:type",
"release": "release-it",
"release:patch": "release-it -i patch"

View File

@ -1,3 +1,4 @@
export { initOpenapiSDK } from './config';
export { openApiClient } from './open';
export * from './tracker';
export * from './survey';

View File

@ -47,7 +47,7 @@ export const OpenAPI: OpenAPIConfig = {
PASSWORD: undefined,
TOKEN: undefined,
USERNAME: undefined,
VERSION: '1.9.2',
VERSION: '1.9.3',
WITH_CREDENTIALS: false,
interceptors: {
request: new Interceptors(),

View File

@ -927,10 +927,10 @@ export class SurveyService {
* @returns unknown Successful response
* @throws ApiError
*/
public static surveyAll(data: $OpenApiTs['/workspace/{workspaceId}/survey//all']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//all']['get']['res'][200]> {
public static surveyAll(data: $OpenApiTs['/workspace/{workspaceId}/survey/all']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/all']['get']['res'][200]> {
return __request(OpenAPI, {
method: 'GET',
url: '/workspace/{workspaceId}/survey//all',
url: '/workspace/{workspaceId}/survey/all',
path: {
workspaceId: data.workspaceId
}
@ -944,10 +944,10 @@ export class SurveyService {
* @returns unknown Successful response
* @throws ApiError
*/
public static surveyGet(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}']['get']['res'][200]> {
public static surveyGet(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}']['get']['res'][200]> {
return __request(OpenAPI, {
method: 'GET',
url: '/workspace/{workspaceId}/survey//{surveyId}',
url: '/workspace/{workspaceId}/survey/{surveyId}',
path: {
workspaceId: data.workspaceId,
surveyId: data.surveyId
@ -963,10 +963,10 @@ export class SurveyService {
* @returns unknown Error response
* @throws ApiError
*/
public static surveyCount(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/count']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/count']['get']['res'][200] | $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/count']['get']['res'][200]> {
public static surveyCount(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/count']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/count']['get']['res'][200] | $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/count']['get']['res'][200]> {
return __request(OpenAPI, {
method: 'GET',
url: '/workspace/{workspaceId}/survey//{surveyId}/count',
url: '/workspace/{workspaceId}/survey/{surveyId}/count',
path: {
workspaceId: data.workspaceId,
surveyId: data.surveyId
@ -981,10 +981,10 @@ export class SurveyService {
* @returns unknown Error response
* @throws ApiError
*/
public static surveyAllResultCount(data: $OpenApiTs['/workspace/{workspaceId}/survey//allResultCount']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//allResultCount']['get']['res'][200] | $OpenApiTs['/workspace/{workspaceId}/survey//allResultCount']['get']['res'][200]> {
public static surveyAllResultCount(data: $OpenApiTs['/workspace/{workspaceId}/survey/allResultCount']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/allResultCount']['get']['res'][200] | $OpenApiTs['/workspace/{workspaceId}/survey/allResultCount']['get']['res'][200]> {
return __request(OpenAPI, {
method: 'GET',
url: '/workspace/{workspaceId}/survey//allResultCount',
url: '/workspace/{workspaceId}/survey/allResultCount',
path: {
workspaceId: data.workspaceId
}
@ -999,10 +999,10 @@ export class SurveyService {
* @returns unknown Successful response
* @throws ApiError
*/
public static surveySubmit(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/submit']['post']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/submit']['post']['res'][200]> {
public static surveySubmit(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/submit']['post']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/submit']['post']['res'][200]> {
return __request(OpenAPI, {
method: 'POST',
url: '/workspace/{workspaceId}/survey//{surveyId}/submit',
url: '/workspace/{workspaceId}/survey/{surveyId}/submit',
path: {
workspaceId: data.workspaceId,
surveyId: data.surveyId
@ -1019,10 +1019,10 @@ export class SurveyService {
* @returns unknown Successful response
* @throws ApiError
*/
public static surveyCreate(data: $OpenApiTs['/workspace/{workspaceId}/survey//create']['post']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//create']['post']['res'][200]> {
public static surveyCreate(data: $OpenApiTs['/workspace/{workspaceId}/survey/create']['post']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/create']['post']['res'][200]> {
return __request(OpenAPI, {
method: 'POST',
url: '/workspace/{workspaceId}/survey//create',
url: '/workspace/{workspaceId}/survey/create',
path: {
workspaceId: data.workspaceId
},
@ -1039,10 +1039,10 @@ export class SurveyService {
* @returns unknown Successful response
* @throws ApiError
*/
public static surveyUpdate(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/update']['patch']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/update']['patch']['res'][200]> {
public static surveyUpdate(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/update']['patch']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/update']['patch']['res'][200]> {
return __request(OpenAPI, {
method: 'PATCH',
url: '/workspace/{workspaceId}/survey//{surveyId}/update',
url: '/workspace/{workspaceId}/survey/{surveyId}/update',
path: {
workspaceId: data.workspaceId,
surveyId: data.surveyId
@ -1059,10 +1059,10 @@ export class SurveyService {
* @returns unknown Successful response
* @throws ApiError
*/
public static surveyDelete(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/delete']['delete']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/delete']['delete']['res'][200]> {
public static surveyDelete(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/delete']['delete']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/delete']['delete']['res'][200]> {
return __request(OpenAPI, {
method: 'DELETE',
url: '/workspace/{workspaceId}/survey//{surveyId}/delete',
url: '/workspace/{workspaceId}/survey/{surveyId}/delete',
path: {
workspaceId: data.workspaceId,
surveyId: data.surveyId
@ -1079,10 +1079,10 @@ export class SurveyService {
* @returns unknown Successful response
* @throws ApiError
*/
public static surveyResultList(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/result/list']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/result/list']['get']['res'][200]> {
public static surveyResultList(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/result/list']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/result/list']['get']['res'][200]> {
return __request(OpenAPI, {
method: 'GET',
url: '/workspace/{workspaceId}/survey//{surveyId}/result/list',
url: '/workspace/{workspaceId}/survey/{surveyId}/result/list',
path: {
workspaceId: data.workspaceId,
surveyId: data.surveyId

View File

@ -439,6 +439,7 @@ export type $OpenApiTs = {
payload: {
[key: string]: unknown;
};
trendingMode: boolean;
createdAt: string;
updatedAt: string;
notifications: Array<{
@ -469,6 +470,7 @@ export type $OpenApiTs = {
payload: {
[key: string]: unknown;
};
trendingMode: boolean;
createdAt: string;
updatedAt: string;
notifications: Array<{
@ -497,6 +499,7 @@ export type $OpenApiTs = {
payload: {
[key: string]: unknown;
};
trendingMode: boolean;
createdAt: string;
updatedAt: string;
};
@ -532,6 +535,7 @@ export type $OpenApiTs = {
active?: boolean;
interval?: number;
maxRetries?: number;
trendingMode?: boolean;
notificationIds?: Array<(string)>;
payload: {
[key: string]: unknown;
@ -554,6 +558,7 @@ export type $OpenApiTs = {
payload: {
[key: string]: unknown;
};
trendingMode: boolean;
createdAt: string;
updatedAt: string;
};
@ -603,6 +608,7 @@ export type $OpenApiTs = {
payload: {
[key: string]: unknown;
};
trendingMode: boolean;
createdAt: string;
updatedAt: string;
};
@ -1091,7 +1097,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//all': {
'/workspace/{workspaceId}/survey/all': {
get: {
req: {
workspaceId: string;
@ -1118,7 +1124,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//{surveyId}': {
'/workspace/{workspaceId}/survey/{surveyId}': {
get: {
req: {
surveyId: string;
@ -1146,7 +1152,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//{surveyId}/count': {
'/workspace/{workspaceId}/survey/{surveyId}/count': {
get: {
req: {
surveyId: string;
@ -1166,7 +1172,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//allResultCount': {
'/workspace/{workspaceId}/survey/allResultCount': {
get: {
req: {
workspaceId: string;
@ -1185,7 +1191,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//{surveyId}/submit': {
'/workspace/{workspaceId}/survey/{surveyId}/submit': {
post: {
req: {
requestBody: {
@ -1204,7 +1210,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//create': {
'/workspace/{workspaceId}/survey/create': {
post: {
req: {
requestBody: {
@ -1242,7 +1248,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//{surveyId}/update': {
'/workspace/{workspaceId}/survey/{surveyId}/update': {
patch: {
req: {
requestBody: {
@ -1281,7 +1287,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//{surveyId}/delete': {
'/workspace/{workspaceId}/survey/{surveyId}/delete': {
delete: {
req: {
surveyId: string;
@ -1309,7 +1315,7 @@ export type $OpenApiTs = {
};
};
};
'/workspace/{workspaceId}/survey//{surveyId}/result/list': {
'/workspace/{workspaceId}/survey/{surveyId}/result/list': {
get: {
req: {
cursor?: string;

View File

@ -0,0 +1 @@
export * as openApiClient from './client';

View File

@ -4,6 +4,8 @@
"module": "ESNext",
"outDir": "./lib",
"baseUrl": ".",
"declaration": true,
"declarationMap": true,
"noEmit": false,
},
"include": ["./src/**/*"]

1
packages/react/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

@ -0,0 +1,28 @@
{
"name": "tianji-client-react",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"scripts": {
"build": "tsc",
"prepare": "tsc",
"generate:client": "openapi-ts -i ../../website/openapi.json -o src/open/client",
"test": "vitest"
},
"keywords": [
"tianji"
],
"author": "moonrailgun <moonrailgun@gmail.com>",
"license": "MIT",
"dependencies": {
"tianji-client-sdk": "workspace:^"
},
"devDependencies": {
"@types/react": "^18.2.22",
"react": "^18.3.1"
},
"peerDependencies": {
"@types/react": "^18.2.22",
"react": "^18.3.1"
}
}

View File

@ -0,0 +1 @@
export * from './useTianjiSurvey';

View File

@ -0,0 +1,38 @@
import { useState, useEffect } from 'react';
import {
initOpenapiSDK,
getSurveyInfo,
openApiClient,
} from 'tianji-client-sdk';
type SurveyInfo =
openApiClient.$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}']['get']['res']['200'];
interface UseTianjiSurveyOptions {
baseUrl?: string;
workspaceId: string;
surveyId: string;
}
export function useTianjiSurvey(options: UseTianjiSurveyOptions) {
const [isLoading, setIsLoading] = useState(false);
const [info, setInfo] = useState<SurveyInfo | undefined>(undefined);
useEffect(() => {
if (options.baseUrl) {
initOpenapiSDK(options.baseUrl);
}
}, [options.baseUrl]);
useEffect(() => {
setIsLoading(true);
getSurveyInfo(options.workspaceId, options.surveyId)
.then((data) => {
setInfo(data);
})
.finally(() => {
setIsLoading(false);
});
}, [options.workspaceId, options.surveyId]);
return { isLoading, info };
}

View File

@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"outDir": "./lib",
"baseUrl": ".",
"noEmit": false,
},
"include": ["./src/**/*"]
}

View File

@ -86,6 +86,19 @@ importers:
specifier: ^1.2.1
version: 1.2.1(@types/node@18.17.12)(happy-dom@14.7.1)
packages/react:
dependencies:
tianji-client-sdk:
specifier: workspace:^
version: link:../client-sdk
devDependencies:
'@types/react':
specifier: ^18.2.22
version: 18.2.78
react:
specifier: ^18.3.1
version: 18.3.1
src/client:
dependencies:
'@ant-design/charts':
@ -23718,6 +23731,13 @@ packages:
loose-envify: 1.4.0
dev: false
/react@18.3.1:
resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==}
engines: {node: '>=0.10.0'}
dependencies:
loose-envify: 1.4.0
dev: true
/reactcss@1.2.3(react@18.2.0):
resolution: {integrity: sha512-KiwVUcFu1RErkI97ywr8nvx8dNOpT03rbnma0SSalTYjkrPYaEajR4a/MRt6DZ46K6arDRbWMNHF+xH7G7n/8A==}
peerDependencies:

View File

@ -292,7 +292,7 @@ function buildSurveyOpenapi(meta: OpenApiMetaInfo): OpenApiMeta {
tags: [OPENAPI_TAG.SURVEY],
protect: true,
...meta,
path: `/workspace/{workspaceId}/survey/${meta.path}`,
path: `/workspace/{workspaceId}/survey${meta.path}`,
},
};
}

File diff suppressed because one or more lines are too long