1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-23 13:46:45 +02:00

feat: make local storage work and make feedback url configurable (#5738)

Make storage work react way.
Make feedback url configurable by env variable.
This commit is contained in:
Jaanus Sellin 2023-12-29 13:19:08 +02:00 committed by GitHub
parent 55bd0a6760
commit e4c9a257ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 27 deletions

View File

@ -1,40 +1,41 @@
import { IInternalBanner } from 'interfaces/banner';
import useAPI from '../useApi/useApi'; import useAPI from '../useApi/useApi';
import { ProvideFeedbackSchema } from '../../../../openapi'; import { ProvideFeedbackSchema } from '../../../../openapi';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
const DIRECT_ENDPOINT = 'https://sandbox.getunleash.io/enterprise/feedback';
const ENDPOINT = 'feedback'; const ENDPOINT = 'feedback';
export const useUserFeedbackApi = () => { export const useUserFeedbackApi = () => {
const addDirectFeedback = async (feedbackSchema: ProvideFeedbackSchema) => { const { uiConfig } = useUiConfig();
await fetch(DIRECT_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(feedbackSchema),
});
};
const { loading, makeRequest, createRequest, errors } = useAPI({ const { loading, makeRequest, createRequest, errors } = useAPI({
propagateErrors: true, propagateErrors: true,
}); });
const addFeedback = async (feedbackSchema: ProvideFeedbackSchema) => { const addFeedback = async (feedbackSchema: ProvideFeedbackSchema) => {
const requestId = 'addFeedback'; if (uiConfig.feedbackUriPath !== undefined) {
const req = createRequest( await fetch(uiConfig.feedbackUriPath, {
ENDPOINT,
{
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(feedbackSchema), body: JSON.stringify(feedbackSchema),
}, });
requestId, } else {
); const requestId = 'addFeedback';
const req = createRequest(
ENDPOINT,
{
method: 'POST',
body: JSON.stringify(feedbackSchema),
},
requestId,
);
const response = await makeRequest(req.caller, req.id); const response = await makeRequest(req.caller, req.id);
return response.json(); return response.json();
}
}; };
return { return {
addFeedback, addFeedback,
addDirectFeedback,
errors, errors,
loading, loading,
}; };

View File

@ -1,20 +1,15 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { getLocalStorageItem, setLocalStorageItem } from '../utils/storage'; import { getLocalStorageItem, setLocalStorageItem } from '../utils/storage';
import { basePath } from 'utils/formatPath'; import { basePath } from 'utils/formatPath';
import { createLocalStorage } from '../utils/createLocalStorage';
export type IFeedbackCategory = 'search'; export type IFeedbackCategory = 'search';
export const useUserSubmittedFeedback = (category: IFeedbackCategory) => { export const useUserSubmittedFeedback = (category: IFeedbackCategory) => {
const key = `${basePath}:unleash-userSubmittedFeedback:${category}`; const key = `${basePath}:unleash-userSubmittedFeedback:${category}`;
const [hasSubmittedFeedback, setHasSubmittedFeedback] = useState(() => { const { value: hasSubmittedFeedback, setValue: setHasSubmittedFeedback } =
return getLocalStorageItem<boolean>(key) || false; createLocalStorage<Boolean>(key, false);
});
useEffect(() => {
setLocalStorageItem(key, hasSubmittedFeedback);
}, [hasSubmittedFeedback, key]);
return { return {
hasSubmittedFeedback, hasSubmittedFeedback,
setHasSubmittedFeedback, setHasSubmittedFeedback,

View File

@ -4,6 +4,7 @@ import { Variant } from 'utils/variants';
export interface IUiConfig { export interface IUiConfig {
authenticationType?: string; authenticationType?: string;
baseUriPath?: string; baseUriPath?: string;
feedbackUriPath?: string;
/** /**
* @deprecated `useUiFlags` can be used instead * @deprecated `useUiFlags` can be used instead
* @example * @example

View File

@ -69,6 +69,7 @@ exports[`should create default config 1`] = `
"_maxListeners": undefined, "_maxListeners": undefined,
Symbol(kCapture): false, Symbol(kCapture): false,
}, },
"feedbackUriPath": undefined,
"flagResolver": FlagResolver { "flagResolver": FlagResolver {
"experiments": { "experiments": {
"anonymiseEventLog": false, "anonymiseEventLog": false,

View File

@ -549,6 +549,8 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
const rateLimiting = loadRateLimitingConfig(options); const rateLimiting = loadRateLimitingConfig(options);
const feedbackUriPath = process.env.FEEDBACK_URI_PATH;
return { return {
db, db,
session, session,
@ -584,6 +586,7 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
isEnterprise: isEnterprise, isEnterprise: isEnterprise,
metricsRateLimiting, metricsRateLimiting,
rateLimiting, rateLimiting,
feedbackUriPath,
}; };
} }

View File

@ -43,6 +43,12 @@ export const uiConfigSchema = {
'The base URI path at which this Unleash instance is listening.', 'The base URI path at which this Unleash instance is listening.',
example: '/enterprise', example: '/enterprise',
}, },
feedbackUriPath: {
type: 'string',
description:
'The URI path at which the feedback endpoint is listening.',
example: '/feedback',
},
disablePasswordAuth: { disablePasswordAuth: {
type: 'boolean', type: 'boolean',
description: description:

View File

@ -142,6 +142,7 @@ class ConfigController extends Controller {
networkViewEnabled: this.config.prometheusApi !== undefined, networkViewEnabled: this.config.prometheusApi !== undefined,
disablePasswordAuth, disablePasswordAuth,
maintenanceMode, maintenanceMode,
feedbackUriPath: this.config.feedbackUriPath,
}; };
this.openApiService.respondWithValidation( this.openApiService.respondWithValidation(

View File

@ -243,4 +243,5 @@ export interface IUnleashConfig {
disableScheduler?: boolean; disableScheduler?: boolean;
isEnterprise: boolean; isEnterprise: boolean;
rateLimiting: IRateLimiting; rateLimiting: IRateLimiting;
feedbackUriPath?: string;
} }