-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/display resource yaml #81
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
Changes from 42 commits
ff122a3
a8469a2
7c5dc82
57632d2
f552855
d63dd7a
99ddbdb
6890ece
7221234
f4226e2
d069cc5
5a67fb4
49c9ce1
794967d
9e58f60
567154c
60d9100
bf417c3
a90d9f1
4d832ce
06dbcae
41354fe
d3ae2ef
f4ff4f0
092b17f
0316081
775cb8f
e598273
4a1601b
c7ab2d3
cdea1f6
1ed594b
ed120af
0f5b052
2a142ed
dea32ec
c9f5416
75b845d
54174b2
a07b296
3571ba4
190a4b0
4161df2
aa13880
096c5f4
18d3f63
2bafa7a
c2df896
046afb0
428e14f
88c9baa
b2da1b2
c37f57a
77c089f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ResourceProps } from './YamlViewButton.tsx'; | ||
import { FC } from 'react'; | ||
|
||
import { stringify } from 'yaml'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import { ResourceObject } from '../../lib/api/types/crate/resourceObject.ts'; | ||
import Loading from '../Shared/Loading.tsx'; | ||
import IllustratedError from '../Shared/IllustratedError.tsx'; | ||
import YamlViewer from './YamlViewer.tsx'; | ||
import useResource from '../../lib/api/useApiResource'; | ||
|
||
export const YamlLoader: FC<ResourceProps> = ({ | ||
workspaceName, | ||
resourceType, | ||
resourceName, | ||
}) => { | ||
const { isLoading, data, error } = useResource( | ||
ResourceObject(workspaceName ?? '', resourceType, resourceName), | ||
); | ||
const { t } = useTranslation(); | ||
if (isLoading) return <Loading />; | ||
if (error) { | ||
return <IllustratedError error={t('common.cannotLoadData')} />; | ||
} | ||
|
||
return ( | ||
<YamlViewer | ||
yamlString={stringify(data)} | ||
filename={`${workspaceName ? `${workspaceName}_` : ''}${resourceType}_${resourceName}`} | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||
import { Bar, Button, Dialog } from '@ui5/webcomponents-react'; | ||||||
import { FC, useState } from 'react'; | ||||||
import { YamlLoader } from './YamlLoader.tsx'; | ||||||
import { useTranslation } from 'react-i18next'; | ||||||
|
||||||
export type ResourceProps = { | ||||||
lucasgoral marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
workspaceName?: string; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this ever be Just wondering if we can simply write
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for the Project YAML it is empty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, in this case I’m wondering what if we made this a bit more generic by decoupling from the workspace/project context? Something like: export type YamlViewButtonProps = {
apiPath: string;
localFilename: string;
} After all, it’s essentially just a dialog that displays downloads and YAML content. It probably shouldn’t need to know the specifics of how to retrieve that data. Just thinking out loud here - we’ll likely need to revisit the fetch logic when we implement GraphQL anyway, so we can see how this approach works then. |
||||||
resourceType: 'projects' | 'workspaces' | 'managedcontrolplanes'; | ||||||
resourceName: string; | ||||||
}; | ||||||
|
||||||
export const YamlViewButton: FC<ResourceProps> = ({ | ||||||
workspaceName, | ||||||
resourceType, | ||||||
resourceName, | ||||||
}) => { | ||||||
const [isOpen, setIsOpen] = useState(false); | ||||||
const { t } = useTranslation(); | ||||||
return ( | ||||||
<span> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is wrapped in span so it it display: inline instead of display:block. So I can put it next to some text. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn’t |
||||||
<Dialog | ||||||
open={isOpen} | ||||||
lucasgoral marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
stretch | ||||||
footer={ | ||||||
<Bar | ||||||
design="Footer" | ||||||
endContent={ | ||||||
<Button design="Emphasized" onClick={() => setIsOpen(false)}> | ||||||
{t('common.close')} | ||||||
</Button> | ||||||
} | ||||||
/> | ||||||
} | ||||||
> | ||||||
<YamlLoader | ||||||
workspaceName={workspaceName} | ||||||
resourceName={resourceName} | ||||||
resourceType={resourceType} | ||||||
/> | ||||||
</Dialog> | ||||||
<Button | ||||||
icon="document" | ||||||
aria-label={t('buttons.viewResource')} | ||||||
title={t('buttons.viewResource')} | ||||||
onClick={() => { | ||||||
setIsOpen(true); | ||||||
}} | ||||||
/> | ||||||
</span> | ||||||
); | ||||||
}; |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||
.container { | ||||||||
position: relative; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m wondering if we should change the overflow to get rid of the horizontal scrollbar, although it feels a bit hacky. What do you think?
Suggested change
I don’t think there’s any guarantee that we can fit the content horizontally to the screen, so maybe not the best idea. 🤔 |
||||||||
} | ||||||||
|
||||||||
.buttons { | ||||||||
position: sticky; | ||||||||
lucasgoral marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
top: 0; | ||||||||
right: 0; | ||||||||
z-index: 1; | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,85 @@ | ||||||
import { FC } from 'react'; | ||||||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; | ||||||
import { | ||||||
materialLight, | ||||||
materialDark, | ||||||
} from 'react-syntax-highlighter/dist/esm/styles/prism'; // You can choose different styles | ||||||
|
} from 'react-syntax-highlighter/dist/esm/styles/prism'; // You can choose different styles | |
} from 'react-syntax-highlighter/dist/esm/styles/prism'; |
Good to know, though 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create a custom hook that handles both error handling and potentially a countdown timer (similar to other copy buttons that update their display after a few seconds).
For example, something like: const { copy, recentlyCopied } = useCopyToClipboard(2000);
What are your thoughts on this? If you agree, I’d suggest adding it as a new backlog item (i.e. not as a part of this pull request).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed we already have a DownloadKubeconfig
function that handles file downloads.
I think it might be worth considering extracting this logic into a separate function, like useFileDownload()
.
Perhaps we could tackle this refactoring in a follow-up task? What are your thoughts?
Uh oh!
There was an error while loading. Please reload this page.