Skip to content

Commit

Permalink
fix(ui): redirect to schemaId don't work
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Oct 3, 2020
1 parent d209337 commit 9dd3998
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
65 changes: 23 additions & 42 deletions client/src/containers/Topic/Topic/TopicData/TopicData.jsx
Expand Up @@ -5,7 +5,7 @@ import './styles.scss';
import Table from '../../../../components/Table/Table';
import { formatDateTime } from '../../../../utils/converters';
import {
uriSchemaRegistry,
uriSchemaId,
uriTopicData,
uriTopicDataDelete,
uriTopicDataSearch, uriTopicDataSingleRecord,
Expand Down Expand Up @@ -52,7 +52,6 @@ class TopicData extends Root {
selectedTopic: this.props.topicId,
cleanupPolicy: '',
datetime: '',
schemas: [],
roles: JSON.parse(sessionStorage.getItem('roles')),
canDeleteRecords: false,
percent: 0,
Expand All @@ -69,7 +68,6 @@ class TopicData extends Root {
const { clusterId, topicId } = this.props.match.params;
const query = new URLSearchParams(this.props.location.search);

const roles = this.state.roles || {};
this.setState(
{
selectedCluster: clusterId,
Expand All @@ -81,7 +79,6 @@ class TopicData extends Root {
currentSearch: (query.get('search'))? query.get('search') : this.state.currentSearch,
offsets: (query.get('offset'))? this.getOffsetsByOffset(query.get('partition'), query.get('offset')) :
((query.get('after'))? this.getOffsetsByAfterString(query.get('after')): this.state.offsets),
canAccessSchema: roles.registry && roles.registry['registry/read']
},
() => {
if(query.get('single') !== null) {
Expand Down Expand Up @@ -174,37 +171,29 @@ class TopicData extends Root {
const {
selectedCluster,
selectedTopic,
canAccessSchema
} = this.state;

const requests = [this.getApi(uriTopicDataSingleRecord(selectedCluster, selectedTopic, partition, offset)),
this.getApi(uriTopicsPartitions(selectedCluster, selectedTopic))];
if (canAccessSchema) {
requests.push(this.getApi(uriSchemaRegistry(selectedCluster, '', '')));
}

this._fetchMessages(requests);
}


getMessages(filters = null, changePage = false) {
const {
selectedCluster,
selectedTopic,
canAccessSchema,
nextPage
} = this.state;

const requests = [this.getApi(uriTopicData(selectedCluster, selectedTopic, filters, changePage ? nextPage : undefined)),
this.getApi(uriTopicsPartitions(selectedCluster, selectedTopic))];
if (canAccessSchema) {
requests.push(this.getApi(uriSchemaRegistry(selectedCluster, '', '')));
}
const requests = [
this.getApi(uriTopicData(selectedCluster, selectedTopic, filters, changePage ? nextPage : undefined)),
this.getApi(uriTopicsPartitions(selectedCluster, selectedTopic))
];

this._fetchMessages(requests, changePage);

if (changePage) {
this.setUrlHistory(nextPage.substring(nextPage.indexOf("?") + 1, nextPage.length));
this.setUrlHistory(nextPage.substring(nextPage.indexOf('?') + 1, nextPage.length));
} else {
this.setUrlHistory(filters);
}
Expand All @@ -222,15 +211,10 @@ class TopicData extends Root {
Promise.all(requests)
.then(data => {
let tableMessages = [],
schemas = [],
pageNumberTemp, offsetsTemp, partitionCountTemp, nextPageTemp, recordCountTemp;

const messagesData = data[0].data;
const partitionData = data[1].data;
if (data.size === 3) {
const schemasData = data[2].data;
schemas = schemasData.results || [];
}

if (messagesData.results) {
tableMessages = this.handleMessages(messagesData.results);
Expand All @@ -248,7 +232,6 @@ class TopicData extends Root {
this.setState({
messages: tableMessages,
canDeleteRecords: messagesData.canDeleteRecords,
schemas: schemas,
pageNumber: (pageNumberTemp) ? pageNumberTemp : pageNumber,
partitionCount: (partitionCountTemp) ? partitionCountTemp : partitionCount,
nextPageInt: (nextPageTemp) ? nextPageTemp : nextPage,
Expand Down Expand Up @@ -400,6 +383,21 @@ class TopicData extends Root {
});
}

redirectToSchema(id) {
const { selectedCluster } = this.state;

this.getApi(uriSchemaId(selectedCluster, id))
.then(response => {
if (response.data) {
this.props.history.push({
pathname: `/ui/${selectedCluster}/schema/details/${response.data.subject}`,
schemaId: response.data.subject
});
} else {
toast.warn(`Unable to find the registry schema with id ${id} !`);
}
})
}

renderSortOptions() {
const { sortOptions } = this.state;
Expand Down Expand Up @@ -504,7 +502,6 @@ class TopicData extends Root {
loading
} = this.state;
let date = moment(datetime);
let { clusterId } = this.props.match.params;
const { history } = this.props;
const firstColumns = [
{ colName: 'Key', colSpan: 1 },
Expand Down Expand Up @@ -819,15 +816,7 @@ class TopicData extends Root {
<span
className="badge badge-primary clickable"
onClick={() => {
let schema = this.state.schemas.find(el => {
return el.id === obj.schema.key;
});
if (schema) {
this.props.history.push({
pathname: `/ui/${clusterId}/schema/details/${schema.subject}`,
schemaId: schema.subject
});
}
this.redirectToSchema(obj.schema.key);
}}
>
Key: {obj[col.accessor].key}
Expand All @@ -838,15 +827,7 @@ class TopicData extends Root {
<span
className="badge badge-primary clickable schema-value"
onClick={() => {
let schema = this.state.schemas.find(el => {
return el.id === obj.schema.value;
});
if (schema) {
this.props.history.push({
pathname: `/ui/${clusterId}/schema/details/${schema.subject}`,
schemaId: schema.subject
});
}
this.redirectToSchema(obj.schema.key);
}}
>
Value: {obj[col.accessor].value}
Expand Down
5 changes: 5 additions & 0 deletions client/src/utils/endpoints.js
Expand Up @@ -149,6 +149,11 @@ export const uriDeleteDefinition = (clusterId, connectId, definitionId) => {
export const uriSchemaRegistry = (clusterId, search, pageNumber) => {
return `${apiUrl}/${clusterId}/schema?&search=${search}&page=${pageNumber}`;
};

export const uriSchemaId = (clusterId, id) => {
return `${apiUrl}/${clusterId}/schema/id/${id}`;
};

export const uriSchemaVersions = (clusterId, subject) => {
return `${apiUrl}/${clusterId}/schema/${subject}/version`;
};
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/akhq/controllers/SchemaController.java
Expand Up @@ -121,6 +121,16 @@ private Schema registerSchema(String cluster, @Body Schema schema) throws IOExce
return register;
}

@Get("api/{cluster}/schema/id/{id}")
@Operation(tags = {"schema registry"}, summary = "Find a schema by id")
public Schema redirectId(
HttpRequest<?> request,
String cluster,
Integer id
) throws IOException, RestClientException, ExecutionException, InterruptedException {
return this.schemaRepository.getById(cluster, id);
}

@Get("api/{cluster}/schema/{subject}/version")
@Operation(tags = {"schema registry"}, summary = "List all version for a schema")
public List<Schema> versions(HttpRequest<?> request, String cluster, String subject) throws IOException, RestClientException {
Expand Down

0 comments on commit 9dd3998

Please sign in to comment.