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

feat: management workspace customization #153

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
10,782 changes: 3,014 additions & 7,768 deletions src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap

Large diffs are not rendered by default.

569 changes: 23 additions & 546 deletions src/core/public/chrome/ui/header/__snapshots__/header.test.tsx.snap

Large diffs are not rendered by default.

19 changes: 6 additions & 13 deletions src/core/public/chrome/ui/header/collapsible_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {
} from './nav_link';
import { ChromeBranding } from '../../chrome_service';
import { CollapsibleNavHeader } from './collapsible_nav_header';
import { MANAGEMENT_WORKSPACE_ID } from '../../../utils';

function getAllCategories(allCategorizedLinks: Record<string, CollapsibleNavLink[]>) {
const allCategories = {} as Record<string, AppCategory | undefined>;
Expand Down Expand Up @@ -154,20 +153,14 @@ export function CollapsibleNav({
}: Props) {
const navLinks = useObservable(observables.navLinks$, []).filter((link) => !link.hidden);
const recentlyAccessed = useObservable(observables.recentlyAccessed$, []);
const workspaceEnabled = useObservable(workspaces.workspaceEnabled$, false);
const currentWorkspaceId = useObservable(workspaces.currentWorkspaceId$, '');
const allNavLinks: CollapsibleNavLink[] = [...navLinks];
if (!workspaceEnabled || currentWorkspaceId !== MANAGEMENT_WORKSPACE_ID) {
// no recently visited in management workspace
if (recentlyAccessed.length) {
allNavLinks.push(
...recentlyAccessed.map((link) => createRecentChromeNavLink(link, navLinks, basePath))
);
} else {
allNavLinks.push(emptyRecentlyVisited);
}
if (recentlyAccessed.length) {
allNavLinks.push(
...recentlyAccessed.map((link) => createRecentChromeNavLink(link, navLinks, basePath))
);
} else {
allNavLinks.push(emptyRecentlyVisited);
}

const appId = useObservable(observables.appId$, '');
const lockRef = useRef<HTMLButtonElement>(null);
const groupedNavLinks = groupBy(allNavLinks, (link) => link?.category?.id);
Expand Down
10 changes: 9 additions & 1 deletion src/core/utils/default_app_categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,20 @@ export const DEFAULT_APP_CATEGORIES: Record<string, AppCategory> = Object.freeze
order: 4000,
euiIconType: 'logoSecurity',
},
openSearchFeatures: {
id: 'openSearchFeatures',
label: i18n.translate('core.ui.openSearchFeaturesNavList.label', {
defaultMessage: 'OpenSearch Features',
}),
order: 5000,
euiIconType: 'folderClosed',
},
management: {
id: 'management',
label: i18n.translate('core.ui.managementNavList.label', {
defaultMessage: 'Management',
}),
order: 5000,
order: 6000,
euiIconType: 'managementApp',
},
});
2 changes: 1 addition & 1 deletion src/plugins/dev_tools/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class DevToolsPlugin implements Plugin<DevToolsSetup> {
icon: '/plugins/home/public/assets/logos/opensearch_mark_default.svg',
/* the order of dev tools, it shows as last item of management section */
order: 9070,
category: DEFAULT_APP_CATEGORIES.management,
category: DEFAULT_APP_CATEGORIES.openSearchFeatures,
mount: async (params: AppMountParameters) => {
const { element, history } = params;
element.classList.add('devAppWrapper');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ import {
EuiComboBoxProps,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';

import {
App,
AppNavLinkStatus,
ApplicationStart,
DEFAULT_APP_CATEGORIES,
MANAGEMENT_WORKSPACE_ID,
PUBLIC_WORKSPACE_ID,
} from '../../../../../core/public';
import { useApplications } from '../../hooks';
import {
Expand Down Expand Up @@ -77,6 +74,7 @@ export interface WorkspaceFormSubmitData {

export interface WorkspaceFormData extends WorkspaceFormSubmitData {
id: string;
reserved?: boolean;
}

type WorkspaceFormErrors = Omit<{ [key in keyof WorkspaceFormData]?: string }, 'permissions'> & {
Expand Down Expand Up @@ -120,12 +118,8 @@ export const WorkspaceForm = ({
defaultValues,
opType,
}: WorkspaceFormProps) => {
const workspaceId = defaultValues?.id;
const workspaceNameReadOnly =
workspaceId === PUBLIC_WORKSPACE_ID || workspaceId === MANAGEMENT_WORKSPACE_ID;
const isShowingWorkspaceFeatures = workspaceId !== MANAGEMENT_WORKSPACE_ID;
const applications = useApplications(application);

const workspaceNameReadOnly = defaultValues?.reserved;
const [name, setName] = useState(defaultValues?.name);
const [description, setDescription] = useState(defaultValues?.description);
const [color, setColor] = useState(defaultValues?.color);
Expand Down Expand Up @@ -401,73 +395,69 @@ export const WorkspaceForm = ({
</EuiFormRow>
</EuiPanel>
<EuiSpacer />
{isShowingWorkspaceFeatures && (
<EuiPanel>
<EuiTitle size="s">
<h2>Workspace features</h2>
</EuiTitle>
<EuiFlexGrid style={{ paddingLeft: 20, paddingTop: 20 }} columns={2}>
{featureOrGroups.map((featureOrGroup) => {
const features = isWorkspaceFeatureGroup(featureOrGroup)
<EuiPanel>
<EuiTitle size="s">
<h2>Workspace features</h2>
</EuiTitle>
<EuiFlexGrid style={{ paddingLeft: 20, paddingTop: 20 }} columns={2}>
{featureOrGroups.map((featureOrGroup) => {
const features = isWorkspaceFeatureGroup(featureOrGroup) ? featureOrGroup.features : [];
const selectedIds = selectedFeatureIds.filter((id) =>
(isWorkspaceFeatureGroup(featureOrGroup)
? featureOrGroup.features
: [];
const selectedIds = selectedFeatureIds.filter((id) =>
(isWorkspaceFeatureGroup(featureOrGroup)
? featureOrGroup.features
: [featureOrGroup]
).find((item) => item.id === id)
);
return (
<EuiFlexItem key={featureOrGroup.name}>
<EuiCheckbox
id={
isWorkspaceFeatureGroup(featureOrGroup)
? featureOrGroup.name
: featureOrGroup.id
}
onChange={
isWorkspaceFeatureGroup(featureOrGroup)
? handleFeatureGroupChange
: handleFeatureCheckboxChange
}
label={`${featureOrGroup.name}${
features.length > 0 ? `(${selectedIds.length}/${features.length})` : ''
}`}
checked={selectedIds.length > 0}
disabled={
!isWorkspaceFeatureGroup(featureOrGroup) &&
isDefaultCheckedFeatureId(featureOrGroup.id)
}
indeterminate={
isWorkspaceFeatureGroup(featureOrGroup) &&
selectedIds.length > 0 &&
selectedIds.length < features.length
}
: [featureOrGroup]
).find((item) => item.id === id)
);
return (
<EuiFlexItem key={featureOrGroup.name}>
<EuiCheckbox
id={
isWorkspaceFeatureGroup(featureOrGroup)
? featureOrGroup.name
: featureOrGroup.id
}
onChange={
isWorkspaceFeatureGroup(featureOrGroup)
? handleFeatureGroupChange
: handleFeatureCheckboxChange
}
label={`${featureOrGroup.name}${
features.length > 0 ? `(${selectedIds.length}/${features.length})` : ''
}`}
checked={selectedIds.length > 0}
disabled={
!isWorkspaceFeatureGroup(featureOrGroup) &&
isDefaultCheckedFeatureId(featureOrGroup.id)
}
indeterminate={
isWorkspaceFeatureGroup(featureOrGroup) &&
selectedIds.length > 0 &&
selectedIds.length < features.length
}
/>
{isWorkspaceFeatureGroup(featureOrGroup) && (
<EuiCheckboxGroup
options={featureOrGroup.features.map((item) => ({
id: item.id,
label: item.name,
disabled: isDefaultCheckedFeatureId(item.id),
}))}
idToSelectedMap={selectedIds.reduce(
(previousValue, currentValue) => ({
...previousValue,
[currentValue]: true,
}),
{}
)}
onChange={handleFeatureChange}
style={{ marginLeft: 40 }}
/>
{isWorkspaceFeatureGroup(featureOrGroup) && (
<EuiCheckboxGroup
options={featureOrGroup.features.map((item) => ({
id: item.id,
label: item.name,
disabled: isDefaultCheckedFeatureId(item.id),
}))}
idToSelectedMap={selectedIds.reduce(
(previousValue, currentValue) => ({
...previousValue,
[currentValue]: true,
}),
{}
)}
onChange={handleFeatureChange}
style={{ marginLeft: 40 }}
/>
)}
</EuiFlexItem>
);
})}
</EuiFlexGrid>
</EuiPanel>
)}
)}
</EuiFlexItem>
);
})}
</EuiFlexGrid>
</EuiPanel>
<EuiSpacer />
<EuiPanel>
<EuiTitle size="s">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ export const WorkspaceMenu = ({ basePath, getUrlForApp, observables }: Props) =>
defaultMessage: 'OpenSearch Dashboards',
}
);
const managementWorkspaceName =
workspaceList.find((workspace) => workspace.id === MANAGEMENT_WORKSPACE_ID)?.name ??
i18n.translate('core.ui.primaryNav.workspacePickerMenu.managementWorkspaceName', {
const managementWorkspaceName = i18n.translate(
'core.ui.primaryNav.workspacePickerMenu.managementWorkspaceName',
{
defaultMessage: 'Management',
});
}
);
const filteredWorkspaceList = getFilteredWorkspaceList(workspaceList, currentWorkspace);
const currentWorkspaceName = currentWorkspace?.name ?? defaultHeaderName;

Expand Down
8 changes: 5 additions & 3 deletions src/plugins/workspace/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
import { i18n } from '@osd/i18n';
import { Observable } from 'rxjs';

import {
PluginInitializerContext,
CoreSetup,
Expand All @@ -26,7 +25,7 @@ import { IWorkspaceDBImpl } from './types';
import { WorkspaceClientWithSavedObject } from './workspace_client';
import { WorkspaceSavedObjectsClientWrapper } from './saved_objects';
import { registerRoutes } from './routes';
import { WORKSPACE_OVERVIEW_APP_ID, WORKSPACE_UPDATE_APP_ID } from '../common/constants';
import { WORKSPACE_OVERVIEW_APP_ID } from '../common/constants';
import { ConfigSchema } from '../config';

export class WorkspacePlugin implements Plugin<{}, {}> {
Expand Down Expand Up @@ -132,6 +131,8 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
const managementWorkspaceACL = new ACL().addPermission([WorkspacePermissionMode.LibraryRead], {
users: ['*'],
});
const DSM_APP_ID = 'dataSources';
const DEV_TOOLS_APP_ID = 'dev_tools';

await Promise.all([
this.checkAndCreateWorkspace(
Expand All @@ -155,7 +156,8 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
features: [
`@${DEFAULT_APP_CATEGORIES.management.id}`,
WORKSPACE_OVERVIEW_APP_ID,
WORKSPACE_UPDATE_APP_ID,
Copy link
Owner

Choose a reason for hiding this comment

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

I think WORKSPACE_UPDATE_APP_ID should not be removed, we should allow people to update management workspace settings

DSM_APP_ID,
DEV_TOOLS_APP_ID,
],
},
managementWorkspaceACL.getPermissions()
Expand Down