fix(ui): pick right mode env production / dev (#23272)

* fix(ui): pick right mode env production / dev

* fix unit tests
This commit is contained in:
Chirag Madlani 2025-09-05 23:06:30 +05:30 committed by GitHub
parent b6f9ed4a5b
commit cb5bcdbb9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 13 deletions

View File

@ -144,3 +144,7 @@ jest.mock('./utils/AdvancedSearchClassBase', () => {
},
};
});
jest.mock('./utils/EnvironmentUtils', () => ({
isDev: jest.fn().mockReturnValue('test'),
}));

View File

@ -11,10 +11,15 @@
* limitations under the License.
*/
import process from 'process';
const development: boolean = (() => {
// Use Vite's import.meta.env which is properly typed now
if (typeof import.meta !== 'undefined' && import.meta.env) {
return import.meta.env.MODE === 'development';
}
const development: boolean =
!process.env.NODE_ENV || process.env.NODE_ENV === 'development';
// Fallback to process.env (defined by Vite's define option)
return !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
})();
export const isDev = (): boolean => {
return development;

View File

@ -371,7 +371,7 @@ class ServiceUtilClassBase {
return EntityType.TABLE;
}
public getServiceLogo(type: string) {
public getServiceLogo(type: string): string {
const serviceTypes = this.getSupportedServiceFromList();
switch (toLower(type)) {
case this.DatabaseServiceTypeSmallCase.CustomDatabase:
@ -684,7 +684,7 @@ class ServiceUtilClassBase {
public getServiceTypeLogo(
searchSource: SearchSuggestions[number] | SearchSourceAlias
) {
): string {
const type = get(searchSource, 'serviceType', '');
const entityType = get(searchSource, 'entityType', '');

View File

@ -57,9 +57,9 @@ export const formatDateTimeLong = (timestamp?: number, format?: string) => {
return '';
}
return DateTime.fromMillis(toNumber(timestamp), { locale: i18next.language }).toFormat(
format ?? DATE_TIME_WITH_OFFSET_FORMAT
);
return DateTime.fromMillis(toNumber(timestamp), {
locale: i18next.language,
}).toFormat(format ?? DATE_TIME_WITH_OFFSET_FORMAT);
};
/**
@ -121,9 +121,9 @@ export const customFormatDateTime = (
return formatDateTime(milliseconds);
}
return DateTime.fromMillis(milliseconds, { locale: i18next.language }).toFormat(
format
);
return DateTime.fromMillis(milliseconds, {
locale: i18next.language,
}).toFormat(format);
};
/**
@ -133,7 +133,9 @@ export const customFormatDateTime = (
*/
export const getRelativeTime = (timeStamp?: number): string => {
return !isNil(timeStamp)
? DateTime.fromMillis(timeStamp, { locale: i18next.language }).toRelative() ?? ''
? DateTime.fromMillis(timeStamp, {
locale: i18next.language,
}).toRelative() ?? ''
: '';
};
@ -176,7 +178,9 @@ export const getRelativeCalendar = (
baseTimeStamp?: number
): string => {
return capitalize(
DateTime.fromMillis(timeStamp, { locale: i18next.language }).toRelativeCalendar({
DateTime.fromMillis(timeStamp, {
locale: i18next.language,
}).toRelativeCalendar({
base: baseTimeStamp
? DateTime.fromMillis(baseTimeStamp, { locale: i18next.language })
: DateTime.now(),

View File

@ -0,0 +1,26 @@
/*
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// eslint-disable-next-line spaced-comment
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly MODE: string;
readonly BASE_URL: string;
readonly PROD: boolean;
readonly DEV: boolean;
// Add other env variables as needed
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}