Skip to content

Commit

Permalink
MGMT-15159: Extract the assisted-service types into a package (opensh…
Browse files Browse the repository at this point in the history
…ift-assisted#2246)

* Adds @openshift-assisted/types

The package provides general type definitions.  
Including:
- assisted-installer-service
- accounts-management-service (non-comprehensive)

* Cleans up the scripts used to update the API types inside ui-lib

* Removes env-cmd

* Adds type definitions for the locales package

* Removes the file extensions from the import statements

* Adds eslint settings for the locales package

* Read the version from package.json in non-standalone deployments

* Produces a CommonJS build of the ui-lib

* Migrates the entire code-base to @openshift-assisted/types

- The commit adds a basic client for AMS, used to retrieve the pull-secret.
- CI workflow adjusted in order to pick up automatically the workspaces that are meant to be published to NPM.
- Release docs updated as well

* Docs updates

* Introduces the tools workspace

The tools workspace is meant to hold packages that are used for the internal maintenance  of the monorepo

* Introduces `watch` and `start` as top-level scripts 

The projects has 2 modes of development, watch-mode and through the stand-alone UI. The commit simplifies starting the main workflows.
Scripts prefixed with _* are internal. All the rest can be used for something useful within our workflows.
Additionally, the types for the Assisted Installer service can be updated by running `yarn update:assisted-installer-service`.

* Separates the declarations from the JSON files in the locales library

+tidy up the ESLint configuration file

* Adds no-debugger to ESLint rules.

* Do not build:all in cy:dev:open script

* Fixes the ocm-client not being initialized correctly

It was being initialized when the `HostsClusterDetailsTabMock` was first rendered instead of being rendered when the module was evaluated for the first time (as a transitive import)

* Removes the getOcmClient function from axiosClient.ts

* Simplifies the AMS (mini) client

* Adds a top-level test:open:dev script

* Allows the integration tests code to control when the `setAuthInterceptor` should be called.

* Fixes duplicated identifiers after rebasing

* More docs updates and adds check_types scripts for locales and types
  • Loading branch information
jkilzi authored Aug 23, 2023
1 parent 7d307ac commit d27ea9b
Show file tree
Hide file tree
Showing 307 changed files with 1,359 additions and 8,258 deletions.
93 changes: 70 additions & 23 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
{
"root": true,
"env": {
"browser": true,
"es6": true,
"node": true
},
"ignorePatterns": ["apps/*/build", "libs/*/build", "libs/*/@types"],
"parserOptions": {
"project": [
"apps/*/tsconfig.json",
"apps/*/tsconfig.eslint.json",
"libs/*/tsconfig.json",
"libs/*/tsconfig.eslint.json"
]
},
"rules": {
"eqeqeq": ["error", "always"],
"indent": "off",
"no-debugger": "error"
},
"ignorePatterns": ["apps/*/build", "libs/*/build", "tools/*/build"],
"overrides": [
{
"files": [
"scripts/*.cjs",
"apps/*/scripts/*.cjs",
"libs/*/scripts/*.cjs",
"tools/*/scripts/*.cjs"
],
"extends": ["eslint:recommended", "prettier"],
"env": {
"browser": false
},
"extends": ["eslint:recommended", "prettier"],
"files": ["scripts/*.cjs", "apps/*/scripts/*.cjs", "libs/*/scripts/*.cjs"],
"rules": {
"no-console": "off"
}
},
{
"files": [
"scripts/*.{js,mjs}",
"apps/*/scripts/*.{js,mjs}",
"libs/*/scripts/*.{js,mjs}",
"tools/*/scripts/*.{js,mjs}"
],
"extends": ["eslint:recommended", "prettier"],
"env": {
"browser": false
},
"extends": ["eslint:recommended", "prettier"],
"files": ["scripts/*.{js,mjs}", "apps/*/scripts/*.{js,mjs}", "libs/*/scripts/*.{js,mjs}"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": "latest"
Expand All @@ -31,12 +55,35 @@
}
},
{
"files": ["tools/eslint-config-assisted-ui/lib/**/*.ts"],
"extends": ["@openshift-assisted/eslint-config-assisted-ui"],
"env": {
"browser": false
},
"rules": {
"no-console": "off"
}
},
{
"files": ["tools/toolbox/lib/**/*.ts"],
"extends": ["@openshift-assisted/eslint-config-assisted-ui"],
"env": {
"browser": false
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": "latest"
},
"rules": {
"no-console": "off"
}
},
{
"files": ["libs/locales/@types/**/*.d.ts"],
"extends": ["@openshift-assisted/eslint-config-assisted-ui"],
"files": ["libs/toolbox/lib/**/*.ts"],
"parserOptions": {
"tsconfigRootDir": "libs/locales",
"project": "tsconfig.json",
"sourceType": "module",
"ecmaVersion": "latest"
},
Expand All @@ -45,8 +92,21 @@
}
},
{
"files": ["libs/types/lib/**/*.ts"],
"extends": ["@openshift-assisted/eslint-config-assisted-ui"],
"parserOptions": {
"tsconfigRootDir": "libs/types",
"project": "tsconfig.eslint.json",
"sourceType": "module",
"ecmaVersion": "latest"
},
"rules": {
"no-console": "off"
}
},
{
"files": ["libs/ui-lib/lib/**/*.{ts,tsx}"],
"extends": ["@openshift-assisted/eslint-config-assisted-ui"],
"parserOptions": {
"tsconfigRootDir": "libs/ui-lib",
"project": "tsconfig.eslint.json"
Expand All @@ -68,11 +128,11 @@
}
},
{
"files": ["apps/assisted-ui/vite.config.ts"],
"extends": ["@openshift-assisted/eslint-config-assisted-ui"],
"env": {
"browser": false
},
"extends": ["@openshift-assisted/eslint-config-assisted-ui"],
"files": ["apps/assisted-ui/vite.config.ts"],
"parserOptions": {
"tsconfigRootDir": "apps/assisted-ui"
},
Expand All @@ -81,8 +141,8 @@
}
},
{
"extends": ["@openshift-assisted/eslint-config-assisted-ui", "plugin:react/jsx-runtime"],
"files": ["apps/assisted-ui/src/**/*.{ts,tsx}"],
"extends": ["@openshift-assisted/eslint-config-assisted-ui", "plugin:react/jsx-runtime"],
"parserOptions": {
"tsconfigRootDir": "apps/assisted-ui",
"EXPERIMENTAL_useSourceOfProjectReferenceRedirect": true
Expand All @@ -106,18 +166,5 @@
]
}
}
],
"parserOptions": {
"project": [
"apps/*/tsconfig.json",
"apps/*/tsconfig.eslint.json",
"libs/*/tsconfig.json",
"libs/*/tsconfig.eslint.json"
]
},
"root": true,
"rules": {
"eqeqeq": ["error", "always"],
"indent": "off"
}
]
}
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
cache: yarn
- run: yarn install --immutable
- run: yarn build:all
- run: yarn check_circular_deps:all
- run: yarn check:circular_deps:all
unit-tests:
needs: preflight-check
if: needs.preflight-check.outputs.skip == 'false'
Expand Down
26 changes: 20 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ jobs:
echo "Expecting to be in a release branch, but we are in: ${{ github.event.release.target_commitish }}"
exit 1
fi
- uses: actions/checkout@v3
with:
token: ${{ secrets.PUSH_TO_PROTECTED_BRANCH }}
ref: ${{ github.event.release.target_commitish }}
fetch-depth: 0

- name: Lookup for workspaces to be published
run: |
declare -a workspaces=()
for pkg in `ls -1 libs/*/package.json`; do
if [[ "$(jq '.publishConfig.access == "public"' ${pkg})" == "true" ]]; then
workspaces+=("${pkg:5:-13}")
fi
done
(IFS=,; printf 'The following workspaces will be published: [%s]' "${workspaces[*]}")
echo "WORKSPACES=${workspaces}" >> $GITHUB_ENV
- name: Configuring git
run: |
git config user.name '${{ github.actor }}'
Expand All @@ -39,8 +51,7 @@ jobs:

- name: Bump workspaces to ${{ github.ref_name }}
run: |
workspaces=(ui-lib locales)
for ws in "${workspaces[@]}"; do
for ws in "${WORKSPACES[@]}"; do
yarn workspace @openshift-assisted/${ws} version ${GITHUB_REF_NAME:1}
# The above command adds a `stableVersion` field after bumping. Removing it as it's buggy.
# See: https://github.com/yarnpkg/berry/issues/4328
Expand All @@ -55,10 +66,13 @@ jobs:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: |
yarn config set npmScopes.openshift-assisted.npmAuthToken $NPM_AUTH_TOKEN
yarn workspace @openshift-assisted/ui-lib npm publish
# Sleep ${{ vars.NPM_PUBLISH_DELAY }} in order to give time for processing the previously published package.
sleep ${{ vars.NPM_PUBLISH_DELAY }}
yarn workspace @openshift-assisted/locales npm publish
for ws in "${WORKSPACES[@]}"; do
yarn workspace @openshift-assisted/${ws} npm publish
# Verify the package has been published before publishing another one.
until yarn info @openshift-assisted/${ws} &> /dev/null; do
sleep ${{ vars.NPM_PUBLISH_DELAY }}
done
done
- name: Update the repo
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ npm-*.log*
yarn-*.log*
## Since we use yarn
package-lock.json
## Relevant to yarn 2 without zero-installs
# Swap the comments on the following lines if you don't wish to use zero-installs
# Documentation here: https://yarnpkg.com/features/zero-installs
#!.yarn/cache
.pnp.*
.yarn/*
!.yarn/patches
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
.idea
apps/*/build
libs/*/build
libs/*/@types
tools/*/build
libs/ui-lib-tests/cypress/fixtures/*/files
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<h1 align="center">
The Assisted Installer User Interface
Assisted Installer User Interface
</h1>

## Documentation

- [How to contribute](docs/CONTRIBUTING.md)
- [Contributing](docs/CONTRIBUTING.md)
- [Development](docs/DEVELOPMENT.md)
- [I18N documentation](docs/I18N.md)
- [Release process](docs/RELEASE_WORKFLOW.md)

## License

This project is [Apache 2.0](LICENSE) licensed and accepts contributions via GitHub pull requests.
This project is Apache-2.0 licensed, please read the [contributing](docs/CONTRIBUTING.md) section
for more details.
7 changes: 7 additions & 0 deletions apps/assisted-ui/src/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module 'global-augmentations' {
global {
interface Window {
__app__: { OCM: typeof import('@openshift-assisted/ui-lib/ocm') };
}
}
}
24 changes: 18 additions & 6 deletions apps/assisted-ui/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { BrowserRouter, Route } from 'react-router-dom';
import { Page } from '@patternfly/react-core';
import { Features, Router as LibRouter, Store } from '@openshift-assisted/ui-lib/ocm';
import Header from './components/Header.jsx';
import BackgroundImage from './components/BackgroundImage.jsx';
import '../../i18n.js';
import * as OCM from '@openshift-assisted/ui-lib/ocm';
import Header from './components/Header';
import BackgroundImage from './components/BackgroundImage';
import '../../i18n';

const {
HostsClusterDetailTabMock: Day2AddHostsMock,
Router: LibRouter,
Features,
Store,
Config,
} = OCM;
window.__app__ = { OCM };
const { routeBasePath } = Config;
const { store } = Store;

const App = () => (
Expand All @@ -18,9 +27,12 @@ const App = () => (
isManagedSidebar
defaultManagedSidebarIsOpen={false}
>
<LibRouter features={Features.STANDALONE_DEPLOYMENT_ENABLED_FEATURES} />
<LibRouter features={Features.STANDALONE_DEPLOYMENT_ENABLED_FEATURES}>
<Route path={`${routeBasePath}/day2-flow-mock`} component={Day2AddHostsMock} />
</LibRouter>
</Page>
</BrowserRouter>
</Provider>
);

export default App;
12 changes: 3 additions & 9 deletions apps/assisted-ui/src/components/App/components/AboutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ import {
TextContent,
ButtonVariant,
} from '@patternfly/react-core';
import { GIT_SHA, VERSION, SERVICE_LABELS, IMAGE_REPO } from '../../../config.js';
import { GIT_SHA, VERSION, SERVICE_LABELS, IMAGE_REPO } from '../../../config';
import redHatLogo from '../../../images/Logo-Red_Hat-OpenShift_Container_Platform-B-Reverse-RGB.png';
import {
Services,
Api,
Constants,
DetailList,
DetailItem,
ListVersions,
} from '@openshift-assisted/ui-lib/ocm';
import { Services, Api, Constants, DetailList, DetailItem } from '@openshift-assisted/ui-lib/ocm';
import { ListVersions } from '@openshift-assisted/types/assisted-installer-service';

export const AboutModalButton: React.FC = () => {
const [isModalOpen, setIsModalOpen] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion apps/assisted-ui/src/components/App/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Brand, PageHeader, PageHeaderTools, Button, ButtonVariant } from '@patt
import { ExternalLinkAltIcon } from '@patternfly/react-icons';
import upstreamLogo from '../../../images/metal3_facet-whitetext.png';
import redhatLogo from '../../../images/Logo-Red_Hat-OpenShift_Container_Platform-B-Reverse-RGB.png';
import AboutModalButton from './AboutModal.js';
import AboutModalButton from './AboutModal';

const { getProductBrandingCode, FEEDBACK_FORM_LINK } = Constants;

Expand Down
2 changes: 0 additions & 2 deletions apps/assisted-ui/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import translation from '@openshift-assisted/locales/en/translation.json';

const dateTimeFormatter = new Intl.DateTimeFormat('default', {
Expand Down
2 changes: 1 addition & 1 deletion apps/assisted-ui/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App/App.js';
import App from './components/App/App';

const rootElement = document.getElementById('root');
ReactDOM.render(
Expand Down
Loading

0 comments on commit d27ea9b

Please sign in to comment.