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

#44120742 SS-Upg | Переводы #188

Open
wants to merge 16 commits into
base: 4.1.1-dodo
Choose a base branch
from
Open
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 @@ -40,13 +40,39 @@ function tryParsePayload(payload: Payload) {
/**
* Try appending search params to an URL if needed.
*/
// function getFullUrl(partialUrl: string, params: CallApi['searchParams']) {
// if (params) {
// const url = new URL(partialUrl, window.location.href);
// const search =
// params instanceof URLSearchParams ? params : new URLSearchParams(params);
// // will completely override any existing search params
// url.search = search.toString();
// return url.href;
// }
// return partialUrl;
// }
// DODO changed 44120742
function getFullUrl(partialUrl: string, params: CallApi['searchParams']) {
if (params) {
const splitPartial = partialUrl.split('?language=');
let languageAddition = '';
if (splitPartial && splitPartial.length > 1) {
languageAddition = splitPartial[1];
}

const url = new URL(partialUrl, window.location.href);
const search =
params instanceof URLSearchParams ? params : new URLSearchParams(params);
// will completely override any existing search params
url.search = search.toString();

if (languageAddition) {
url.searchParams.set('language', languageAddition);
} else {
const search =
params instanceof URLSearchParams
? params
: new URLSearchParams(params);

// will completely override any existing search params
url.search = search.toString();
}
return url.href;
}
return partialUrl;
Expand Down
18 changes: 18 additions & 0 deletions superset-frontend/src/DodoExtensions/Common/LanguageIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { StyledPencil } from './StyledPencil';
import { StyledFlag } from './StyledFlag';
import { TitleLabel } from './TitleLabel';

const LanguageIndicator = ({
language = 'gb',
canEdit,
}: {
language: 'gb' | 'ru';
canEdit?: boolean;
}) => (
<TitleLabel>
<StyledFlag language={language} />
{canEdit && <StyledPencil />}
</TitleLabel>
);

export { LanguageIndicator };
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { styled } from '@superset-ui/core';

// eslint-disable-next-line theme-colors/no-literal-colors
const LanguageIndicatorWrapper = styled.div`
display: flex;
align-items: flex-start;
justify-content: flex-start;
flex-direction: row;
margin-bottom: 4px;
min-height: 26px;
font-size: ${({ theme }) => theme.typography.sizes.s}px;
color: ${({ theme }) => theme.colors.grayscale.dark1};

span {
&:nth-child(n + 1) {
margin-left: 12px;
}
}
.editable-title--editing {
color: ${({ theme }) => theme.colors.primary.base};
}
&:hover {
.editable-title {
color: ${({ theme }) => theme.colors.grayscale.base};
}
.editable-title--editing {
color: ${({ theme }) => theme.colors.primary.base};
}
}
`;

export { LanguageIndicatorWrapper };
25 changes: 25 additions & 0 deletions superset-frontend/src/DodoExtensions/Common/StyledFlag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// DODO added
import { styled } from '@superset-ui/core';
import { FC } from 'react';

const Flag = styled.i<{ $pressToTheBottom: boolean }>`
margin-top: ${props => props.$pressToTheBottom ?? '2px'};
`;

type Props = {
language: string;
style?: Record<string, string>;
pressToTheBottom?: boolean;
};

const StyledFlag: FC<Props> = ({
language = 'gb',
style = {},
pressToTheBottom = true,
}) => (
<div style={style} className="f16">
<Flag className={`flag ${language}`} $pressToTheBottom={pressToTheBottom} />
</div>
);

export { StyledFlag };
11 changes: 11 additions & 0 deletions superset-frontend/src/DodoExtensions/Common/StyledPencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { styled } from '@superset-ui/core';

const Pencil = styled.i`
margin-left: 6px;
margin-top: 6px;
font-size: 12px;
`;

const StyledPencil = () => <Pencil className="fa fa-pencil" />;

export { StyledPencil };
8 changes: 8 additions & 0 deletions superset-frontend/src/DodoExtensions/Common/TitleLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { styled } from '@superset-ui/core';

const TitleLabel = styled.span`
display: flex;
padding: 2px 0;
`;

export { TitleLabel };
19 changes: 19 additions & 0 deletions superset-frontend/src/DodoExtensions/Common/TitleWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { styled } from '@superset-ui/core';

const TitleWrapper = styled.div`
display: flex;
align-items: flex-start;
justify-content: flex-start;
flex-direction: row;
margin-bottom: 8px;
span {
margin-left: 12px;
&:first-child {
margin-left: 0;
}
}
`;

export { TitleWrapper };
15 changes: 15 additions & 0 deletions superset-frontend/src/DodoExtensions/Common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TitleWrapper } from 'src/DodoExtensions/Common/TitleWrapper';
import { TitleLabel } from 'src/DodoExtensions/Common/TitleLabel';
import { StyledFlag } from 'src/DodoExtensions/Common/StyledFlag';
import { StyledPencil } from 'src/DodoExtensions/Common/StyledPencil';
import { LanguageIndicator } from 'src/DodoExtensions/Common/LanguageIndicator';
import { LanguageIndicatorWrapper } from 'src/DodoExtensions/Common/LanguageIndicatorWrapper';

export {
TitleWrapper,
TitleLabel,
StyledFlag,
StyledPencil,
LanguageIndicator,
LanguageIndicatorWrapper,
};
3 changes: 0 additions & 3 deletions superset-frontend/src/components/EditableTitle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ export default function EditableTitle({
css={(theme: SupersetTheme) => css`
color: ${theme.colors.grayscale.dark1};
text-decoration: none;
:hover {
text-decoration: underline;
}
display: inline-block;
`}
>
Expand Down
5 changes: 4 additions & 1 deletion superset-frontend/src/dashboard/actions/dashboardLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ export function updateDashboardTitle(text) {
export const DASHBOARD_TITLE_CHANGED = 'DASHBOARD_TITLE_CHANGED';

// call this one when it's not an undo-able action
export function dashboardTitleChanged(text) {
// export function dashboardTitleChanged(text) {
// DODO changed 44120742
export function dashboardTitleChanged(text, textRU) {
return {
type: DASHBOARD_TITLE_CHANGED,
text,
textRU, // DODO added 44120742
};
}

Expand Down
7 changes: 6 additions & 1 deletion superset-frontend/src/dashboard/actions/dashboardState.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export function saveDashboardRequest(data, id, saveType) {
certification_details,
css,
dashboard_title,
dashboard_title_RU, // DODO added 44120742
owners,
roles,
slug,
Expand All @@ -304,7 +305,9 @@ export function saveDashboardRequest(data, id, saveType) {
certification_details:
certified_by && certification_details ? certification_details : '',
css: css || '',
dashboard_title: dashboard_title || t('[ untitled dashboard ]'),
// dashboard_title: dashboard_title || t('[ untitled dashboard ]'),
dashboard_title: dashboard_title || '[ untitled dashboard ]', // DODO changed 44120742
dashboard_title_RU: dashboard_title_RU || '[ безымянный дашборд ]', // DODO added 44120742
owners: ensureIsArray(owners).map(o => (hasId(o) ? o.id : o)),
roles: !isFeatureEnabled(FeatureFlag.DashboardRbac)
? undefined
Expand Down Expand Up @@ -445,6 +448,7 @@ export function saveDashboardRequest(data, id, saveType) {
certification_details: cleanedData.certification_details,
css: cleanedData.css,
dashboard_title: cleanedData.dashboard_title,
dashboard_title_RU: cleanedData.dashboard_title_RU, // DODO added 44120742
slug: cleanedData.slug,
owners: cleanedData.owners,
roles: cleanedData.roles,
Expand Down Expand Up @@ -519,6 +523,7 @@ export function saveDashboardRequest(data, id, saveType) {
cleanedData.metadata.filter_scopes = serializedFilterScopes;
const copyPayload = {
dashboard_title: cleanedData.dashboard_title,
dashboard_title_RU: cleanedData.dashboard_title_RU, // DODO added 44120742
css: cleanedData.css,
duplicate_slices: cleanedData.duplicate_slices,
json_metadata: JSON.stringify(cleanedData.metadata),
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/dashboard/actions/hydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export const hydrateDashboard =
type: DASHBOARD_HEADER_TYPE,
meta: {
text: dashboard.dashboard_title,
textRU: dashboard.dashboard_title_RU, // DODO added 44120742
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '@superset-ui/core';
import { Global } from '@emotion/react';
import { useDispatch, useSelector } from 'react-redux';
import { bootstrapData } from 'src/preamble';
import ErrorBoundary from 'src/components/ErrorBoundary';
import BuilderComponentPane from 'src/dashboard/components/BuilderComponentPane';
import DashboardHeader from 'src/dashboard/containers/DashboardHeader';
Expand Down Expand Up @@ -84,6 +85,36 @@ import DashboardWrapper from './DashboardWrapper';

type DashboardBuilderProps = {};

// DODO added start 44120742
const getPageLanguage = () => {
if (!document) {
return null;
}
const select = document.querySelector(
'#changeLanguage select',
) as HTMLSelectElement;
const selectedLanguage = select ? select.value : null;
return selectedLanguage;
};

const getLocaleForSuperset = () => {
const dodoisLanguage = getPageLanguage();
if (dodoisLanguage) {
if (dodoisLanguage === 'ru-RU') return 'ru';
return 'en';
}
return 'en';
};

let locale = 'en';

if (process.env.type === undefined) {
locale = bootstrapData?.common?.locale || 'en';
} else {
locale = getLocaleForSuperset();
}
// DODO added stop 44120742

// @z-index-above-dashboard-charts + 1 = 11
const FiltersPanel = styled.div<{ width: number; hidden: boolean }>`
grid-column: 1;
Expand Down Expand Up @@ -555,6 +586,7 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
renderTabContent={false}
renderHoverMenu={false}
onChangeTab={handleChangeTab}
locale={locale} // DODO added 44120742
/>
</WithPopoverMenu>
)}
Expand Down Expand Up @@ -623,6 +655,7 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
</ResizableSidebar>
</>
)}

<StyledHeader ref={headerRef}>
{/* @ts-ignore */}
<Droppable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const createProps = () => ({
},
reports: {},
dashboardTitle: 'Dashboard Title',
dashboardTitleRU: 'Dashboard Title',
charts: {},
layout: {},
expandedSlices: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const createProps = (): HeaderDropdownProps => ({
},
},
dashboardTitle: 'Title',
dashboardTitleRU: 'Title',
editMode: false,
expandedSlices: {},
forceRefreshAllCharts: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const propTypes = {
dashboardInfo: PropTypes.object.isRequired,
dashboardId: PropTypes.number,
dashboardTitle: PropTypes.string,
dashboardTitleRU: PropTypes.string,
dataMask: PropTypes.object.isRequired,
customCss: PropTypes.string,
colorNamespace: PropTypes.string,
Expand Down Expand Up @@ -156,6 +157,7 @@ export class HeaderActionsDropdown extends PureComponent {
render() {
const {
dashboardTitle,
dashboardTitleRU, // DODO added 44120742
dashboardId,
dashboardInfo,
refreshFrequency,
Expand Down Expand Up @@ -248,6 +250,7 @@ export class HeaderActionsDropdown extends PureComponent {
addDangerToast={this.props.addDangerToast}
dashboardId={dashboardId}
dashboardTitle={dashboardTitle}
dashboardTitleRU={dashboardTitleRU} // DODO added 44120742
dashboardInfo={dashboardInfo}
saveType={SAVE_TYPE_NEWDASHBOARD}
layout={layout}
Expand Down
Loading
Loading