( hasLicense: boolean, features: Record<string, Feature>, )
| 6 | * @returns record from feature name whether to show the feature |
| 7 | */ |
| 8 | export const getFeatureVisibility = ( |
| 9 | hasLicense: boolean, |
| 10 | features: Record<string, Feature>, |
| 11 | ): Record<string, boolean> => { |
| 12 | if (!hasLicense) { |
| 13 | return {}; |
| 14 | } |
| 15 | |
| 16 | const permissionPairs = Object.entries(features).map( |
| 17 | ([feature, { entitlement, limit, actual, enabled }]) => { |
| 18 | const entitled = ["entitled", "grace_period"].includes(entitlement); |
| 19 | const limitCompliant = limit && actual ? limit >= actual : true; |
| 20 | return [feature, entitled && limitCompliant && enabled]; |
| 21 | }, |
| 22 | ); |
| 23 | return Object.fromEntries(permissionPairs); |
| 24 | }; |
| 25 | |
| 26 | export const selectFeatureVisibility = ( |
| 27 | entitlements: Entitlements, |
no outgoing calls
no test coverage detected