Skip to content

add OpenShift LogSnippet #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
83d46d5
add OpenShift LogSnippet
InsaneZein Feb 8, 2024
3af9de9
fix layout; switch to pf variables
InsaneZein Feb 9, 2024
e63ddfa
add test
InsaneZein Feb 9, 2024
3fcba6e
pf variables and fix typos
InsaneZein Feb 13, 2024
6ce785e
fix snapshot
InsaneZein Feb 13, 2024
e510823
wip: add leftBorderVariant
InsaneZein Feb 15, 2024
e659560
fix dynamic styling
InsaneZein Feb 19, 2024
bae7d6c
update snapshot
InsaneZein Feb 19, 2024
9959299
remove old redborder class
InsaneZein Feb 19, 2024
b8327d4
update snapshot again
InsaneZein Feb 19, 2024
3d000d5
add types to createuseStyles
InsaneZein Feb 20, 2024
8b7385c
revert leftborder default to danger
InsaneZein Feb 20, 2024
fb101c3
Merge branch 'main' of github.com:patternfly/react-component-groups i…
InsaneZein Feb 20, 2024
96c265e
clean up code
InsaneZein Feb 20, 2024
dc1ffa6
add OpenShift LogSnippet
InsaneZein Feb 8, 2024
1850983
fix layout; switch to pf variables
InsaneZein Feb 9, 2024
de4c55c
add test
InsaneZein Feb 9, 2024
7689bd2
pf variables and fix typos
InsaneZein Feb 13, 2024
558893c
fix snapshot
InsaneZein Feb 13, 2024
49a1255
wip: add leftBorderVariant
InsaneZein Feb 15, 2024
5bbc8f4
fix dynamic styling
InsaneZein Feb 19, 2024
1a34f9b
update snapshot
InsaneZein Feb 19, 2024
a2b1258
remove old redborder class
InsaneZein Feb 19, 2024
f6a1506
update snapshot again
InsaneZein Feb 19, 2024
bc7cc0f
add types to createuseStyles
InsaneZein Feb 20, 2024
b21ccdf
revert leftborder default to danger
InsaneZein Feb 20, 2024
9c8dbf8
clean up code
InsaneZein Feb 20, 2024
588d44f
Merge branch 'add-logsnippet' of github.com:patternfly/react-componen…
InsaneZein Feb 20, 2024
8f2074a
more cleanup
InsaneZein Feb 20, 2024
0d4e71c
Merge branch 'main' of github.com:patternfly/react-component-groups i…
InsaneZein Feb 20, 2024
ea38872
feat(logsnippet): add log snippet
InsaneZein Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# Sidenav top-level section
# should be the same for all markdown files
section: extensions
subsection: Component groups
# Sidenav secondary level section
# should be the same for all markdown files
id: Log snippet
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
source: react
# If you use typescript, the name of the interface to display props for
# These are found through the sourceProps function provided in patternfly-docs.source.js
propComponents: ['LogSnippet']
sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packages/module/patternfly-docs/content/extensions/component-groups/examples/LogSnippet/LogSnippet.md
---

import LogSnippet from '@patternfly/react-component-groups/dist/dynamic/LogSnippet';

A **log snippet** component provides a way to display a log snippet or code along with a message

## Examples

### Basic log snippet

```js file="./LogSnippetExample.tsx"

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import LogSnippet from '@patternfly/react-component-groups/dist/dynamic/LogSnippet';

export const BasicExample: React.FunctionComponent = () => {
const code = `apiVersion: helm.openshift.io/v1beta1/
kind: HelmChartRepository
metadata:
name: azure-sample-repo
spec:
connectionConfig:
url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs`;

return <LogSnippet message='Failure - check logs for details' logSnippet={code} />;
}
9 changes: 9 additions & 0 deletions packages/module/src/LogSnippet/LogSnippet.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { render } from '@testing-library/react';
import LogSnippet from './LogSnippet';

describe('LogSnippet component', () => {
it('should render LogSnippet component', () => {
expect(render(<LogSnippet message='A log snippet' logSnippet='console.log(hello world)'/>)).toMatchSnapshot();
});
});
50 changes: 50 additions & 0 deletions packages/module/src/LogSnippet/LogSnippet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as React from 'react';
import { CodeBlock, CodeBlockCode, Flex, FlexItem, FlexProps, Text, TextVariants } from '@patternfly/react-core';
import clsx from 'clsx';
import { createUseStyles } from 'react-jss'

export type BorderVariant = 'danger' | 'success' | 'info' | 'warning';

export interface LogSnippetProps extends FlexProps {
/** Log snippet or code to be displayed */
logSnippet?: string;
/** Message to appear above the log snippet */
message: string | React.ReactNode;
/** Custom color for left border */
leftBorderVariant?: BorderVariant;
}

const useStyles = createUseStyles({
logSnippet: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use clsx with this. Is there a reason we aren't here? I think we should use a layout instead of the div and p below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought clsx was just for conditional rendering

marginLeft: 'var(--pf-v5-global--spacer--sm)',
padding: 'var(--pf-v5-global--spacer--sm) 0 var(--pf-v5-global--spacer--sm) var(--pf-v5-global--spacer--sm)',
backgroundColor: 'var(--pf-v5-global--BackgroundColor--100)',
},
variantBorderColor: (leftBorderVariant: string) => ({
borderLeft: `var(--pf-v5-global--BorderWidth--md) solid var(--pf-v5-global--${leftBorderVariant}-color--100)`,
}),
statusMessage: {
marginBottom:'var(--pf-v5-global--spacer--sm)',
},
});



export const LogSnippet: React.FunctionComponent<LogSnippetProps> = ({ logSnippet, message, leftBorderVariant = 'danger', ...props }: LogSnippetProps) => {
const classes = useStyles(leftBorderVariant);

return (
<Flex direction={{ default: 'column' }} className={clsx(classes.logSnippet, classes.variantBorderColor)} {...props}>
<FlexItem>
{ typeof message === 'string' ? <Text component={TextVariants.p} className={classes.statusMessage}>{message}</Text> : message }
</FlexItem>
{ logSnippet && <FlexItem>
<CodeBlock>
<CodeBlockCode id="code-content">{logSnippet}</CodeBlockCode>
</CodeBlock>
</FlexItem> }
</Flex>
)
};

export default LogSnippet;
142 changes: 142 additions & 0 deletions packages/module/src/LogSnippet/__snapshots__/LogSnippet.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`LogSnippet component should render LogSnippet component 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
<div>
<div
class="pf-v5-l-flex pf-m-column logSnippet-0-2-1 variantBorderColor-0-2-2 variantBorderColor-d0-0-2-4"
>
<div
class=""
>
<p
class="statusMessage-0-2-3"
data-ouia-component-id="OUIA-Generated-Text-1"
data-ouia-component-type="PF5/Text"
data-ouia-safe="true"
data-pf-content="true"
>
A log snippet
</p>
</div>
<div
class=""
>
<div
class="pf-v5-c-code-block"
>
<div
class="pf-v5-c-code-block__content"
>
<pre
class="pf-v5-c-code-block__pre"
id="code-content"
>
<code
class="pf-v5-c-code-block__code"
>
console.log(hello world)
</code>
</pre>
</div>
</div>
</div>
</div>
</div>
</body>,
"container": <div>
<div
class="pf-v5-l-flex pf-m-column logSnippet-0-2-1 variantBorderColor-0-2-2 variantBorderColor-d0-0-2-4"
>
<div
class=""
>
<p
class="statusMessage-0-2-3"
data-ouia-component-id="OUIA-Generated-Text-1"
data-ouia-component-type="PF5/Text"
data-ouia-safe="true"
data-pf-content="true"
>
A log snippet
</p>
</div>
<div
class=""
>
<div
class="pf-v5-c-code-block"
>
<div
class="pf-v5-c-code-block__content"
>
<pre
class="pf-v5-c-code-block__pre"
id="code-content"
>
<code
class="pf-v5-c-code-block__code"
>
console.log(hello world)
</code>
</pre>
</div>
</div>
</div>
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
2 changes: 2 additions & 0 deletions packages/module/src/LogSnippet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './LogSnippet';
export * from './LogSnippet';
3 changes: 3 additions & 0 deletions packages/module/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export * from './HorizontalNav';
export { default as InvalidObject } from './InvalidObject';
export * from './InvalidObject';

export { default as LogSnippet } from './LogSnippet';
export * from './LogSnippet';

export { default as NotAuthorized } from './NotAuthorized';
export * from './NotAuthorized';

Expand Down