forked from provectus/kafka-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Topic settings editing (provectus#55)
* Topic editing * Remove old code * Implement unique field name select * Final changes to topic editing * Cleanup eslint.json
- Loading branch information
Showing
39 changed files
with
5,876 additions
and
3,545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,6 @@ build/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
/kafka-ui-api/app/node | ||
/kafka-ui-api/app/node | ||
|
||
.DS_Store |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
kafka-ui-react-app/src/components/Topics/Details/Settings/SettingsEditButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
interface Props { | ||
to: string; | ||
} | ||
|
||
const SettingsEditButton: React.FC<Props> = ({ to }) => ( | ||
<Link to={to}> | ||
<button type="button" className="button is-small is-warning"> | ||
Edit settings | ||
</button> | ||
</Link> | ||
); | ||
|
||
export default SettingsEditButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import React from 'react'; | ||
import { | ||
ClusterName, | ||
TopicFormData, | ||
TopicName, | ||
TopicConfigByName, | ||
TopicWithDetailedInfo, | ||
CleanupPolicy, | ||
} from 'redux/interfaces'; | ||
import { useForm, FormContext } from 'react-hook-form'; | ||
import { camelCase } from 'lodash'; | ||
|
||
import TopicForm from '../shared/Form/TopicForm'; | ||
import FormBreadcrumbs from '../shared/Form/FormBreadcrumbs'; | ||
|
||
interface Props { | ||
clusterName: ClusterName; | ||
topicName: TopicName; | ||
topic?: TopicWithDetailedInfo; | ||
isFetched: boolean; | ||
isTopicDetailsFetched: boolean; | ||
isTopicUpdated: boolean; | ||
fetchTopicDetails: (clusterName: ClusterName, topicName: TopicName) => void; | ||
fetchTopicConfig: (clusterName: ClusterName, topicName: TopicName) => void; | ||
updateTopic: (clusterName: ClusterName, form: TopicFormData) => void; | ||
redirectToTopicPath: (clusterName: ClusterName, topicName: TopicName) => void; | ||
resetUploadedState: () => void; | ||
} | ||
|
||
const DEFAULTS = { | ||
partitions: 1, | ||
replicationFactor: 1, | ||
minInSyncReplicas: 1, | ||
cleanupPolicy: CleanupPolicy.Delete, | ||
retentionBytes: -1, | ||
maxMessageBytes: 1000012, | ||
}; | ||
|
||
const topicParams = (topic: TopicWithDetailedInfo | undefined) => { | ||
if (!topic) { | ||
return DEFAULTS; | ||
} | ||
|
||
const { name, replicationFactor } = topic; | ||
|
||
const configs = topic.config?.reduce( | ||
(result: { [name: string]: string }, param) => { | ||
result[camelCase(param.name)] = param.value || param.defaultValue; | ||
return result; | ||
}, | ||
{} | ||
); | ||
|
||
return { | ||
...DEFAULTS, | ||
name, | ||
partitions: topic.partitionCount || DEFAULTS.partitions, | ||
replicationFactor, | ||
...configs, | ||
}; | ||
}; | ||
|
||
let formInit = false; | ||
|
||
const Edit: React.FC<Props> = ({ | ||
clusterName, | ||
topicName, | ||
topic, | ||
isFetched, | ||
isTopicDetailsFetched, | ||
isTopicUpdated, | ||
fetchTopicDetails, | ||
fetchTopicConfig, | ||
updateTopic, | ||
redirectToTopicPath, | ||
}) => { | ||
const defaultValues = topicParams(topic); | ||
|
||
const methods = useForm<TopicFormData>({ defaultValues }); | ||
|
||
const [isSubmitting, setIsSubmitting] = React.useState<boolean>(false); | ||
|
||
React.useEffect(() => { | ||
fetchTopicConfig(clusterName, topicName); | ||
fetchTopicDetails(clusterName, topicName); | ||
}, [fetchTopicConfig, fetchTopicDetails, clusterName, topicName]); | ||
|
||
React.useEffect(() => { | ||
if (isSubmitting && isTopicUpdated) { | ||
const { name } = methods.getValues(); | ||
redirectToTopicPath(clusterName, name); | ||
} | ||
}, [isSubmitting, isTopicUpdated, redirectToTopicPath, clusterName, methods]); | ||
|
||
if (!isFetched || !isTopicDetailsFetched || !topic || !topic.config) { | ||
return null; | ||
} | ||
|
||
if (!formInit) { | ||
methods.reset(defaultValues); | ||
formInit = true; | ||
} | ||
|
||
const config: TopicConfigByName = { | ||
byName: {}, | ||
}; | ||
|
||
topic.config.forEach((param) => { | ||
config.byName[param.name] = param; | ||
}); | ||
|
||
const onSubmit = async (data: TopicFormData) => { | ||
setIsSubmitting(true); | ||
updateTopic(clusterName, data); | ||
}; | ||
|
||
return ( | ||
<div className="section"> | ||
<div className="level"> | ||
<FormBreadcrumbs | ||
clusterName={clusterName} | ||
topicName={topicName} | ||
current="Edit Topic" | ||
/> | ||
</div> | ||
|
||
<div className="box"> | ||
{/* eslint-disable-next-line react/jsx-props-no-spreading */} | ||
<FormContext {...methods}> | ||
<TopicForm | ||
topicName={topicName} | ||
config={config} | ||
isSubmitting={isSubmitting} | ||
isEditing | ||
onSubmit={methods.handleSubmit(onSubmit)} | ||
/> | ||
</FormContext> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Edit; |
63 changes: 63 additions & 0 deletions
63
kafka-ui-react-app/src/components/Topics/Edit/EditContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { connect } from 'react-redux'; | ||
import { | ||
RootState, | ||
ClusterName, | ||
TopicFormData, | ||
TopicName, | ||
Action, | ||
} from 'redux/interfaces'; | ||
import { withRouter, RouteComponentProps } from 'react-router-dom'; | ||
import { | ||
updateTopic, | ||
fetchTopicConfig, | ||
fetchTopicDetails, | ||
} from 'redux/actions'; | ||
import { | ||
getTopicConfigFetched, | ||
getTopicUpdated, | ||
getIsTopicDetailsFetched, | ||
getFullTopic, | ||
} from 'redux/reducers/topics/selectors'; | ||
import { clusterTopicPath } from 'lib/paths'; | ||
import { ThunkDispatch } from 'redux-thunk'; | ||
import Edit from './Edit'; | ||
|
||
interface RouteProps { | ||
clusterName: ClusterName; | ||
topicName: TopicName; | ||
} | ||
|
||
type OwnProps = RouteComponentProps<RouteProps>; | ||
|
||
const mapStateToProps = ( | ||
state: RootState, | ||
{ | ||
match: { | ||
params: { topicName, clusterName }, | ||
}, | ||
}: OwnProps | ||
) => ({ | ||
clusterName, | ||
topicName, | ||
topic: getFullTopic(state, topicName), | ||
isFetched: getTopicConfigFetched(state), | ||
isTopicDetailsFetched: getIsTopicDetailsFetched(state), | ||
isTopicUpdated: getTopicUpdated(state), | ||
}); | ||
|
||
const mapDispatchToProps = ( | ||
dispatch: ThunkDispatch<RootState, undefined, Action>, | ||
{ history }: OwnProps | ||
) => ({ | ||
fetchTopicDetails: (clusterName: ClusterName, topicName: TopicName) => | ||
dispatch(fetchTopicDetails(clusterName, topicName)), | ||
fetchTopicConfig: (clusterName: ClusterName, topicName: TopicName) => | ||
dispatch(fetchTopicConfig(clusterName, topicName)), | ||
updateTopic: (clusterName: ClusterName, form: TopicFormData) => | ||
dispatch(updateTopic(clusterName, form)), | ||
redirectToTopicPath: (clusterName: ClusterName, topicName: TopicName) => { | ||
history.push(clusterTopicPath(clusterName, topicName)); | ||
}, | ||
}); | ||
|
||
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Edit)); |
20 changes: 0 additions & 20 deletions
20
kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamOptions.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.