From 7e3b8271fde92365ca83426e4229b301e8025b65 Mon Sep 17 00:00:00 2001 From: Oleksii Kurinnyi Date: Tue, 10 Dec 2024 18:35:47 +0200 Subject: [PATCH] Full content of the .gitconfig (#1271) * feat: show full content of .gitconfig Signed-off-by: Oleksii Kurinnyi * chore: re-generate list of licenses Signed-off-by: Oleksii Kurinnyi * fixup! feat: show full content of .gitconfig * fixup! chore: re-generate list of licenses * fixup! fixup! feat: show full content of .gitconfig --------- Signed-off-by: Oleksii Kurinnyi --- .deps/EXCLUDED/prod.md | 4 +- .deps/prod.md | 16 +- .../BasicViewer/__mocks__/index.tsx | 29 +++ .../__snapshots__/index.spec.tsx.snap | 11 + .../BasicViewer/__tests__/index.spec.tsx | 43 ++++ .../components/BasicViewer/index.module.css | 23 ++ .../src/components/BasicViewer/index.tsx | 66 ++++++ .../UserPreferences/GitConfig/Form/index.tsx | 10 +- .../GitConfig/Toolbar/__mocks__/index.tsx | 34 +++ .../__snapshots__/index.spec.tsx.snap | 154 +++++++++++++- .../Toolbar/__tests__/index.spec.tsx | 58 +++-- .../GitConfig/Toolbar/index.tsx | 30 ++- .../GitConfig/Viewer/__mocks__/index.tsx | 21 ++ .../GitConfig/Viewer/__tests__/index.spec.tsx | 40 ++++ .../GitConfig/Viewer/index.tsx | 50 +++++ .../__snapshots__/index.spec.tsx.snap | 113 +++------- .../GitConfig/__tests__/index.spec.tsx | 13 ++ .../pages/UserPreferences/GitConfig/index.tsx | 84 +++++--- .../__snapshots__/index.spec.tsx.snap | 198 +++++++++--------- .../src/pages/UserPreferences/index.tsx | 53 ++--- .../yarn/old_version/.deps/EXCLUDED/prod.md | 4 +- scripts/yarn/old_version/.deps/prod.md | 18 +- 22 files changed, 794 insertions(+), 278 deletions(-) create mode 100644 packages/dashboard-frontend/src/components/BasicViewer/__mocks__/index.tsx create mode 100644 packages/dashboard-frontend/src/components/BasicViewer/__tests__/__snapshots__/index.spec.tsx.snap create mode 100644 packages/dashboard-frontend/src/components/BasicViewer/__tests__/index.spec.tsx create mode 100644 packages/dashboard-frontend/src/components/BasicViewer/index.module.css create mode 100644 packages/dashboard-frontend/src/components/BasicViewer/index.tsx create mode 100644 packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__mocks__/index.tsx create mode 100644 packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Viewer/__mocks__/index.tsx create mode 100644 packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Viewer/__tests__/index.spec.tsx create mode 100644 packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Viewer/index.tsx diff --git a/.deps/EXCLUDED/prod.md b/.deps/EXCLUDED/prod.md index 419536d28..9a01bf422 100644 --- a/.deps/EXCLUDED/prod.md +++ b/.deps/EXCLUDED/prod.md @@ -11,9 +11,9 @@ This file lists dependencies that do not need CQs or auto-detection does not wor | `blueimp-md5@2.19.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/blueimp-md5/2.19.0) | | `codemirror@5.65.16` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.16) | | `cookie-signature@1.2.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/cookie-signature/1.2.1) | -| `ecc-jsbn@0.1.2` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/ecc-jsbn/0.1.2) | +| `elliptic@6.6.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/elliptic/6.6.1) | | `fast-uri@2.4.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fast-uri/2.4.0) | | `fastify@4.28.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fastify/4.28.1) | | `jsep@1.3.9` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/jsep/1.3.9) | -| `real-require@0.2.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/real-require/0.2.0) | | `light-my-request@5.14.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/light-my-request/5.14.0) | +| `real-require@0.2.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/real-require/0.2.0) | diff --git a/.deps/prod.md b/.deps/prod.md index 100739925..7cb2397e4 100644 --- a/.deps/prod.md +++ b/.deps/prod.md @@ -171,8 +171,8 @@ | [`domutils@3.1.0`](git://github.com/fb55/domutils.git) | BSD-2-Clause | #8391 | | [`duplexify@4.1.3`](git://github.com/mafintosh/duplexify) | MIT | clearlydefined | | `eastasianwidth@0.2.0` | MIT | clearlydefined | -| [`ecc-jsbn@0.1.2`](https://github.com/quartzjer/ecc-jsbn.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/ecc-jsbn/0.1.2) | -| [`elliptic@6.6.1`](git@github.com:indutny/elliptic) | MIT | clearlydefined | +| [`ecc-jsbn@0.1.2`](https://github.com/quartzjer/ecc-jsbn.git) | MIT | #17389 | +| [`elliptic@6.6.1`](git@github.com:indutny/elliptic) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/elliptic/6.6.1) | | [`emoji-regex@8.0.0`](https://github.com/mathiasbynens/emoji-regex.git) | MIT | clearlydefined | | [`emoji-regex@9.2.2`](https://github.com/mathiasbynens/emoji-regex.git) | MIT | clearlydefined | | `encoding@0.1.13` | MIT | #1016 | @@ -326,20 +326,20 @@ | `micromark-factory-space@2.0.0` | MIT | clearlydefined | | `micromark-factory-title@2.0.0` | MIT | clearlydefined | | `micromark-factory-whitespace@2.0.0` | MIT | clearlydefined | -| `micromark-util-character@2.1.0` | MIT | clearlydefined | +| `micromark-util-character@2.1.0` | MIT | #17409 | | `micromark-util-chunked@2.0.0` | MIT | clearlydefined | | `micromark-util-classify-character@2.0.0` | MIT | clearlydefined | | `micromark-util-combine-extensions@2.0.0` | MIT | clearlydefined | | `micromark-util-decode-numeric-character-reference@2.0.1` | MIT | clearlydefined | | `micromark-util-decode-string@2.0.0` | MIT | clearlydefined | -| `micromark-util-encode@2.0.0` | MIT | clearlydefined | +| `micromark-util-encode@2.0.0` | MIT | #17395 | | `micromark-util-html-tag-name@2.0.0` | MIT | clearlydefined | | `micromark-util-normalize-identifier@2.0.0` | MIT | clearlydefined | | `micromark-util-resolve-all@2.0.0` | MIT | clearlydefined | -| `micromark-util-sanitize-uri@2.0.0` | MIT | clearlydefined | +| `micromark-util-sanitize-uri@2.0.0` | MIT | #17416 | | `micromark-util-subtokenize@2.0.1` | MIT | clearlydefined | -| `micromark-util-symbol@2.0.0` | MIT | clearlydefined | -| `micromark-util-types@2.0.0` | MIT | clearlydefined | +| `micromark-util-symbol@2.0.0` | MIT | #17394 | +| `micromark-util-types@2.0.0` | MIT | #17405 | | `micromark@4.0.0` | MIT | clearlydefined | | [`miller-rabin@4.0.1`](git@github.com:indutny/miller-rabin) | MIT | clearlydefined | | `mime-db@1.52.0` | MIT | clearlydefined | @@ -559,6 +559,6 @@ | [`wrappy@1.0.2`](https://github.com/npm/wrappy) | ISC | clearlydefined | | [`yallist@4.0.0`](git+https://github.com/isaacs/yallist.git) | ISC | clearlydefined | | [`yallist@5.0.0`](git+https://github.com/isaacs/yallist.git) | BlueOak-1.0.0 | clearlydefined | -| [`yaml@2.6.0`](https://eemeli.org/yaml/) | ISC | clearlydefined | +| [`yaml@2.6.0`](https://eemeli.org/yaml/) | ISC | #17714 | | `yocto-queue@0.1.0` | MIT | clearlydefined | | `zwitch@2.0.4` | MIT | clearlydefined | diff --git a/packages/dashboard-frontend/src/components/BasicViewer/__mocks__/index.tsx b/packages/dashboard-frontend/src/components/BasicViewer/__mocks__/index.tsx new file mode 100644 index 000000000..7dadc4053 --- /dev/null +++ b/packages/dashboard-frontend/src/components/BasicViewer/__mocks__/index.tsx @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2024 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +import React from 'react'; + +import { Props } from '@/components/BasicViewer'; + +export class BasicViewer extends React.PureComponent { + public render(): React.ReactNode { + const { id, value } = this.props; + + return ( +
+ Mock Basic Viewer + {id} + {value} +
+ ); + } +} diff --git a/packages/dashboard-frontend/src/components/BasicViewer/__tests__/__snapshots__/index.spec.tsx.snap b/packages/dashboard-frontend/src/components/BasicViewer/__tests__/__snapshots__/index.spec.tsx.snap new file mode 100644 index 000000000..6eb934936 --- /dev/null +++ b/packages/dashboard-frontend/src/components/BasicViewer/__tests__/__snapshots__/index.spec.tsx.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BasicViewer snapshot 1`] = ` +
+
+
+`; diff --git a/packages/dashboard-frontend/src/components/BasicViewer/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/components/BasicViewer/__tests__/index.spec.tsx new file mode 100644 index 000000000..65948f868 --- /dev/null +++ b/packages/dashboard-frontend/src/components/BasicViewer/__tests__/index.spec.tsx @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018-2024 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +import React from 'react'; + +import { BasicViewer } from '@/components/BasicViewer'; +import getComponentRenderer, { screen } from '@/services/__mocks__/getComponentRenderer'; + +const { createSnapshot, renderComponent } = getComponentRenderer(getComponent); + +describe('BasicViewer', () => { + test('snapshot', () => { + const snapshot = createSnapshot('line 1\nline 2\nline 3'); + expect(snapshot.toJSON()).toMatchSnapshot(); + }); + + test('handle content change', () => { + const { reRenderComponent } = renderComponent('line 1\nline 2\nline 3'); + + const textbox = screen.getByRole('textbox'); + + // no new line character + expect(textbox).toHaveTextContent('line 1line 2line 3'); + + reRenderComponent('line 4\nline 5\nline 6'); + + // no new line character + expect(textbox).toHaveTextContent('line 4line 5line 6'); + }); +}); + +function getComponent(value: string): React.ReactElement { + return ; +} diff --git a/packages/dashboard-frontend/src/components/BasicViewer/index.module.css b/packages/dashboard-frontend/src/components/BasicViewer/index.module.css new file mode 100644 index 000000000..6248608a2 --- /dev/null +++ b/packages/dashboard-frontend/src/components/BasicViewer/index.module.css @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2018-2024 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +.basicViewer { + overflow: auto; + width: 100%; + height: 100%; +} + +.basicViewer > div { + overflow: auto; + height: 100%; + border: 1px solid var(--pf-global--BorderColor--100); +} diff --git a/packages/dashboard-frontend/src/components/BasicViewer/index.tsx b/packages/dashboard-frontend/src/components/BasicViewer/index.tsx new file mode 100644 index 000000000..ea1be739e --- /dev/null +++ b/packages/dashboard-frontend/src/components/BasicViewer/index.tsx @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018-2024 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language'; +import { EditorState } from '@codemirror/state'; +import { EditorView } from '@codemirror/view'; +import React from 'react'; + +import styles from '@/components/BasicViewer/index.module.css'; + +export type Props = { + value: string; + id: string; +}; + +export class BasicViewer extends React.PureComponent { + private editor: EditorView | undefined; + + public componentDidMount(): void { + const parent = window.document.querySelector(`#${this.props.id}`); + if (parent) { + const state = this.getEditorState(); + this.editor = new EditorView({ + state, + parent, + }); + } + } + + public componentWillUnmount(): void { + if (this.editor) { + this.editor.destroy(); + } + } + + componentDidUpdate(prevProps: Readonly): void { + if (this.editor && this.props.value !== prevProps.value) { + const state = this.getEditorState(); + this.editor.setState(state); + } + } + + private getEditorState(): EditorState { + return EditorState.create({ + doc: this.props.value, + extensions: [syntaxHighlighting(defaultHighlightStyle), EditorState.readOnly.of(true)], + }); + } + + public render(): React.ReactElement { + return ( +
+
+
+ ); + } +} diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Form/index.tsx b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Form/index.tsx index fccc82047..8576fb888 100644 --- a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Form/index.tsx +++ b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Form/index.tsx @@ -14,17 +14,17 @@ import { Button, Flex, Form, PageSection, PageSectionVariants } from '@patternfl import React, { FormEvent } from 'react'; import { GitConfigSectionUser } from '@/pages/UserPreferences/GitConfig/Form/SectionUser'; -import * as GitConfigStore from '@/store/GitConfig'; +import { GitConfig } from '@/store/GitConfig'; export type Props = { isLoading: boolean; - gitConfig: GitConfigStore.GitConfig; - onSave: (gitConfig: GitConfigStore.GitConfig) => Promise; + gitConfig: GitConfig; + onSave: (gitConfig: GitConfig) => Promise; onReload: () => Promise; }; export type State = { isValid: boolean; - nextGitConfig: GitConfigStore.GitConfig | undefined; + nextGitConfig: GitConfig | undefined; }; export class GitConfigForm extends React.PureComponent { @@ -62,7 +62,7 @@ export class GitConfigForm extends React.PureComponent { } } - private handleChangeConfig(gitConfig: GitConfigStore.GitConfig, isValid: boolean): void { + private handleChangeConfig(gitConfig: GitConfig, isValid: boolean): void { this.setState({ nextGitConfig: gitConfig, isValid, diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__mocks__/index.tsx b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__mocks__/index.tsx new file mode 100644 index 000000000..f24b515f0 --- /dev/null +++ b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__mocks__/index.tsx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-2024 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +import React from 'react'; + +import { Props } from '@/pages/UserPreferences/GitConfig/Toolbar'; + +export class GitConfigToolbar extends React.PureComponent { + render() { + const { mode, onAdd, onChangeMode } = this.props; + const nextMode = mode === 'form' ? 'viewer' : 'form'; + return ( +
+ Mock Git Config Toolbar + {mode} + + +
+ ); + } +} diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__tests__/__snapshots__/index.spec.tsx.snap b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__tests__/__snapshots__/index.spec.tsx.snap index 8ef57cb7a..69af96776 100644 --- a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__tests__/__snapshots__/index.spec.tsx.snap +++ b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__tests__/__snapshots__/index.spec.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`GitConfigToolbar snapshot 1`] = ` +exports[`GitConfigToolbar snapshot, form mode 1`] = `
+ + + + + + Switch to Viewer + +
`; + +exports[`GitConfigToolbar snapshot, viewer mode 1`] = ` +
+
+
+
+ + +
+
+
+
+
+
+ +`; diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__tests__/index.spec.tsx index 5e479b1cc..342d3187d 100644 --- a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__tests__/index.spec.tsx +++ b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/__tests__/index.spec.tsx @@ -10,40 +10,68 @@ * Red Hat, Inc. - initial API and implementation */ +import userEvent from '@testing-library/user-event'; import React from 'react'; -import getComponentRenderer, { screen } from '@/services/__mocks__/getComponentRenderer'; - -import { GitConfigToolbar } from '..'; +import { GitConfigToolbar } from '@/pages/UserPreferences/GitConfig/Toolbar'; +import getComponentRenderer, { screen, waitFor } from '@/services/__mocks__/getComponentRenderer'; const { createSnapshot, renderComponent } = getComponentRenderer(getComponent); const mockOnAdd = jest.fn(); +const mockOnChangeMode = jest.fn(); describe('GitConfigToolbar', () => { afterEach(() => { jest.clearAllMocks(); }); - test('snapshot', () => { - const snapshot = createSnapshot(); + test('snapshot, form mode', () => { + const snapshot = createSnapshot('form'); + expect(snapshot.toJSON()).toMatchSnapshot(); + }); + + test('snapshot, viewer mode', () => { + const snapshot = createSnapshot('form'); expect(snapshot.toJSON()).toMatchSnapshot(); }); - describe('import Git Configuration', () => { - it('should handle onAdd event', () => { - renderComponent(); + test('import Git Configuration', () => { + renderComponent('form'); + + expect(mockOnAdd).not.toHaveBeenCalled(); + + const button = screen.getByRole('button', { name: 'Import Git Configuration' }); + button.click(); + + expect(mockOnAdd).toHaveBeenCalled(); + }); + + test('change mode to viewer', async () => { + renderComponent('form'); + + expect(mockOnChangeMode).not.toHaveBeenCalled(); + expect(screen.queryByRole('button', { name: 'Switch to Form' })).toBeNull(); + + const viewerButton = screen.getByRole('button', { name: 'Switch to Viewer' }); + await userEvent.click(viewerButton); + + await waitFor(() => expect(mockOnChangeMode).toHaveBeenCalledWith('viewer')); + }); + + test('change mode to form', async () => { + renderComponent('viewer'); - expect(mockOnAdd).not.toHaveBeenCalled(); + expect(mockOnChangeMode).not.toHaveBeenCalled(); + expect(screen.queryByRole('button', { name: 'Switch to Viewer' })).toBeNull(); - const button = screen.getByRole('button', { name: 'Import Git Configuration' }); - button.click(); + const formButton = screen.getByRole('button', { name: 'Switch to Form' }); + await userEvent.click(formButton); - expect(mockOnAdd).toHaveBeenCalled(); - }); + await waitFor(() => expect(mockOnChangeMode).toHaveBeenCalledWith('form')); }); }); -function getComponent(): React.ReactElement { - return ; +function getComponent(mode: 'form' | 'viewer'): React.ReactElement { + return ; } diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/index.tsx b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/index.tsx index 815ea00c8..aea35ad1c 100644 --- a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/index.tsx +++ b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/Toolbar/index.tsx @@ -17,19 +17,47 @@ import { ToolbarContent, ToolbarItem, } from '@patternfly/react-core'; -import { PlusCircleIcon } from '@patternfly/react-icons'; +import { CodeIcon, ListIcon, PlusCircleIcon } from '@patternfly/react-icons'; import React from 'react'; export type Props = { + mode: 'form' | 'viewer'; onAdd: () => void; + onChangeMode: (mode: 'form' | 'viewer') => void; }; export class GitConfigToolbar extends React.PureComponent { + private handleModeChange(mode: 'form' | 'viewer'): void { + this.setState({ mode }); + this.props.onChangeMode(mode); + } + public render(): React.ReactElement { + const { mode } = this.props; + return ( + {mode === 'form' ? ( + + ) : ( + + )} -
-
-
-
-
-
-
- , -] + + `; exports[`GitConfig snapshot with no gitconfig 1`] = ` -[ +
, + />
@@ -150,6 +97,6 @@ exports[`GitConfig snapshot with no gitconfig 1`] = ` No gitconfig found
-
, -] + + `; diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/__tests__/index.spec.tsx index 69dd05677..5d9928452 100644 --- a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/__tests__/index.spec.tsx +++ b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/__tests__/index.spec.tsx @@ -27,6 +27,8 @@ import { MockStoreBuilder } from '@/store/__mocks__/mockStore'; import { gitConfigActionCreators } from '@/store/GitConfig'; jest.mock('@/pages/UserPreferences/GitConfig/Form'); +jest.mock('@/pages/UserPreferences/GitConfig/Viewer'); +jest.mock('@/pages/UserPreferences/GitConfig/Toolbar'); // mute output console.error = jest.fn(); @@ -194,6 +196,17 @@ describe('GitConfig', () => { expect(mockRequestGitConfig).toHaveBeenCalled(); }); }); + + test('switch to viewer mode', async () => { + renderComponent(store); + + expect(screen.getByTestId('toolbar-mode')).toHaveTextContent('form'); + + const switchModeButton = screen.getByRole('button', { name: 'Switch Mode' }); + await userEvent.click(switchModeButton); + + await waitFor(() => expect(screen.getByTestId('toolbar-mode')).toHaveTextContent('viewer')); + }); }); function getComponent(store: Store): React.ReactElement { diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/index.tsx b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/index.tsx index ad717ff0b..c20c10f7c 100644 --- a/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/index.tsx +++ b/packages/dashboard-frontend/src/pages/UserPreferences/GitConfig/index.tsx @@ -11,7 +11,7 @@ */ import { helpers } from '@eclipse-che/common'; -import { AlertVariant, PageSection } from '@patternfly/react-core'; +import { AlertVariant, PageSection, PageSectionVariants } from '@patternfly/react-core'; import React from 'react'; import { connect, ConnectedProps } from 'react-redux'; @@ -21,6 +21,7 @@ import { GitConfigAddModal } from '@/pages/UserPreferences/GitConfig/AddModal'; import { GitConfigEmptyState } from '@/pages/UserPreferences/GitConfig/EmptyState'; import { GitConfigForm } from '@/pages/UserPreferences/GitConfig/Form'; import { GitConfigToolbar } from '@/pages/UserPreferences/GitConfig/Toolbar'; +import { GitConfigViewer } from '@/pages/UserPreferences/GitConfig/Viewer'; import { AppAlerts } from '@/services/alerts/appAlerts'; import { RootState } from '@/store'; import * as GitConfigStore from '@/store/GitConfig'; @@ -35,6 +36,7 @@ export type Props = MappedProps; export type State = { isAddEditOpen: boolean; + mode: 'form' | 'viewer'; }; class GitConfig extends React.PureComponent { @@ -46,6 +48,7 @@ class GitConfig extends React.PureComponent { this.state = { isAddEditOpen: false, + mode: 'form', }; } @@ -105,43 +108,62 @@ class GitConfig extends React.PureComponent { }); } + private handleModeChange(mode: 'form' | 'viewer'): void { + this.setState({ mode }); + } + public render(): React.ReactElement { const { gitConfigIsLoading, gitConfig } = this.props; - const { isAddEditOpen } = this.state; + const { isAddEditOpen, mode } = this.state; const isEmpty = gitConfig === undefined; + let gitConfigViewer = <>; + if (gitConfig !== undefined) { + if (mode === 'form') { + gitConfigViewer = ( + await this.handleSave(gitConfig)} + onReload={async () => await this.handleReload()} + /> + ); + } else { + gitConfigViewer = ; + } + } + return ( - - this.handleCloseAddEditModal()} - onSave={async gitConfig => { - await this.handleSave(gitConfig); - this.handleCloseAddEditModal(); - }} - /> - {isEmpty ? ( - - ) : ( - - { - this.setState({ - isAddEditOpen: true, - }); - }} - /> - await this.handleSave(gitConfig)} - onReload={async () => await this.handleReload()} - /> - - )} + + + this.handleCloseAddEditModal()} + onSave={async gitConfig => { + await this.handleSave(gitConfig); + this.handleCloseAddEditModal(); + }} + /> + {isEmpty ? ( + + ) : ( + + { + this.setState({ + isAddEditOpen: true, + }); + }} + onChangeMode={mode => this.handleModeChange(mode)} + /> + {gitConfigViewer} + + )} + ); } diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/__tests__/__snapshots__/index.spec.tsx.snap b/packages/dashboard-frontend/src/pages/UserPreferences/__tests__/__snapshots__/index.spec.tsx.snap index c51ee3af1..723cf7e00 100644 --- a/packages/dashboard-frontend/src/pages/UserPreferences/__tests__/__snapshots__/index.spec.tsx.snap +++ b/packages/dashboard-frontend/src/pages/UserPreferences/__tests__/__snapshots__/index.spec.tsx.snap @@ -15,112 +15,116 @@ exports[`UserPreferences snapshot 1`] = ` User Preferences -
-
    - - + - + - + - + -
-
-
-
- ContainerRegistries + + +
+
+
+ ContainerRegistries +
+
diff --git a/packages/dashboard-frontend/src/pages/UserPreferences/index.tsx b/packages/dashboard-frontend/src/pages/UserPreferences/index.tsx index 156477788..fdaed5727 100644 --- a/packages/dashboard-frontend/src/pages/UserPreferences/index.tsx +++ b/packages/dashboard-frontend/src/pages/UserPreferences/index.tsx @@ -89,30 +89,35 @@ class UserPreferences extends React.PureComponent { User Preferences - this.handleTabClick(event, tabKey)} - mountOnEnter={true} - unmountOnExit={true} - > - - - - - - - - - - - - - - - - + + this.handleTabClick(event, tabKey)} + mountOnEnter={true} + unmountOnExit={true} + > + + + + + + + + + + + + + + + + + ); } diff --git a/scripts/yarn/old_version/.deps/EXCLUDED/prod.md b/scripts/yarn/old_version/.deps/EXCLUDED/prod.md index 419536d28..9a01bf422 100644 --- a/scripts/yarn/old_version/.deps/EXCLUDED/prod.md +++ b/scripts/yarn/old_version/.deps/EXCLUDED/prod.md @@ -11,9 +11,9 @@ This file lists dependencies that do not need CQs or auto-detection does not wor | `blueimp-md5@2.19.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/blueimp-md5/2.19.0) | | `codemirror@5.65.16` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.16) | | `cookie-signature@1.2.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/cookie-signature/1.2.1) | -| `ecc-jsbn@0.1.2` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/ecc-jsbn/0.1.2) | +| `elliptic@6.6.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/elliptic/6.6.1) | | `fast-uri@2.4.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fast-uri/2.4.0) | | `fastify@4.28.1` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fastify/4.28.1) | | `jsep@1.3.9` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/jsep/1.3.9) | -| `real-require@0.2.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/real-require/0.2.0) | | `light-my-request@5.14.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/light-my-request/5.14.0) | +| `real-require@0.2.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/real-require/0.2.0) | diff --git a/scripts/yarn/old_version/.deps/prod.md b/scripts/yarn/old_version/.deps/prod.md index 17738d16e..f56dbe80e 100644 --- a/scripts/yarn/old_version/.deps/prod.md +++ b/scripts/yarn/old_version/.deps/prod.md @@ -10,9 +10,9 @@ | [`@codemirror/view@6.34.2`](https://github.com/codemirror/view.git) | MIT | clearlydefined | | [`@devfile/api@2.3.0-1721400636`](https://github.com/GIT_USER_ID/GIT_REPO_ID.git) | Apache-2.0 | clearlydefined | | [`@eclipse-che/che-devworkspace-generator@7.90.0-next-4510df7`](git+https://github.com/devfile/devworkspace-generator.git) | EPL-2.0 | ecd.che | -| [`@eclipse-che/common@7.95.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che | -| [`@eclipse-che/dashboard-backend@7.95.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che | -| [`@eclipse-che/dashboard-frontend@7.95.0-next`](git://github.com/eclipse/che-dashboard.git) | EPL-2.0 | ecd.che | +| [`@eclipse-che/common@7.96.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che | +| [`@eclipse-che/dashboard-backend@7.96.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che | +| [`@eclipse-che/dashboard-frontend@7.96.0-next`](git://github.com/eclipse/che-dashboard.git) | EPL-2.0 | ecd.che | | [`@fastify/accept-negotiator@1.1.0`](git+https://github.com/fastify/accept-negotiator.git) | MIT | clearlydefined | | [`@fastify/ajv-compiler@3.6.0`](git+https://github.com/fastify/ajv-compiler.git) | MIT | clearlydefined | | [`@fastify/busboy@2.0.0`](https://github.com/fastify/busboy.git) | MIT | clearlydefined | @@ -154,7 +154,7 @@ | [`duplexify@4.1.3`](git://github.com/mafintosh/duplexify) | MIT | clearlydefined | | [`eastasianwidth@0.2.0`](git://github.com/komagata/eastasianwidth.git) | MIT | clearlydefined | | [`ecc-jsbn@0.1.2`](https://github.com/quartzjer/ecc-jsbn.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/ecc-jsbn/0.1.2) | -| [`elliptic@6.6.1`](git@github.com:indutny/elliptic) | MIT | clearlydefined | +| [`elliptic@6.6.1`](git@github.com:indutny/elliptic) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/elliptic/6.6.1) | | [`emoji-regex@8.0.0`](https://github.com/mathiasbynens/emoji-regex.git) | MIT | clearlydefined | | [`end-of-stream@1.4.4`](git://github.com/mafintosh/end-of-stream.git) | MIT | clearlydefined | | [`entities@4.5.0`](git://github.com/fb55/entities.git) | BSD-2-Clause | #7910 | @@ -279,20 +279,20 @@ | [`micromark-factory-space@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-factory-space) | MIT | clearlydefined | | [`micromark-factory-title@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-factory-title) | MIT | clearlydefined | | [`micromark-factory-whitespace@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-factory-whitespace) | MIT | clearlydefined | -| [`micromark-util-character@2.1.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-character) | MIT | clearlydefined | +| [`micromark-util-character@2.1.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-character) | MIT | #17409 | | [`micromark-util-chunked@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-chunked) | MIT | clearlydefined | | [`micromark-util-classify-character@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-classify-character) | MIT | clearlydefined | | [`micromark-util-combine-extensions@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-combine-extensions) | MIT | clearlydefined | | [`micromark-util-decode-numeric-character-reference@2.0.1`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-decode-numeric-character-reference) | MIT | clearlydefined | | [`micromark-util-decode-string@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-decode-string) | MIT | clearlydefined | -| [`micromark-util-encode@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-encode) | MIT | clearlydefined | +| [`micromark-util-encode@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-encode) | MIT | #17395 | | [`micromark-util-html-tag-name@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-html-tag-name) | MIT | clearlydefined | | [`micromark-util-normalize-identifier@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-normalize-identifier) | MIT | clearlydefined | | [`micromark-util-resolve-all@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-resolve-all) | MIT | clearlydefined | -| [`micromark-util-sanitize-uri@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-sanitize-uri) | MIT | clearlydefined | +| [`micromark-util-sanitize-uri@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-sanitize-uri) | MIT | #17416 | | [`micromark-util-subtokenize@2.0.1`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-subtokenize) | MIT | clearlydefined | -| [`micromark-util-symbol@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-symbol) | MIT | clearlydefined | -| [`micromark-util-types@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-types) | MIT | clearlydefined | +| [`micromark-util-symbol@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-symbol) | MIT | #17394 | +| [`micromark-util-types@2.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-types) | MIT | #17405 | | [`micromark@4.0.0`](https://github.com/micromark/micromark/tree/main/packages/micromark) | MIT | clearlydefined | | [`miller-rabin@4.0.1`](git@github.com:indutny/miller-rabin) | MIT | clearlydefined | | [`mime-db@1.52.0`](https://github.com/jshttp/mime-db.git) | MIT | clearlydefined |