-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upstream: b=main,r=314d894c671a662a70e9c0f93c105a2b90765ca0,t=2022-09…
…-30-1242-43906
- Loading branch information
1 parent
13df2af
commit baac7d7
Showing
75 changed files
with
1,887 additions
and
251 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
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
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
33 changes: 33 additions & 0 deletions
33
...nents/nexus-ui-plugin/src/frontend/src/components/widgets/ReadOnlyField/ReadOnlyField.jsx
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,33 @@ | ||
/* | ||
* Sonatype Nexus (TM) Open Source Version | ||
* Copyright (c) 2008-present Sonatype, Inc. | ||
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, | ||
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. | ||
* | ||
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks | ||
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the | ||
* Eclipse Foundation. All other trademarks are the property of their respective owners. | ||
*/ | ||
import React from 'react'; | ||
import {NxReadOnly} from '@sonatype/react-shared-components'; | ||
import {isNil, isEmpty} from 'ramda'; | ||
|
||
/** | ||
* @param {string} label | ||
* @param value [required] | ||
* @return {ReactNode} | ||
*/ | ||
export default function ReadOnlyField({label, value}) { | ||
const valid = !isNil(value) && !isEmpty(value); | ||
|
||
return ( | ||
valid && ( | ||
<> | ||
<NxReadOnly.Label>{label}</NxReadOnly.Label> | ||
<NxReadOnly.Data>{value}</NxReadOnly.Data> | ||
</> | ||
) | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
.../nexus-ui-plugin/src/frontend/src/components/widgets/ReadOnlyField/ReadOnlyField.test.jsx
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,61 @@ | ||
/* | ||
* Sonatype Nexus (TM) Open Source Version | ||
* Copyright (c) 2008-present Sonatype, Inc. | ||
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, | ||
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. | ||
* | ||
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks | ||
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the | ||
* Eclipse Foundation. All other trademarks are the property of their respective owners. | ||
*/ | ||
import React from 'react'; | ||
import {render, screen} from '@testing-library/react'; | ||
import ReadOnlyField from './ReadOnlyField'; | ||
|
||
describe('readOnlyRenderField', () => { | ||
const label = 'Best Label'; | ||
const data = '[email protected]'; | ||
|
||
const selectors = { | ||
label: () => screen.getByText(label), | ||
data: () => screen.getByText(data), | ||
queryLabel: () => screen.queryByText(label), | ||
queryData: () => screen.queryByText(data), | ||
}; | ||
|
||
const renderComponent = () => | ||
render(<ReadOnlyField label={label} value={data} />); | ||
|
||
it('returns an element', () => { | ||
renderComponent(); | ||
|
||
expect(selectors.label()).toBeInTheDocument(); | ||
expect(selectors.data()).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not return an element if the data is empty, null or undefined', async () => { | ||
const {rerender} = renderComponent(); | ||
|
||
rerender(<ReadOnlyField label={label} />); | ||
|
||
expect(selectors.queryLabel()).not.toBeInTheDocument(); | ||
expect(selectors.queryData()).not.toBeInTheDocument(); | ||
|
||
rerender(<ReadOnlyField label={label} value="" />); | ||
|
||
expect(selectors.queryLabel()).not.toBeInTheDocument(); | ||
expect(selectors.queryData()).not.toBeInTheDocument(); | ||
|
||
rerender(<ReadOnlyField label={label} value={null} />); | ||
|
||
expect(selectors.queryLabel()).not.toBeInTheDocument(); | ||
expect(selectors.queryData()).not.toBeInTheDocument(); | ||
|
||
rerender(<ReadOnlyField label={label} value={undefined} />); | ||
|
||
expect(selectors.queryLabel()).not.toBeInTheDocument(); | ||
expect(selectors.queryData()).not.toBeInTheDocument(); | ||
}); | ||
}); |
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
Oops, something went wrong.