refactor
This commit is contained in:
@@ -16,15 +16,15 @@ export const resolveApiPath = (path = '') => path;
|
||||
const makeRowKey = (type, id) =>
|
||||
id ? `${type}${ROW_KEY_SEPARATOR}${id}` : `${type}${ROW_KEY_SEPARATOR}`;
|
||||
|
||||
const getRowType = (key) => (
|
||||
typeof key?.split === 'function' ? key.split(ROW_KEY_SEPARATOR, 1)[0] : ''
|
||||
);
|
||||
const normalizeRowKey = (key: string | number | null | undefined) => String(key ?? '');
|
||||
|
||||
const getRowType = (key) => normalizeRowKey(key).split(ROW_KEY_SEPARATOR, 1)[0] ?? '';
|
||||
|
||||
export const getRowId = (key) => {
|
||||
if (typeof key?.indexOf !== 'function' || typeof key?.slice !== 'function') return '';
|
||||
const separatorIndex = key.indexOf(ROW_KEY_SEPARATOR);
|
||||
if (separatorIndex === -1) return key;
|
||||
return key.slice(separatorIndex + 1);
|
||||
const normalized = normalizeRowKey(key);
|
||||
const separatorIndex = normalized.indexOf(ROW_KEY_SEPARATOR);
|
||||
if (separatorIndex === -1) return normalized;
|
||||
return normalized.slice(separatorIndex + 1);
|
||||
};
|
||||
|
||||
export const isDocumentRowKey = (key) => getRowType(key) === DOCUMENT_ROW_PREFIX;
|
||||
|
||||
Reference in New Issue
Block a user