- Notifications
You must be signed in to change notification settings - Fork928
Proof of concept for licensing#3008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
Uh oh!
There was an error while loading.Please reload this page.
Closed
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
31ae8eb
Add stubbed api call
presleypead0ab4
Add licenseXService
presleyp9aa9f04
add LicenseBanner that calls xservice
presleypcd600e2
Mount license banner
presleyp3716612
Show stub audit log page if feature enabled
presleypd372600
Move audit page and add nav link
presleyp0ae85e3
Example smaller feature
presleypFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletionssite/src/AppRouter.tsx
This file contains hidden or 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
27 changes: 27 additions & 0 deletionssite/src/api/api.ts
This file contains hidden or 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
14 changes: 14 additions & 0 deletionssite/src/api/types.ts
This file contains hidden or 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
2 changes: 2 additions & 0 deletionssite/src/app.tsx
This file contains hidden or 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
20 changes: 20 additions & 0 deletionssite/src/components/LicenseBanner/LicenseBanner.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useActor } from "@xstate/react" | ||
import { useContext, useEffect } from "react" | ||
import { XServiceContext } from "../../xServices/StateContext" | ||
export const LicenseBanner: React.FC = () => { | ||
const xServices = useContext(XServiceContext) | ||
const [licenseState, licenseSend] = useActor(xServices.licenseXService) | ||
const warnings = licenseState.context.licenseData.warnings | ||
/** Gets license data on app mount because LicenseBanner is mounted in App */ | ||
useEffect(() => { | ||
licenseSend("GET_LICENSE_DATA") | ||
}, [licenseSend]) | ||
if (warnings) { | ||
return <div>{warnings.map((warning, i) => <p key={`${i}`}>{warning}</p>)}</div> | ||
} else { | ||
return null | ||
} | ||
} |
7 changes: 5 additions & 2 deletionssite/src/components/Navbar/Navbar.tsx
This file contains hidden or 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
11 changes: 10 additions & 1 deletionsite/src/components/NavbarView/NavbarView.tsx
This file contains hidden or 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
24 changes: 24 additions & 0 deletionssite/src/components/RequireLicense/RequireLicense.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useSelector } from "@xstate/react" | ||
import React, { useContext } from "react" | ||
import { Navigate } from "react-router" | ||
import { FullScreenLoader } from "../Loader/FullScreenLoader" | ||
import { XServiceContext } from "../../xServices/StateContext" | ||
import { selectLicenseVisibility } from "../../xServices/license/licenseSelectors" | ||
import { LicensePermission } from "../../api/types" | ||
export interface RequireLicenseProps { | ||
children: JSX.Element | ||
permissionRequired: LicensePermission | ||
} | ||
export const RequireLicense: React.FC<RequireLicenseProps> = ({ children, permissionRequired }) => { | ||
const xServices = useContext(XServiceContext) | ||
const visibility = useSelector(xServices.licenseXService, selectLicenseVisibility) | ||
if (!visibility) { | ||
return <FullScreenLoader /> | ||
} else if (!visibility[permissionRequired]) { | ||
return <Navigate to="/not-found" /> | ||
} else { | ||
return children | ||
} | ||
} |
2 changes: 2 additions & 0 deletionssite/src/components/Workspace/Workspace.tsx
This file contains hidden or 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
9 changes: 7 additions & 2 deletionssite/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx
This file contains hidden or 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
9 changes: 9 additions & 0 deletionssite/src/components/WorkspaceScheduleButton/CELAdminScheduleLabel.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
const Language = { | ||
orgDefault: "Org default:" | ||
} | ||
export const CELAdminScheduleLabel: React.FC = () => { | ||
return <span>{Language.orgDefault} </span> | ||
} |
10 changes: 10 additions & 0 deletionssite/src/components/WorkspaceScheduleButton/CELChangeScheduleLink.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
const Language = { | ||
overrideScheduleLink: "Override Schedule" | ||
} | ||
export const CELChangeScheduleLink: React.FC = () => { | ||
return <span>{Language.overrideScheduleLink}</span> | ||
} | ||
9 changes: 9 additions & 0 deletionssite/src/components/WorkspaceScheduleButton/OSSChangeScheduleLink.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
const Language = { | ||
editScheduleLink: "Edit Schedule" | ||
} | ||
export const OSSChangeScheduleLink: React.FC = () => { | ||
return <span>{Language.editScheduleLink}</span> | ||
} |
6 changes: 5 additions & 1 deletionsite/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.tsx
This file contains hidden or 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
5 changes: 5 additions & 0 deletionssite/src/pages/AuditLogPage/AuditLogPage.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const AuditLogPage = () => { | ||
return <div> | ||
This is a stub for the audit log page. | ||
</div> | ||
} |
3 changes: 3 additions & 0 deletionssite/src/pages/WorkspacePage/WorkspacePage.tsx
This file contains hidden or 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
3 changes: 3 additions & 0 deletionssite/src/xServices/StateContext.tsx
This file contains hidden or 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
24 changes: 24 additions & 0 deletionssite/src/xServices/license/licenseSelectors.ts
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { State } from "xstate" | ||
import { LicensePermission } from "../../api/types" | ||
import { LicenseContext, LicenseEvent } from "./licenseXService" | ||
type LicenseState = State<LicenseContext, LicenseEvent> | ||
export const selectLicenseVisibility = (state: LicenseState): Record<LicensePermission, boolean> => { | ||
const features = state.context.licenseData.features | ||
const featureNames = Object.keys(features) as LicensePermission[] | ||
const visibilityPairs = featureNames.map((feature: LicensePermission) => { | ||
return [feature, features[feature].enabled] | ||
}) | ||
return Object.fromEntries(visibilityPairs) | ||
} | ||
export const selectLicenseEntitlement = (state: LicenseState): Record<LicensePermission, boolean> => { | ||
const features = state.context.licenseData.features | ||
const featureNames = Object.keys(features) as LicensePermission[] | ||
const permissionPairs = featureNames.map((feature: LicensePermission) => { | ||
const { entitled, limit, actual } = features[feature] | ||
const limitCompliant = limit && actual && limit >= actual | ||
return [feature, entitled && limitCompliant] | ||
}) | ||
return Object.fromEntries(permissionPairs) | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.