-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
544 additions
and
2 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
109 changes: 109 additions & 0 deletions
109
packages/apps/esm-implementer-tools-app/src/feature-flags/feature-flags.component.tsx
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { Fragment, useMemo } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { | ||
DataTable, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
Toggle, | ||
} from "@carbon/react"; | ||
import styles from "./frontend-modules.scss"; | ||
import { registerFeatureFlag, useStore } from "@openmrs/esm-framework"; | ||
import { | ||
featureFlagsStore, | ||
setFeatureFlag, | ||
} from "@openmrs/esm-framework/src/internal"; | ||
|
||
export function FeatureFlags() { | ||
const { flags } = useStore(featureFlagsStore); | ||
const { t } = useTranslation(); | ||
|
||
const headers = useMemo( | ||
() => [ | ||
{ | ||
key: "label", | ||
header: t("featureFlag", "Feature Flag"), | ||
}, | ||
{ | ||
key: "description", | ||
header: t("description", "Description"), | ||
}, | ||
{ | ||
key: "enabled", | ||
header: t("enabled", "Enabled"), | ||
}, | ||
], | ||
[t] | ||
); | ||
|
||
const rows = useMemo(() => { | ||
return Object.entries(flags) | ||
.sort(([ka, va], [kb, vb]) => { | ||
return (va.label ?? ka).localeCompare(vb.label || kb); | ||
}) | ||
.map(([name, { enabled, label, description }]) => ({ | ||
name, | ||
enabled, | ||
label, | ||
description, | ||
})); | ||
}, [flags]); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<DataTable rows={[]} headers={headers}> | ||
{({ headers, getTableProps, getHeaderProps }) => ( | ||
<TableContainer title=""> | ||
<Table {...getTableProps()}> | ||
<TableHead> | ||
<TableRow> | ||
{headers.map((header) => ( | ||
<TableHeader {...getHeaderProps({ header })}> | ||
{header.header} | ||
</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((flag) => ( | ||
<Fragment key={flag.name}> | ||
<TableRow> | ||
<TableCell> | ||
<div | ||
id={`flag-label-${flag.name}`} | ||
className={styles.header} | ||
> | ||
{flag.label} | ||
</div> | ||
<div className={styles.helper}>{flag.name}</div> | ||
</TableCell> | ||
<TableCell> | ||
<span>{flag.description}</span> | ||
</TableCell> | ||
<TableCell> | ||
<Toggle | ||
id={`feature-flag-${flag.name}-toggle`} | ||
aria-labelledby={`flag-label-${flag.name}`} | ||
labelText="" // using aria-labelledby instead | ||
hideLabel={true} | ||
toggled={flag.enabled} | ||
onToggle={() => | ||
setFeatureFlag(flag.name, !flag.enabled) | ||
} | ||
/> | ||
</TableCell> | ||
</TableRow> | ||
</Fragment> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
)} | ||
</DataTable> | ||
</div> | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/apps/esm-implementer-tools-app/src/feature-flags/frontend-modules.scss
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@use "@carbon/styles/scss/type"; | ||
|
||
.container { | ||
height: 50vh; | ||
overflow-y: auto; | ||
|
||
:global(.cds--data-table-container) { | ||
padding-top: 0; | ||
} | ||
} | ||
|
||
.header { | ||
@include type.type-style("heading-compact-02"); | ||
} | ||
|
||
.helper { | ||
@include type.type-style("helper-text-01"); | ||
} |
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
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 |
---|---|---|
|
@@ -15,4 +15,3 @@ PRs welcome! See | |
[OpenMRS Frontend RFC-20](https://github.com/openmrs/openmrs-rfc-frontend/blob/master/text/0020-contributing-guidelines.md#contributing-guidelines) | ||
for guidelines about contributing. | ||
|
||
Maintainer: Brandon Istenes ([email protected]) |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# openmrs-esm-feature-flags | ||
|
||
[![npm: openmrs/esm-feature-flags](https://img.shields.io/npm/v/@openmrs/esm-feature-flags)](https://www.npmjs.com/package/@openmrs/esm-feature-flags) | ||
|
||
## What is this? | ||
|
||
This is the feature flags library for [OpenMRS Frontend 3.0](https://wiki.openmrs.org/display/projects/OpenMRS+3.0%3A+A+Frontend+Framework+that+enables+collaboration+and+better+User+Experience). | ||
|
||
Please see the [Developer Documentation](https://openmrs.github.io/openmrs-esm-core/#/main/config) | ||
for information about how to use it. | ||
|
||
## Contributing & Development | ||
|
||
PRs welcome! See | ||
[OpenMRS Frontend RFC-20](https://github.com/openmrs/openmrs-rfc-frontend/blob/master/text/0020-contributing-guidelines.md#contributing-guidelines) | ||
for guidelines about contributing. |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
transform: { | ||
"^.+\\.tsx?$": ["@swc/jest"], | ||
}, | ||
testEnvironment: "jsdom", | ||
testEnvironmentOptions: { | ||
url: "http://localhost/", | ||
}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "@openmrs/esm-feature-flags", | ||
"version": "5.0.2", | ||
"license": "MPL-2.0", | ||
"description": "A feature flag system for the OpenMRS Single-Spa framework.", | ||
"browser": "dist/openmrs-esm-feature-flags.js", | ||
"main": "src/index.ts", | ||
"source": true, | ||
"scripts": { | ||
"test": "jest --config jest.config.js --passWithNoTests", | ||
"build": "webpack --mode=production", | ||
"build:development": "webpack --mode development", | ||
"analyze": "webpack --mode=production --env analyze=true", | ||
"typescript": "tsc", | ||
"lint": "eslint src --ext ts,tsx" | ||
}, | ||
"keywords": [ | ||
"openmrs", | ||
"microfrontends" | ||
], | ||
"directories": { | ||
"lib": "dist", | ||
"src": "src" | ||
}, | ||
"browserslist": [ | ||
"extends browserslist-config-openmrs" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/openmrs/openmrs-esm-core.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/openmrs/openmrs-esm-core/issues" | ||
}, | ||
"homepage": "https://github.com/openmrs/openmrs-esm-core#readme", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"ramda": "^0.26.1" | ||
}, | ||
"peerDependencies": { | ||
"@openmrs/esm-globals": "4.x", | ||
"@openmrs/esm-state": "4.x", | ||
"single-spa": "5.x" | ||
}, | ||
"devDependencies": { | ||
"@openmrs/esm-globals": "^5.0.2", | ||
"@openmrs/esm-state": "^5.0.2" | ||
} | ||
} |
Oops, something went wrong.