-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup branding to be configurable during the build
Refactor and enhance branding capabilities. Now branding is included from a single directory that contains at least `strings.json`, `manifest.json`, and `favicon.ico`. Any other assets may be placed in the directory and will be copied to the bundled app. Change summary: - Move Konveyor branding assets to a project top-level branding directory - Remove MTA branding assets - Remove profile/branding constants from `env` and client module - Embed branding strings and assets in the common module - `strings.json` is templated to allow the build to adjust asset URL path roots as necessary - `brandingAssetPath()` - server's index.html generation sources the template strings from the common module's branding strings - HeaderApp support brand definitions - client about and masthead to use 'useBranding' hook - `BRANDING` as a relative path is computed from the project root - webpack build source branding assets directly from the common module - Unit tests, snapshots and jest configs updated as necessary Jest changes: - Use `react-i18next` mock from `client/__mocks__` as a more robust mock borrowed from react-i18n repos - Move `setupTests.ts` into `client/src/app/test-config` to keep jest test config code all in the same directory Related changes: - Upgrade rollup to v4, add new rollup plugins (copy, virtual) Signed-off-by: Scott J Dickerson <[email protected]>
- Loading branch information
Showing
42 changed files
with
737 additions
and
305 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"application": { | ||
"title": "Konveyor", | ||
"name": "Konveyor Tackle UI", | ||
"description": "Konveyor/Tackle UI" | ||
}, | ||
"about": { | ||
"displayName": "Konveyor", | ||
"imageSrc": "<%= brandingRoot %>/images/masthead-logo.svg", | ||
"documentationUrl": "https://konveyor.github.io/konveyor/" | ||
}, | ||
"masthead": { | ||
"leftBrand": { | ||
"src": "<%= brandingRoot %>/images/masthead-logo.svg", | ||
"alt": "brand", | ||
"height": "60px" | ||
}, | ||
"leftTitle": null, | ||
"rightBrand": null | ||
} | ||
} |
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,68 @@ | ||
/* eslint-env node */ | ||
|
||
// Adapted from https://github.com/i18next/react-i18next/blob/master/example/test-jest/src/__mocks__/react-i18next.js | ||
import React from "react"; | ||
import * as reactI18next from "react-i18next"; | ||
|
||
const hasChildren = (node) => | ||
node && (node.children || (node.props && node.props.children)); | ||
|
||
const getChildren = (node) => | ||
node && node.children ? node.children : node.props && node.props.children; | ||
|
||
const renderNodes = (reactNodes) => { | ||
if (typeof reactNodes === "string") { | ||
return reactNodes; | ||
} | ||
|
||
return Object.keys(reactNodes).map((key, i) => { | ||
const child = reactNodes[key]; | ||
const isElement = React.isValidElement(child); | ||
|
||
if (typeof child === "string") { | ||
return child; | ||
} | ||
if (hasChildren(child)) { | ||
const inner = renderNodes(getChildren(child)); | ||
return React.cloneElement(child, { ...child.props, key: i }, inner); | ||
} | ||
if (typeof child === "object" && !isElement) { | ||
return Object.keys(child).reduce( | ||
(str, childKey) => `${str}${child[childKey]}`, | ||
"" | ||
); | ||
} | ||
|
||
return child; | ||
}); | ||
}; | ||
|
||
const useMock = [(k) => k, { changeLanguage: () => new Promise(() => {}) }]; | ||
useMock.t = (k) => k; | ||
useMock.i18n = { changeLanguage: () => new Promise(() => {}) }; | ||
|
||
module.exports = { | ||
// Note: Ignoring "withTranslation" HOC. We don't use it. | ||
|
||
Trans: ({ children, i18nKey }) => | ||
!children | ||
? i18nKey | ||
: Array.isArray(children) | ||
? renderNodes(children) | ||
: renderNodes([children]), | ||
|
||
Translation: ({ children }) => children((k) => k, { i18n: {} }), | ||
|
||
useTranslation: () => useMock, | ||
|
||
// mock if needed | ||
I18nextProvider: reactI18next.I18nextProvider, | ||
initReactI18next: { | ||
type: "3rdParty", | ||
init: () => {}, | ||
}, | ||
setDefaults: reactI18next.setDefaults, | ||
getDefaults: reactI18next.getDefaults, | ||
setI18n: reactI18next.setI18n, | ||
getI18n: reactI18next.getI18n, | ||
}; |
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
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { BrandingStrings, brandingStrings } from "@konveyor-ui/common"; | ||
|
||
/** | ||
* Wrap the branding strings in a hook so components access it in a standard | ||
* React way instead of a direct import. This allows the branding implementation | ||
* to change in future with a minimal amount of refactoring in existing components. | ||
*/ | ||
export const useBranding = (): BrandingStrings => { | ||
return brandingStrings; | ||
}; | ||
|
||
export default useBranding; |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.