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

FE,BE: Add download button #4323

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -45,6 +45,7 @@ public static class Cluster {
MetricsConfigData metrics;
Map<String, Object> properties;
boolean readOnly = false;
boolean messageDownloadAllowed = false;
List<SerdeConfig> serde;
String defaultKeySerde;
String defaultValueSerde;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class InternalClusterState {
private BigDecimal bytesInPerSec;
private BigDecimal bytesOutPerSec;
private Boolean readOnly;
private Boolean isMessageDownloadAllowed;

public InternalClusterState(KafkaCluster cluster, Statistics statistics) {
name = cluster.getName();
Expand Down Expand Up @@ -75,6 +76,7 @@ public InternalClusterState(KafkaCluster cluster, Statistics statistics) {
outOfSyncReplicasCount = partitionsStats.getOutOfSyncReplicasCount();
underReplicatedPartitionCount = partitionsStats.getUnderReplicatedPartitionCount();
readOnly = cluster.isReadOnly();
isMessageDownloadAllowed = cluster.isMessageDownloadAllowed();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class KafkaCluster {
private final String bootstrapServers;
private final Properties properties;
private final boolean readOnly;
private final boolean isMessageDownloadAllowed;
private final MetricsConfig metricsConfig;
private final DataMasking masking;
private final PollingSettings pollingSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public KafkaCluster create(ClustersProperties properties,
builder.bootstrapServers(clusterProperties.getBootstrapServers());
builder.properties(convertProperties(clusterProperties.getProperties()));
builder.readOnly(clusterProperties.isReadOnly());
builder.isMessageDownloadAllowed(clusterProperties.isMessageDownloadAllowed());
builder.masking(DataMasking.create(clusterProperties.getMasking()));
builder.pollingSettings(PollingSettings.create(clusterProperties, properties));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,8 @@ components:
type: number
readOnly:
type: boolean
isMessageDownloadAllowed:
type: boolean
version:
type: string
features:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const ClusterPage: React.FC = () => {
hasAclViewConfigured:
features.includes(ClusterFeaturesEnum.KAFKA_ACL_VIEW) ||
features.includes(ClusterFeaturesEnum.KAFKA_ACL_EDIT),
isMessageDownloadAllowed: cluster?.isMessageDownloadAllowed || false,
};
}, [clusterName, data]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Button } from 'components/common/Button/Button';
import { useSearchParams } from 'react-router-dom';
import { MESSAGES_PER_PAGE } from 'lib/constants';
import * as S from 'components/common/NewTable/Table.styled';
import ClusterContext from 'components/contexts/ClusterContext';

import PreviewModal from './PreviewModal';
import Message, { PreviewFilter } from './Message';
Expand All @@ -28,6 +29,7 @@ const MessagesTable: React.FC = () => {
const { isLive } = useContext(TopicMessagesContext);

const messages = useAppSelector(getTopicMessges);
const { isMessageDownloadAllowed } = useContext(ClusterContext);
const isFetching = useAppSelector(getIsTopicMessagesFetching);

const isTailing = isLive && isFetching;
Expand All @@ -51,6 +53,28 @@ const MessagesTable: React.FC = () => {
setSearchParams(searchParams);
};

const handleDownload = () => {
const download = (filename: string, content: Blob) => {
// create anchor tag to download file
const url = URL.createObjectURL(content);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);

// download file
link.click();

// clean up
document.body.removeChild(link);
URL.revokeObjectURL(url);
};

const jsonString = JSON.stringify(messages);
const content = new Blob([jsonString], { type: 'application/json' });
download('download.json', content);
};

return (
<div style={{ position: 'relative' }}>
{previewFor !== null && (
Expand Down Expand Up @@ -136,6 +160,14 @@ const MessagesTable: React.FC = () => {
>
Next →
</Button>
<Button
buttonType="secondary"
buttonSize="L"
onClick={handleDownload}
disabled={!isMessageDownloadAllowed}
>
Download
</Button>
</S.Pages>
</S.Pagination>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ export interface ContextProps {
hasKafkaConnectConfigured: boolean;
hasSchemaRegistryConfigured: boolean;
isTopicDeletionAllowed: boolean;
isMessageDownloadAllowed: boolean;
}

export const initialValue: ContextProps = {
isReadOnly: false,
hasKafkaConnectConfigured: false,
hasSchemaRegistryConfigured: false,
isTopicDeletionAllowed: true,
isMessageDownloadAllowed: false,
};
const ClusterContext = React.createContext(initialValue);

Expand Down