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

[Workspace] feat: only allow essential use case when creating workspace if all data sources are serverless #7612

Merged
merged 8 commits into from
Aug 12, 2024

Conversation

raintygao
Copy link
Contributor

@raintygao raintygao commented Aug 2, 2024

Description

Only allow essential use case when creating workspace if all data sources are serverless

Screenshot

img_v3_02dc_5375e41d-b44f-432a-8d15-bfab1a20b46g
Create workspace

Testing the changes

Set all data sources as serverless, then go to workspace create page or detail page.

Changelog

  • feat: Only allow essential use case when creating workspace if all data sources are serverless

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link

codecov bot commented Aug 2, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 63.70%. Comparing base (1bf63e3) to head (f069430).
Report is 2 commits behind head on main.

Files Patch % Lines
src/plugins/workspace/public/utils.ts 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7612   +/-   ##
=======================================
  Coverage   63.69%   63.70%           
=======================================
  Files        3633     3633           
  Lines       80135    80153   +18     
  Branches    12699    12702    +3     
=======================================
+ Hits        51043    51061   +18     
  Misses      25984    25984           
  Partials     3108     3108           
Flag Coverage Δ
Linux_1 30.60% <90.00%> (+0.01%) ⬆️
Linux_2 55.63% <ø> (ø)
Linux_3 40.56% <ø> (?)
Linux_4 31.31% <ø> (ø)
Windows_1 30.62% <90.00%> (+0.01%) ⬆️
Windows_2 55.58% <ø> (ø)
Windows_3 40.56% <ø> (ø)
Windows_4 31.31% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

export const getIsOnlyAllowEssentialUseCase = async (client: SavedObjectsStart['client']) => {
const allDataSources = await getDataSourcesList(client, ['*']);
if (allDataSources.length > 0) {
const serverlessDataSource = allDataSources.filter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use allDataSources.every()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.

@@ -54,21 +60,60 @@ const WorkspaceUseCaseCard = ({
);
};

type AvailableUseCase = Pick<
WorkspaceUseCaseObject,
'id' | 'title' | 'description' | 'systematic'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is irrelevant, but what does systematic stand for? cc @wanglam

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For filtering out system nav group, we won't show system nav groups in the use case selector.

raintygao pushed a commit to raintygao/OpenSearch-Dashboards that referenced this pull request Aug 2, 2024
@raintygao raintygao changed the title [Workspace] feat: only allow essential use case when creating or updating workspace if all data sources are serverless [Workspace] feat: only allow essential use case when creating workspace if all data sources are serverless Aug 2, 2024
opensearch-changeset-bot bot added a commit to raintygao/OpenSearch-Dashboards that referenced this pull request Aug 2, 2024
Comment on lines 121 to 123
{displayedUseCases.map(({ id, title, description, disabled }) => (
<EuiFlexItem key={id}>
<WorkspaceUseCaseCard
id={id}
title={title}
description={description}
checked={value === id}
onChange={onChange}
disabled={disabled}
/>
</EuiFlexItem>
))}
Copy link
Contributor

@Hailong-am Hailong-am Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't find the place set disabled, do we still need it? I see we are doing filter instead of setting other use cases disabled.

// 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);

Copy link
Contributor Author

@raintygao raintygao Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed to delete it.Thanks for catching it. Will update it soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines +82 to +88
useEffect(() => {
if (operationType === WorkspaceOperationType.Create) {
getIsOnlyAllowEssentialUseCase(savedObjects.client).then((result: boolean) => {
setIsOnlyAllowEssential(result);
});
}
}, [savedObjects, operationType]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks we can simply use useMemo instead of useEffect + useState

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here useMemo would be hard to combine with promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I used useEffect + useState to make it clear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, that's a promise

Comment on lines 90 to 101
useEffect(() => {
let allAvailableUseCases = availableUseCases
.filter((item) => !item.systematic)
.concat(DEFAULT_NAV_GROUPS.all);
// 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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here, we can simply use useMemo, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Signed-off-by: tygao <tygao@amazon.com>
ruanyl
ruanyl previously approved these changes Aug 12, 2024
SuZhou-Joe
SuZhou-Joe previously approved these changes Aug 12, 2024
@raintygao raintygao dismissed stale reviews from SuZhou-Joe and ruanyl via f069430 August 12, 2024 03:06
@raintygao
Copy link
Contributor Author

@SuZhou-Joe @ruanyl Could you help me approve it again? Just fix a error that use case changes from analytics to essential after pulling main.

@ruanyl ruanyl merged commit f59c2b9 into opensearch-project:main Aug 12, 2024
69 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 12, 2024
…ce if all data sources are serverless (#7612)

* feat: only allow essential use case when all data sources are serverless

Signed-off-by: tygao <tygao@amazon.com>

* Changeset file for PR #7612 created/updated

* update and only keep workspace create case

Signed-off-by: tygao <tygao@amazon.com>

* Changeset file for PR #7612 created/updated

* remove useless disabled logic

Signed-off-by: tygao <tygao@amazon.com>

* use useMemo

Signed-off-by: tygao <tygao@amazon.com>

* update filter and tests to update with essiential use case change

Signed-off-by: tygao <tygao@amazon.com>

---------

Signed-off-by: tygao <tygao@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit f59c2b9)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ruanyl pushed a commit that referenced this pull request Aug 12, 2024
…ce if all data sources are serverless (#7612) (#7684)

* feat: only allow essential use case when all data sources are serverless



* Changeset file for PR #7612 created/updated

* update and only keep workspace create case



* Changeset file for PR #7612 created/updated

* remove useless disabled logic



* use useMemo



* update filter and tests to update with essiential use case change



---------



(cherry picked from commit f59c2b9)

Signed-off-by: tygao <tygao@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants