Skip to content
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

feat: custom extension rendering #994

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
db17606
Custom extension value render
Apr 19, 2024
a52c230
Merge branch 'master' into feat/custom-extension-value-render
asyncapi-bot Apr 24, 2024
22f07b3
Add parent to ExtensionComponentProps and move changes to Extensions …
Apr 25, 2024
18654d2
Merge remote-tracking branch 'origin/feat/custom-extension-value-rend…
Apr 25, 2024
9b978b8
Address Sonar issue
Apr 25, 2024
de451e8
Merge branch 'master' into feat/custom-extension-value-render
ductaily Apr 30, 2024
13a8a6c
Apply suggestions from code review
ductaily Apr 30, 2024
23401a9
Clean up Extension class
Apr 30, 2024
6c4f19f
Merge branch 'refs/heads/master' into feat/custom-extension-value-render
May 2, 2024
37bc952
Merge branch 'master' into feat/custom-extension-value-render
ductaily May 2, 2024
3b19209
Merge remote-tracking branch 'origin/feat/custom-extension-value-rend…
May 2, 2024
95bfa86
Merge branch 'master' into feat/custom-extension-value-render
derberg May 13, 2024
8492e7a
Merge branch 'master' into feat/custom-extension-value-render
asyncapi-bot May 13, 2024
389e407
Merge remote-tracking branch 'origin/feat/custom-extension-value-rend…
May 13, 2024
973c1da
Address eslint errors
May 13, 2024
4b03c14
Fix handling of concatenatedConfig for extensions
May 21, 2024
3b548f5
Add config modification docs
May 21, 2024
cae5861
Add test
May 22, 2024
8caea6e
Add example for x-x extension
May 22, 2024
f986398
Add viewBox to x logo
May 22, 2024
979777d
Merge branch 'master' into feat/custom-extension-value-render
ductaily Jun 12, 2024
a34f50a
Update package-lock.json
Jun 19, 2024
32cf262
Fix lint error
Jun 19, 2024
c630f89
Merge branch 'master' into feat/custom-extension-value-render
pavelkornev Jun 19, 2024
eed70c4
Merge branch 'refs/heads/master' into feat/custom-extension-value-render
Jul 23, 2024
350646a
Merge remote-tracking branch 'origin/feat/custom-extension-value-rend…
Jul 23, 2024
d91df2a
Merge branch 'master' into feat/custom-extension-value-render
ductaily Jul 31, 2024
3e57a3f
Add x-x extensions example.
Jul 31, 2024
1740980
Merge branch 'master' into feat/custom-extension-value-render
asyncapi-bot Jul 31, 2024
361a2c2
Merge branch 'master' into feat/custom-extension-value-render
ductaily Sep 2, 2024
aa7423b
Merge branch 'master' into feat/custom-extension-value-render
pavelkornev Sep 2, 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
7 changes: 7 additions & 0 deletions library/src/components/Extensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ import React from 'react';
import { Schema } from './Schema';

import { SchemaHelpers } from '../helpers';
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';

interface Props {
name?: string;
item: any;
}

export interface ExtensionComponentProps<V = any> {
propertyName: string;
propertyValue: V;
document: AsyncAPIDocumentInterface;
}

export const Extensions: React.FunctionComponent<Props> = ({
name = 'Extensions',
item,
Expand Down
17 changes: 17 additions & 0 deletions library/src/components/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SchemaInterface } from '@asyncapi/parser';

import { Href, CollapseButton, Markdown, Extensions } from './index';
import { SchemaHelpers } from '../helpers';
import { useConfig, useSpec } from '../contexts';

interface Props {
schemaName?: React.ReactNode;
Expand Down Expand Up @@ -37,6 +38,8 @@ export const Schema: React.FunctionComponent<Props> = ({
const { reverse, deepExpanded } = useContext(SchemaContext);
const [expanded, setExpanded] = useState(propExpanded || isArray);
const [deepExpand, setDeepExpand] = useState(false);
const config = useConfig();
const document = useSpec();

useEffect(() => {
if (!isArray) {
Expand Down Expand Up @@ -87,6 +90,20 @@ export const Schema: React.FunctionComponent<Props> = ({
schemaName
);

const extensions = config.extensions;

if (typeof schemaName === 'string' && extensions && extensions[schemaName]) {
const Component = extensions[schemaName];

return (
<Component
propertyValue={schema.const()}
propertyName={schemaName}
document={document}
/>
);
}

return (
<SchemaContext.Provider
value={{ reverse: !reverse, deepExpanded: deepExpand }}
Expand Down
3 changes: 3 additions & 0 deletions library/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ExtensionComponentProps } from '../components';

export interface ConfigInterface {
schemaID?: string;
show?: ShowConfig;
Expand All @@ -10,6 +12,7 @@ export interface ConfigInterface {
receiveLabel?: string;
requestLabel?: string;
replyLabel?: string;
extensions?: Record<string, React.ComponentType<ExtensionComponentProps>>;
}

export interface ShowConfig {
Expand Down
1 change: 1 addition & 0 deletions library/src/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export const defaultConfig: ConfigInterface = {
receiveLabel: RECEIVE_TEXT_LABEL_DEFAULT_TEXT,
requestLabel: REQUEST_LABEL_DEFAULT_TEXT,
replyLabel: REPLIER_LABEL_DEFAULT_TEXT,
extensions: {},
};
Loading