Skip to content

Commit 29e84a8

Browse files
committed
refactor: replace localized no records message function with generic fields localization
1 parent 406ed63 commit 29e84a8

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

packages/react-sdk-components/src/components/helpers/common-utils.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@ export function isEmptyObject(obj: Object): boolean {
22
return Object.keys(obj).length === 0;
33
}
44

5-
export function getLocalizedNoRecordsMessage(): string {
5+
/**
6+
* Get a localized value from the Generic Fields
7+
* @param path - The path within Generic Fields (e.g., 'CosmosFields.fields.lists')
8+
* @param key - The key of the string to localize
9+
* @returns The localized string or the key itself if no translation is found
10+
*/
11+
export function getGenericFieldsLocalizedValue(path: string, key: string): string {
612
const GENERIC_BUNDLE_KEY = PCore.getLocaleUtils().GENERIC_BUNDLE_KEY;
7-
return PCore.getLocaleUtils().localeStore[GENERIC_BUNDLE_KEY]?.CosmosFields?.fields?.lists?.['No records found.'] || 'No records found.';
13+
const localeStore = PCore.getLocaleUtils().localeStore[GENERIC_BUNDLE_KEY];
14+
15+
if (!localeStore) return key;
16+
17+
// Split the path and traverse the object
18+
const pathParts = path.split('.');
19+
let currentObj = localeStore;
20+
21+
for (const part of pathParts) {
22+
if (!currentObj[part]) return key;
23+
currentObj = currentObj[part];
24+
}
25+
26+
return currentObj[key] || key;
827
}

packages/react-sdk-components/src/components/template/ListView/ListView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { filterData } from '../../helpers/simpleTableHelpers';
4343
import './ListView.css';
4444
import { getDateFormatInfo } from '../../helpers/date-format-utils';
4545
import { getCurrencyOptions } from '../../field/Currency/currency-utils';
46-
import { getLocalizedNoRecordsMessage } from '../../helpers/common-utils';
46+
import { getGenericFieldsLocalizedValue } from '../../helpers/common-utils';
4747
import { format } from '../../helpers/formatters';
4848

4949
import useInit from './hooks';
@@ -1130,7 +1130,9 @@ export default function ListView(props: ListViewProps) {
11301130
})}
11311131
</TableBody>
11321132
</Table>
1133-
{arRows && arRows.length === 0 && <div className='no-records'>{getLocalizedNoRecordsMessage()}</div>}
1133+
{arRows && arRows.length === 0 && (
1134+
<div className='no-records'>{getGenericFieldsLocalizedValue('CosmosFields.fields.lists', 'No records found.')}</div>
1135+
)}
11341136
</TableContainer>
11351137
)}
11361138
</>

packages/react-sdk-components/src/components/template/SimpleTable/SimpleTableManual/SimpleTableManual.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import createPConnectComponent from '../../../../bridge/react_pconnect';
2727
import { Utils } from '../../../helpers/utils';
2828
import { getReferenceList } from '../../../helpers/field-group-utils';
2929
import { getDataPage } from '../../../helpers/data_page';
30-
import { getLocalizedNoRecordsMessage } from '../../../helpers/common-utils';
30+
import { getGenericFieldsLocalizedValue } from '../../../helpers/common-utils';
3131
import { buildFieldsForTable, filterData, getContext } from '../../../helpers/simpleTableHelpers';
3232
import { PConnProps } from '../../../../types/PConnProps';
3333
import { format } from '../../../helpers/formatters';
@@ -712,7 +712,7 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
712712
</Table>
713713
{((readOnlyMode && (!rowData || rowData?.length === 0)) || (editableMode && (!referenceList || referenceList?.length === 0))) && (
714714
<div className='no-records' id='no-records'>
715-
{getLocalizedNoRecordsMessage()}
715+
{getGenericFieldsLocalizedValue('CosmosFields.fields.lists', 'No records found.')}
716716
</div>
717717
)}
718718
</TableContainer>

0 commit comments

Comments
 (0)