Skip to content

Commit

Permalink
update and only keep workspace create case
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Aug 2, 2024
1 parent 795d0d0 commit bfc32df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,4 @@ describe('WorkspaceUseCase', () => {
expect(renderResult.queryByText('Observability')).not.toBeInTheDocument();
});
});

it('should only disable all use cases except essential use case when updating workspace if getIsOnlyAllowEssentialUseCase returns true', async () => {
(getIsOnlyAllowEssentialUseCase as jest.Mock).mockResolvedValue(true);

const { renderResult } = setup({
operationType: WorkspaceOperationType.Update,
});
await waitFor(() => {
expect(renderResult.queryByText('Analytics')).not.toBeDisabled();
// Use case card doesn't have disable property, only has class name to compare.
expect(renderResult.getByText('Observability')).toHaveClass(
'euiCheckableCard__label-isDisabled'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,22 @@ export const WorkspaceUseCase = ({
const [isOnlyAllowEssential, setIsOnlyAllowEssential] = useState(false);

useEffect(() => {
getIsOnlyAllowEssentialUseCase(savedObjects.client).then((result: boolean) => {
setIsOnlyAllowEssential(result);
});
}, [savedObjects]);
if (operationType === WorkspaceOperationType.Create) {
getIsOnlyAllowEssentialUseCase(savedObjects.client).then((result: boolean) => {
setIsOnlyAllowEssential(result);
});
}
}, [savedObjects, operationType]);

useEffect(() => {
let allAvailableUseCases = availableUseCases
.filter((item) => !item.systematic)
.concat(DEFAULT_NAV_GROUPS.all);
if (isOnlyAllowEssential) {
// When creating, only display essential use case
if (operationType === WorkspaceOperationType.Create) {
allAvailableUseCases = allAvailableUseCases.filter(
(item) => item.id === DEFAULT_NAV_GROUPS.analytics.id
);
} else {
// When updating, all use cases except essential use case are disabled.
allAvailableUseCases = allAvailableUseCases.map((item) => ({
...item,
disabled: item.id === DEFAULT_NAV_GROUPS.analytics.id ? false : true,
}));
}
// When creating and isOnlyAllowEssential is true, only display essential use case
if (isOnlyAllowEssential && operationType === WorkspaceOperationType.Create) {
allAvailableUseCases = allAvailableUseCases.filter(
(item) => item.id === DEFAULT_NAV_GROUPS.analytics.id
);
}
setDisplayedUseCases(allAvailableUseCases);
}, [availableUseCases, isOnlyAllowEssential, operationType]);
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,9 @@ export const getDataSourcesList = (client: SavedObjectsStart['client'], workspac
export const getIsOnlyAllowEssentialUseCase = async (client: SavedObjectsStart['client']) => {
const allDataSources = await getDataSourcesList(client, ['*']);
if (allDataSources.length > 0) {
const serverlessDataSource = allDataSources.filter(
return allDataSources.every(
(ds) => ds?.auth?.credentials?.service === SigV4ServiceName.OpenSearchServerless
);
if (serverlessDataSource.length === allDataSources.length) {
return true;
}
}
return false;
};
Expand Down

0 comments on commit bfc32df

Please sign in to comment.