8000 Fix reader allows update schema registry · Pull Request #518 · tchiotludo/akhq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix reader allows update schema registry #518

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 1 commit into from
Nov 19, 2020
Merged
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
106 changes: 59 additions & 47 deletions client/src/containers/Schema/SchemaDetail/Schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Schema extends Root {
schemaId: this.props.history.schemaId || this.props.match.params.schemaId,
selectedTab: 'update',
totalVersions: 0,
schemaVersions: []
schemaVersions: [],
roles: JSON.parse(sessionStorage.getItem('roles'))
};

tabs = ['update', 'versions'];
Expand All @@ -36,18 +37,22 @@ class Schema extends Root {

async getSchemaVersions() {
let schemas = [];
const { clusterId, schemaId } = this.state;
const tabSelected = getSelectedTab(this.props, this.tabs);
const { clusterId, schemaId, roles } = this.state;
let tabSelected = getSelectedTab(this.props, this.tabs);

if(!roles.registry['registry/update'] && tabSelected === 'update') {
tabSelected = 'versions';
}

schemas = await this.getApi(endpoints.uriSchemaVersions(clusterId, schemaId));
this.setState({
schemaVersions: schemas.data,
totalVersions: schemas.data.length,
selectedTab: tabSelected === 'versions' ? tabSelected : 'update'
},
() => {
this.props.history.replace(`/ui/${clusterId}/schema/details/${schemaId}/${this.state.selectedTab}`);
});
schemaVersions: schemas.data,
totalVersions: schemas.data.length,
selectedTab: tabSelected === 'versions' ? tabSelected : 'update'
},
() => {
this.props.history.replace(`/ui/${clusterId}/schema/details/${schemaId}/${this.state.selectedTab}`);
});
}

renderSelectedTab() {
Expand All @@ -59,61 +64,68 @@ class Schema extends Root {
switch (selectedTab) {
case 'update':
return (
<SchemaUpdate
getSchemaVersions={() => {
this.getSchemaVersions();
}}
schemaId={schemaId}
history={history}
match={match}
/>
<SchemaUpdate
getSchemaVersions={() => {
this.getSchemaVersions();
}}
schemaId={schemaId}
history={history}
match={match}
/>
);
case 'versions':
return (
<SchemaVersions
<SchemaVersions
schemaName={schemaId}
clusterId={clusterId}
schemas={schemaVersions}
history={history}
match={match}
/>
);
default:
return <SchemaVersions
schemaName={schemaId}
clusterId={clusterId}
schemas={schemaVersions}
history={history}
match={match}
/>
);
default:
return <SchemaUpdate schemaId={schemaId} history={history} match={match} />;
/>;
}
}

render() {
const { clusterId, schemaId, totalVersions } = this.state;
const { clusterId, schemaId, totalVersions, roles } = this.state;

return (
<div>
<Header title={`Schema: ${schemaId}`} history={this.props.history} />
<div className="tabs-container">
<ul className="nav nav-tabs" role="tablist">
<li className="nav-item">
<Link to={`/ui/${clusterId}/schema/details/${schemaId}/update`}
className={this.tabClassName('update')}
>
Update
</Link>
</li>
<li className="nav-item">
<Link to={`/ui/${clusterId}/schema/details/${schemaId}/versions`}
className={this.tabClassName('versions')}
>
Versions <span className="badge badge-secondary">{totalVersions}</span>
</Link>
</li>
</ul>
<div>
<Header title={`Schema: ${schemaId}`} history={this.props.history} />
<div className="tabs-container">
<ul className="nav nav-tabs" role="tablist">
{roles.registry['registry/update'] && (
<li className="nav-item">
<Link to={`/ui/${clusterId}/schema/details/${schemaId}/update`}
className={this.tabClassName('update')}
>
Update
</Link>
</li>)}
<li className="nav-item">
<Link to={`/ui/${clusterId}/schema/details/${schemaId}/versions`}
className={this.tabClassName('versions')}
>
Versions <span className="badge badge-secondary">{totalVersions}</span>
</Link>
</li>
</ul>

<div className="tab-content">
<div className="tab-pane active" role="tabpanel">
{this.renderSelectedTab()}
<div className="tab-content">
<div className="tab-pane active" role="tabpanel">
{this.renderSelectedTab()}
</div>
</div>
</div>
</div>
</div>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class SchemaUpdate extends Form {
compatibility: '',
schema: ''
},
errors: {}
errors: {},
roles: JSON.parse(sessionStorage.getItem('roles'))
};

schema = {
Expand Down Expand Up @@ -95,15 +96,15 @@ class SchemaUpdate extends Form {
};

this.postApi(uriUpdateSchema(clusterId, formData.subject), body)
.then(() => {
toast.success(`Schema '${formData.subject}' is updated`);
this.props.getSchemaVersions();
window.location.reload(false);
});
.then(() => {
toast.success(`Schema '${formData.subject}' is updated`);
this.props.getSchemaVersions();
window.location.reload(false);
});
}

render() {
const { compatibilityOptions } = this.state;
const { compatibilityOptions, roles } = this.state;

return (
<form
Expand Down Expand Up @@ -135,13 +136,14 @@ class SchemaUpdate extends Form {
'col-sm-10'
)}
{this.renderJSONInput('schema', 'Latest Schema', value => {
let { formData } = { ...this.state };
formData.schema = value;
this.setState({ formData });
},
'col-sm-10'
)}
{this.renderButton('Update', undefined, undefined, 'submit')}
let { formData } = { ...this.state };
formData.schema = value;
this.setState({ formData });
},
'col-sm-10'
)}
{roles.registry['registry/update'] && (
this.renderButton('Update', undefined, undefined, 'submit'))}
</fieldset>
</form>
);
Expand Down
9 changes: 9 additions & 0 deletions client/src/utils/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ class Routes extends Root {
{roles && roles.registry && roles.registry['registry/insert'] && (
<Route exact path="/ui/:clusterId/schema/create" component={SchemaCreate} />
)}

{roles && roles.registry && roles.registry['registry/update'] && (
<Route
exact
path="/ui/:clusterId/schema/details/:schemaId/update"
component={Schema}
/>
)}

{roles && roles.registry && roles.registry['registry/read'] && (
<Route
exact
Expand Down
0