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

Move user info to compas foundation #278

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/Hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { Drawer } from '@material/mwc-drawer';
import { ActionDetail, List } from '@material/mwc-list';
import { ListItem } from '@material/mwc-list/mwc-list-item';

import { Mixin, newPendingStateEvent, UserInfoEvent } from './foundation.js';
import { Mixin, newPendingStateEvent } from './foundation.js';
import { UserInfoEvent } from './compas/foundation.js';
Copy link

Choose a reason for hiding this comment

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

Do we still want this in here? Or do we eventually move this out aswell (by extending Hosting in the compas package). Whatever we pick, this is still a step in the right direction!

import { LoggingElement } from './Logging.js';
import { PluggingElement, Plugin, pluginIcons } from './Plugging.js';
import { SettingElement } from './Setting.js';
Expand Down
2 changes: 1 addition & 1 deletion src/compas/CompasUserInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { newUserInfoEvent } from '../foundation.js';
import { newUserInfoEvent } from './foundation.js';

import { CompasUserInfoService } from '../compas-services/CompasUserInfoService.js';
import { createLogEvent } from '../compas-services/foundation.js';
Expand Down
22 changes: 22 additions & 0 deletions src/compas/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,25 @@ export function compareVersions(
}
return result;
}

/** Represents user information from a backend. */
export interface UserInfoDetail {
name: string;
}
export type UserInfoEvent = CustomEvent<UserInfoDetail>;
export function newUserInfoEvent(
name: string,
eventInitDict?: CustomEventInit<Partial<UserInfoDetail>>
): UserInfoEvent {
return new CustomEvent<UserInfoDetail>('userinfo', {
bubbles: true,
composed: true,
...eventInitDict,
detail: { name, ...eventInitDict?.detail },
});
}
declare global {
interface ElementEventMap {
['userinfo']: UserInfoEvent;
}
}
18 changes: 0 additions & 18 deletions src/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,23 +479,6 @@ export function newOpenDocEvent(
});
}

/** Represents user information from a backend. */
export interface UserInfoDetail {
name: string;
}
export type UserInfoEvent = CustomEvent<UserInfoDetail>;
export function newUserInfoEvent(
name: string,
eventInitDict?: CustomEventInit<Partial<UserInfoDetail>>
): UserInfoEvent {
return new CustomEvent<UserInfoDetail>('userinfo', {
bubbles: true,
composed: true,
...eventInitDict,
detail: { name, ...eventInitDict?.detail },
});
}

/** @returns a reference to `element` with segments delimited by '/'. */
// TODO(c-dinkel): replace with identity (FIXME)
export function referencePath(element: Element): string {
Expand Down Expand Up @@ -2880,7 +2863,6 @@ declare global {
['pending-state']: PendingStateEvent;
['editor-action']: EditorActionEvent<EditorAction>;
['open-doc']: OpenDocEvent;
['userinfo']: UserInfoEvent;
['wizard']: WizardEvent;
['validate']: ValidateEvent;
['log']: LogEvent;
Expand Down
6 changes: 4 additions & 2 deletions test/integration/compas/foundation.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { expect, fixture, html } from '@open-wc/testing';

import { updateDocumentInOpenSCD } from '../../../src/compas/foundation.js';
import {
updateDocumentInOpenSCD,
newUserInfoEvent,
} from '../../../src/compas/foundation.js';

import { OpenSCD } from '../../../src/open-scd.js';
import '../../../src/open-scd.js';
import { newUserInfoEvent } from '../../../src/foundation.js';

describe('compas-foundation', () => {
let element: OpenSCD;
Expand Down