eschutho commented on code in PR #20877: URL: https://github.com/apache/superset/pull/20877#discussion_r942877780
########## superset-frontend/src/SqlLab/components/SqlEditorTabHeader/index.tsx: ########## @@ -0,0 +1,146 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { useMemo } from 'react'; +import { bindActionCreators } from 'redux'; +import { useSelector, useDispatch, shallowEqual } from 'react-redux'; +import { Dropdown } from 'src/components/Dropdown'; +import { Menu } from 'src/components/Menu'; +import { styled, t, QueryState } from '@superset-ui/core'; +import { + removeQueryEditor, + removeAllOtherQueryEditors, + queryEditorSetTitle, + cloneQueryToNewTab, + toggleLeftBar, +} from 'src/SqlLab/actions/sqlLab'; +import { QueryEditor, SqlLabRootState } from 'src/SqlLab/types'; +import TabStatusIcon from '../TabStatusIcon'; + +const TabTitleWrapper = styled.div` + display: flex; + align-items: center; +`; +const TabTitle = styled.span` + margin-right: ${({ theme }) => theme.gridUnit * 2}px; + text-transform: none; +`; + +interface Props { + queryEditor: QueryEditor; +} + +const SqlEditorTabHeader: React.FC<Props> = ({ queryEditor }) => { + const qe = useSelector<SqlLabRootState, QueryEditor>( + ({ sqlLab: { unsavedQueryEditor } }) => ({ + ...queryEditor, + ...(queryEditor.id === unsavedQueryEditor.id && unsavedQueryEditor), + }), + shallowEqual, + ); + const queryStatus = useSelector<SqlLabRootState, QueryState>( + ({ sqlLab }) => sqlLab.queries[qe.latestQueryId || '']?.state || '', + ); + const dispatch = useDispatch(); + const actions = useMemo( + () => + bindActionCreators( + { + removeQueryEditor, + removeAllOtherQueryEditors, + queryEditorSetTitle, + cloneQueryToNewTab, + toggleLeftBar, + }, + dispatch, + ), + [dispatch], + ); + + function renameTab() { + const newTitle = prompt(t('Enter a new title for the tab')); + if (newTitle) { + actions.queryEditorSetTitle(qe, newTitle); + } + } + + return ( + <TabTitleWrapper> + <Dropdown Review Comment: Not sure if this was expected, but can we bring back the `trigger={['click']}` on this component, too? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
