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

[Feature] wraps UI strings with i18n #11

Closed
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
111 changes: 20 additions & 91 deletions src/plugins/vis_type_drilldown/public/drilldown_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useCallback, Fragment, useState, useEffect, useRef } from 'react';
import React, { useCallback, useState } from 'react';
import {
EuiPanel,
EuiTitle,
Expand All @@ -12,107 +12,46 @@ import {
EuiFlexItem,
EuiFieldText,
EuiAccordion,
EuiSuperSelect,
EuiText,
} from '@elastic/eui';

import { FormattedMessage } from '@osd/i18n/react';
import { i18n } from '@osd/i18n';
import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
import { useOpenSearchDashboards } from '../../opensearch_dashboards_react/public';
import { DrilldownServices, DrilldownVisParams } from './types';
import { DrilldownVisParams } from './types';

function DrilldownOptions({ stateParams, setValue }: VisOptionsProps<DrilldownVisParams>) {
const onMarkdownUpdate = useCallback(
(value: DrilldownVisParams['cardName']) => setValue('cardName', value),
[setValue]
);

const {
services: { http, savedObjects },
} = useOpenSearchDashboards<DrilldownServices>();

interface List {
value: string;
inputDisplay: string;
dropdownDisplay: JSX.Element; // Adjust the type based on the actual type of dropdownDisplay
}

const options = useRef<List[]>([
{
value: '1',
inputDisplay: 'Option 1',
dropdownDisplay: (
<Fragment>
<strong>Name</strong>
<EuiText size="s" color="subdued">
<p className="euiTextColor--subdued">
id
<br />
text
</p>
</EuiText>
</Fragment>
),
},
]);

const saved = useRef<any>();
const index = useRef<any>();

useEffect(() => {
const fetchData = async () => {
saved.current = savedObjects?.client.find({
type: 'dashboard',
});
const path = (await saved.current).savedObjects[0]['client']
.getPath(['dashboard', (await saved.current).savedObjects[0].id])
.substring(28);
const savedObjectURL = http.basePath.prepend('/app/dashboards#/view/' + path);
options.current = [
{
value: savedObjectURL,
inputDisplay: 'yes',
dropdownDisplay: (
<Fragment>
<strong>Name</strong>
<EuiText size="s" color="subdued">
<p className="euiTextColor--subdued">
id
<br />
text
</p>
</EuiText>
</Fragment>
),
},
];
};
fetchData();
}, []);

const onDescriptionUpdate = useCallback(
(value: DrilldownVisParams['cardDescription']) => setValue('cardDescription', value),
[setValue]
);

const activeVisName = '';
const handleVisTypeChange = () => {};

return (
<EuiAccordion buttonContent="Drilldown 1">
<EuiPanel paddingSize="s">
<EuiFlexGroup direction="column" gutterSize="m" className="eui-fullHeight">
<EuiFlexItem>
<EuiTitle size="xs">
<h2>
<label htmlFor="drilldownVisInput">Card Name</label>
<label
// test
htmlFor={i18n.translate('drilldownVisInput', {
defaultMessage: 'Drilldown visualisation input',
})}
>
Card Name
</label>
</h2>
</EuiTitle>
</EuiFlexItem>

<EuiFlexItem>
<EuiFieldText
id="drilldownVisInput"
placeholder="Placeholder text"
placeholder={i18n.translate('Placeholder text', { defaultMessage: 'Placeholder' })}
className="eui-fullHeight"
value={stateParams.cardName}
onChange={({ target: { value } }) => onMarkdownUpdate(value)}
Expand All @@ -123,7 +62,13 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps<DrilldownVi
<EuiFlexItem>
<EuiTitle size="xs">
<h2>
<label htmlFor="drilldownVisInput">Description</label>
<label
htmlFor={i18n.translate('drilldownVisInput', {
defaultMessage: 'Drilldown visualisation input',
})}
>
Description
</label>
</h2>
</EuiTitle>
</EuiFlexItem>
Expand All @@ -138,22 +83,6 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps<DrilldownVi
data-test-subj="markdownTextarea"
/>
</EuiFlexItem>

<EuiFlexItem>
<EuiTitle size="xs">
<h2>
<label htmlFor="drilldownVisInput">Select a Destination</label>
</h2>
</EuiTitle>
</EuiFlexItem>

<EuiSuperSelect
options={options.current}
valueOfSelected={activeVisName}
onChange={handleVisTypeChange}
fullWidth
data-test-subj="chartPicker"
/>
</EuiFlexGroup>
</EuiPanel>
</EuiAccordion>
Expand Down
Loading