Skip to content

Commit

Permalink
filter non-configurable workspace features in workspace configuration…
Browse files Browse the repository at this point in the history
… page (opensearch-project#106)

* feat: filter non-configurable workspace features in workspace configuration page

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

* feat: filter non-configurable workspace features in workspace configuration page

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

* fix: add append feature ids and add disabled to feature in group

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

* fix: add set to unique

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

---------

Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao authored and ruanyl committed Sep 15, 2023
1 parent 08d55e1 commit c885d08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/plugins/workspace/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const WORKSPACE_CREATE_APP_ID = 'workspace_create';
export const WORKSPACE_LIST_APP_ID = 'workspace_list';
export const WORKSPACE_UPDATE_APP_ID = 'workspace_update';
export const WORKSPACE_OVERVIEW_APP_ID = 'workspace_overview';
// These features will be checked and disabled in checkbox on default.
export const DEFAULT_CHECKED_FEATURES_IDS = [WORKSPACE_UPDATE_APP_ID, WORKSPACE_OVERVIEW_APP_ID];
export const WORKSPACE_FATAL_ERROR_APP_ID = 'workspace_fatal_error';
export const PATHS = {
create: '/create',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import {
DEFAULT_APP_CATEGORIES,
} from '../../../../../core/public';
import { useApplications } from '../../hooks';
import { WORKSPACE_OP_TYPE_CREATE, WORKSPACE_OP_TYPE_UPDATE } from '../../../common/constants';
import {
WORKSPACE_OP_TYPE_CREATE,
WORKSPACE_OP_TYPE_UPDATE,
DEFAULT_CHECKED_FEATURES_IDS,
} from '../../../common/constants';
import {
isFeatureDependBySelectedFeatures,
getFinalFeatureIdsByDependency,
Expand Down Expand Up @@ -84,6 +88,15 @@ const isValidWorkspacePermissionSetting = (
setting.modes.length > 0 &&
((setting.type === 'user' && !!setting.userId) || (setting.type === 'group' && !!setting.group));

const isDefaultCheckedFeatureId = (id: string) => {
return DEFAULT_CHECKED_FEATURES_IDS.indexOf(id) > -1;
};

const appendDefaultFeatureIds = (ids: string[]) => {
// concat default checked ids and unique the result
return Array.from(new Set(ids.concat(DEFAULT_CHECKED_FEATURES_IDS)));
};

const workspaceHtmlIdGenerator = htmlIdGenerator();

const defaultVISThemeOptions = [{ label: 'Categorical', value: 'categorical' }];
Expand All @@ -109,7 +122,9 @@ export const WorkspaceForm = ({
const [icon, setIcon] = useState(defaultValues?.icon);
const [defaultVISTheme, setDefaultVISTheme] = useState(defaultValues?.defaultVISTheme);

const [selectedFeatureIds, setSelectedFeatureIds] = useState(defaultValues?.features || []);
const [selectedFeatureIds, setSelectedFeatureIds] = useState(
appendDefaultFeatureIds(defaultValues?.features || [])
);
const [permissionSettings, setPermissionSettings] = useState<
Array<Partial<WorkspacePermissionSetting>>
>(
Expand Down Expand Up @@ -402,6 +417,10 @@ export const WorkspaceForm = ({
features.length > 0 ? `(${selectedIds.length}/${features.length})` : ''
}`}
checked={selectedIds.length > 0}
disabled={
!isWorkspaceFeatureGroup(featureOrGroup) &&
isDefaultCheckedFeatureId(featureOrGroup.id)
}
indeterminate={
isWorkspaceFeatureGroup(featureOrGroup) &&
selectedIds.length > 0 &&
Expand All @@ -413,6 +432,7 @@ export const WorkspaceForm = ({
options={featureOrGroup.features.map((item) => ({
id: item.id,
label: item.name,
disabled: isDefaultCheckedFeatureId(item.id),
}))}
idToSelectedMap={selectedIds.reduce(
(previousValue, currentValue) => ({
Expand Down

0 comments on commit c885d08

Please sign in to comment.