-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify changed version card message logic
- Loading branch information
1 parent
96b52f3
commit 0bb039f
Showing
5 changed files
with
30 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,22 @@ | ||
import { escapeRegExp, keyBy } from 'lodash'; | ||
|
||
export const getFieldLabels = (intl, paths, labelsMap = {}, hiddenFields = [], systemUpdatedFields = []) => { | ||
if (!paths) return { changedFields: [], systemChanges: [] }; | ||
export const getFieldLabels = (intl, paths, labelsMap = {}, hiddenFields = []) => { | ||
if (!paths) return null; | ||
|
||
const labelsMapEntries = Object.entries(labelsMap); | ||
const hiddenFieldsMap = keyBy(hiddenFields); | ||
|
||
const { changedFields, systemChanges } = paths.reduce((acc, path) => { | ||
return paths.reduce((acc, path) => { | ||
const fieldLabel = labelsMapEntries.find(([fieldPath]) => { | ||
const regex = new RegExp(`^${escapeRegExp(fieldPath).replaceAll('\\\\d', '\\d')}$`); | ||
const regex = new RegExp(`^${escapeRegExp(fieldPath).replace('\\\\d', '\\d')}$`); | ||
|
||
return regex.test(path); | ||
})?.[1] || path; | ||
|
||
if (systemUpdatedFields.includes(path.replace(/\[\d+\]/g, ''))) { | ||
acc.systemChanges.push(fieldLabel); | ||
} else if (!hiddenFieldsMap[fieldLabel]) { | ||
acc.changedFields.push(intl.formatMessage({ id: fieldLabel })); | ||
if (!hiddenFieldsMap[fieldLabel]) { | ||
acc.push(intl.formatMessage({ id: fieldLabel })); | ||
} | ||
|
||
return acc; | ||
}, { changedFields: [], systemChanges: [] }); | ||
|
||
return { | ||
changedFields: changedFields.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())), | ||
systemChanges, | ||
isSystemChange: !changedFields.length && systemChanges.length, | ||
}; | ||
}, []).sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters