Skip to content

Commit

Permalink
add i18n, finally block, move function
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Tackett <[email protected]>
  • Loading branch information
Adam Tackett committed Nov 12, 2024
1 parent 42b6c6b commit b06e832
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EuiText,
EuiButton,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { coreRefs } from '../../../framework/core_refs';
import { dataSourceManagementPluginId } from '../../../../common/constants/shared';

Expand All @@ -31,8 +32,10 @@ export function AddDataSourceCallout() {
<EuiFlexItem grow={false} style={{ maxWidth: '40%' }}>
<EuiText textAlign="center">
<p style={{ margin: 0 }}>
There are no data sources associated to the workspace. Associate data sources or
request your administrator to associate data sources for you to get started.
{i18n.translate('traceAnalytics.noDataSourcesMessage', {
defaultMessage:
'There are no data sources associated to the workspace. Associate data sources or request your administrator to associate data sources for you to get started.',
})}
</p>
</EuiText>
</EuiFlexItem>
Expand Down
35 changes: 18 additions & 17 deletions public/components/overview/components/dashboard_controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,27 @@ export function DashboardControls() {
const isDashboardSelected = useObservable(ObsDashboardStateManager.isDashboardSelected$);
const dashboardState = useObservable(ObsDashboardStateManager.dashboardState$);

useEffect(() => {
const checkDataSource = async () => {
const currentUrl = window.location.href;
const workspaceId = getWorkspaceIdFromUrl(currentUrl, coreRefs?.http?.basePath.getBasePath());
const checkDataSource = async () => {
const currentUrl = window.location.href;
const workspaceId = getWorkspaceIdFromUrl(currentUrl, coreRefs?.http?.basePath.getBasePath());

if (workspaceId) {
setIsInWorkspace(true);
const savedObjectsArray = await getDatasourceAttributes();
setIsDataSourceEmpty(savedObjectsArray.length === 0);
if (workspaceId) {
setIsInWorkspace(true);
const savedObjectsArray = await getDatasourceAttributes();
setIsDataSourceEmpty(savedObjectsArray.length === 0);

// Set to null if there are no data sources associated [Handle if dashboard was set, then datasource deleted]
if (savedObjectsArray.length === 0) {
await setObservabilityDashboardsId(null);
getOverviewPage().removeSection(SECTIONS.DASHBOARD); // Clear the present dashboard
}
} else {
setIsInWorkspace(false);
setIsDataSourceEmpty(false); // Not in workspace
// Set to null if there are no data sources associated [Handle if dashboard was set, then datasource deleted]
if (savedObjectsArray.length === 0) {
await setObservabilityDashboardsId(null);
getOverviewPage().removeSection(SECTIONS.DASHBOARD); // Clear the present dashboard
}
};
} else {
setIsInWorkspace(false);
setIsDataSourceEmpty(false); // Not in workspace
}
};

useEffect(() => {
checkDataSource();
}, []);

Expand Down
4 changes: 2 additions & 2 deletions public/components/overview/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export const Home = () => {
startDate: dashboardAttributes.timeFrom,
endDate: dashboardAttributes.timeTo,
};
setIsDashboardLoaded(true);
return acc;
}, {} as DashboardSavedObjectsType);

Expand Down Expand Up @@ -127,6 +126,8 @@ export const Home = () => {
})
.catch((error) => {
console.error('Error fetching dashboards:', error);
})
.finally(() => {
setIsDashboardLoaded(true);
});
};
Expand Down Expand Up @@ -182,7 +183,6 @@ export const Home = () => {
closePopover();

if (updatedShowCards) {
console.log('Called createSection');
getOverviewPage().createSection(GET_STARTED_SECTION);
} else {
getOverviewPage().removeSection(SECTIONS.GET_STARTED);
Expand Down

0 comments on commit b06e832

Please sign in to comment.