Skip to content

Commit

Permalink
dashboard: refactor directory structure (#995)
Browse files Browse the repository at this point in the history
Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com>
  • Loading branch information
koonpeng committed Aug 14, 2024
1 parent b9189e8 commit 21b8364
Show file tree
Hide file tree
Showing 95 changed files with 654 additions and 693 deletions.
4 changes: 3 additions & 1 deletion packages/dashboard/src/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';
import { getDefaultTaskDefinition, TaskDefinition } from 'react-components';

import testConfig from '../app-config.json';
import { Authenticator, KeycloakAuthenticator, StubAuthenticator } from './auth';
import { Authenticator } from './services/authenticator';
import { KeycloakAuthenticator } from './services/keycloak';
import { StubAuthenticator } from './services/stub-authenticator';

export interface RobotResource {
/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ import './app.css';
import React from 'react';
import { Navigate, Route, Routes } from 'react-router-dom';

import { AppConfigContext, AuthenticatorContext, ResourcesContext } from '../app-config';
import { LoginPage, PrivateRoute } from '../auth';
import { AppConfigContext, AuthenticatorContext, ResourcesContext } from './app-config';
import {
AdminRouter,
AppBase,
AppEvents,
ManagedWorkspace,
PrivateRoute,
RmfApp,
SettingsContext,
Workspace,
WorkspaceState,
} from './components';
import { LoginPage } from './pages';
import {
AdminRoute,
CustomRoute1,
Expand All @@ -18,16 +29,40 @@ import {
LoginRoute,
RobotsRoute,
TasksRoute,
} from '../util/url';
import { AdminRouter } from './admin';
import { AppBase } from './app-base';
import { SettingsContext } from './app-contexts';
import { AppEvents } from './app-events';
import { dashboardWorkspace } from './dashboard';
import { RmfApp } from './rmf-app';
import { robotsWorkspace } from './robots/robots-workspace';
import { tasksWorkspace } from './tasks/tasks-workspace';
import { ManagedWorkspace, Workspace } from './workspace';
} from './utils/url';

const dashboardWorkspace: WorkspaceState = {
layout: [{ i: 'map', x: 0, y: 0, w: 12, h: 12 }],
windows: [{ key: 'map', appName: 'Map' }],
};

const robotsWorkspace: WorkspaceState = {
layout: [
{ i: 'robots', x: 0, y: 0, w: 7, h: 4 },
{ i: 'map', x: 8, y: 0, w: 5, h: 8 },
{ i: 'doors', x: 0, y: 0, w: 7, h: 4 },
{ i: 'lifts', x: 0, y: 0, w: 7, h: 4 },
{ i: 'mutexGroups', x: 8, y: 0, w: 5, h: 4 },
],
windows: [
{ key: 'robots', appName: 'Robots' },
{ key: 'map', appName: 'Map' },
{ key: 'doors', appName: 'Doors' },
{ key: 'lifts', appName: 'Lifts' },
{ key: 'mutexGroups', appName: 'Mutex Groups' },
],
};

const tasksWorkspace: WorkspaceState = {
layout: [
{ i: 'tasks', x: 0, y: 0, w: 7, h: 12 },
{ i: 'map', x: 8, y: 0, w: 5, h: 12 },
],
windows: [
{ key: 'tasks', appName: 'Tasks' },
{ key: 'map', appName: 'Map' },
],
};

export default function App(): JSX.Element | null {
const authenticator = React.useContext(AuthenticatorContext);
Expand Down
7 changes: 0 additions & 7 deletions packages/dashboard/src/auth/index.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/dashboard/src/auth/login.stories.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Meta, StoryFn } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';

import { AddPermissionDialog, AddPermissionDialogProps } from './add-permission-dialog';
import { AddPermissionDialog } from './add-permission-dialog';

export default {
title: 'Admin/Add Permission Dialog',
component: AddPermissionDialog,
} satisfies Meta;

export const Default: StoryFn<AddPermissionDialogProps> = (args) => {
return (
type Story = StoryObj<typeof AddPermissionDialog>;

export const Default: Story = {
storyName: 'Add Permission Dialog',
render: (args) => (
<AddPermissionDialog
{...args}
open={true}
setOpen={() => {}}
savePermission={() => new Promise((res) => setTimeout(res, 100))}
/>
);
),
};

Default.storyName = 'Add Permission Dialog';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';

import { RmfAction } from '../../permissions';
import { AddPermissionDialog } from '../add-permission-dialog';
import { RmfAction } from '../../services/permissions';
import { AddPermissionDialog } from './add-permission-dialog';

describe('AddPermissionDialog', () => {
it('calls savePermission when form is submitted', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Permission } from 'api-client';
import React from 'react';
import { ConfirmationDialog, useAsync } from 'react-components';

import { getActionText, RmfAction } from '../../services/permissions';
import { AppControllerContext } from '../app-contexts';
import { getActionText, RmfAction } from '../permissions';

export interface AddPermissionDialogProps {
open: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Meta, StoryFn } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';

import { CreateRoleDialog, CreateRoleDialogProps } from './create-role-dialog';
import { CreateRoleDialog } from './create-role-dialog';

export default {
title: 'Admin/Create Role Dialog',
component: CreateRoleDialog,
} satisfies Meta;

export const Default: StoryFn<CreateRoleDialogProps> = (args) => {
return (
type Story = StoryObj<typeof CreateRoleDialog>;

export const Default: Story = {
storyName: 'Create Role Dialog',
render: (args) => (
<CreateRoleDialog
{...args}
open={true}
createRole={() => new Promise((res) => setTimeout(res, 100))}
/>
);
),
};

Default.storyName = 'Create Role Dialog';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';

import { CreateRoleDialog } from '../create-role-dialog';
import { CreateRoleDialog } from './create-role-dialog';

describe('CreateRoleDialog', () => {
it('calls createRole when form is submitted', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { Meta, StoryFn } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';

import { CreateUserDialog, CreateUserDialogProps } from './create-user-dialog';
import { CreateUserDialog } from './create-user-dialog';

export default {
title: 'Admin/Create User Dialog',
component: CreateUserDialog,
} satisfies Meta;

export const Default: StoryFn<CreateUserDialogProps> = (args) => {
return (
type Story = StoryObj<typeof CreateUserDialog>;

export const Default: Story = {
storyName: 'Create User Dialog',
render: (args) => (
<CreateUserDialog
{...args}
open={true}
createUser={() => new Promise((res) => setTimeout(res, 100))}
/>
);
),
};

Default.storyName = 'Create User Dialog';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';

import { CreateUserDialog } from '../create-user-dialog';
import { CreateUserDialog } from './create-user-dialog';

describe('CreateUserDialog', () => {
it('calls createUser when form is submitted', async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/dashboard/src/components/admin/drawer.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Meta, StoryFn } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';

import { AdminDrawer } from './drawer';

Expand All @@ -12,8 +12,8 @@ export default {
},
} satisfies Meta;

export const Default: StoryFn<{}> = (args) => {
return <AdminDrawer {...args} />;
};
type Story = StoryObj<typeof AdminDrawer>;

Default.storyName = 'Drawer';
export const Default: Story = {
storyName: 'Drawer',
};
15 changes: 15 additions & 0 deletions packages/dashboard/src/components/admin/drawer.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { render } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
import { describe, it } from 'vitest';

import { AdminDrawer } from './drawer';

describe('AdminDrawer', () => {
it('smoke test', () => {
render(
<MemoryRouter>
<AdminDrawer />
</MemoryRouter>,
);
});
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { Meta, StoryFn } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';

import { ManageRolesCard } from './manage-roles-dialog';
import { RoleListCardProps } from './role-list-card';

export default {
title: 'Admin/Manage Roles Card',
component: ManageRolesCard,
} satisfies Meta;

const allRoles: string[] = [];
for (let i = 0; i < 5; i++) {
allRoles.push(`role${i}`);
}

export const Default: StoryFn<RoleListCardProps> = (args) => {
return (
type Story = StoryObj<typeof ManageRolesCard>;

export const Default: Story = {
storyName: 'Manage Roles Card',
args: {
assignedRoles: ['role1'],
},
render: (args) => (
<ManageRolesCard
assignedRoles={['role1']}
getAllRoles={async () => {
await new Promise((res) => setTimeout(res, 100));
return allRoles;
Expand All @@ -25,7 +30,5 @@ export const Default: StoryFn<RoleListCardProps> = (args) => {
}}
{...args}
/>
);
),
};

Default.storyName = 'Manage Roles Card';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, waitFor, waitForElementToBeRemoved } from '@testing-library/rea
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';

import { ManageRolesCard, ManageRolesDialog } from '../manage-roles-dialog';
import { ManageRolesCard, ManageRolesDialog } from './manage-roles-dialog';

describe('ManageRolesCard', () => {
it('shows dialog when add/remove is clicked', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, StoryFn } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';
import { Permission } from 'api-client';

import { PermissionsCard, PermissionsCardProps } from './permissions-card';
import { PermissionsCard } from './permissions-card';

export default {
title: 'Admin/Permissions Card',
Expand All @@ -16,10 +16,11 @@ export default {
},
} satisfies Meta;

export const Default: StoryFn<PermissionsCardProps> = (args) => {
return (
type Story = StoryObj<typeof PermissionsCard>;

export const Default: Story = {
storyName: 'Permissions Card',
render: (args) => (
<PermissionsCard {...args} savePermission={() => new Promise((res) => setTimeout(res, 100))} />
);
),
};

Default.storyName = 'Permissions Card';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { fireEvent, render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';

import { getActionText, RmfAction } from '../../permissions';
import { PermissionsCard } from '../permissions-card';
import { getActionText, RmfAction } from '../../services/permissions';
import { PermissionsCard } from './permissions-card';

// TODO(AA): To remove after
// https://github.com/testing-library/react-testing-library/issues/1216
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { Permission } from 'api-client';
import React from 'react';
import { Loading, useAsync } from 'react-components';

import { getActionText } from '../../services/permissions';
import { AppControllerContext } from '../app-contexts';
import { getActionText } from '../permissions';
import { AddPermissionDialog, AddPermissionDialogProps } from './add-permission-dialog';

const prefix = 'permissions-card';
Expand Down
Loading

0 comments on commit 21b8364

Please sign in to comment.