Skip to content

Commit

Permalink
feat(arch): move && simplify component link
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Aug 2, 2023
1 parent ac49716 commit 034064d
Show file tree
Hide file tree
Showing 87 changed files with 481 additions and 513 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
80 changes: 80 additions & 0 deletions packages-new/components/link/documentation/specifications/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
* [**Interfaces**](#interfaces)
* [**Types**](#types)
* [**Classes**](#classes)
* [**Type alias**](#type-alias)
* [**Variables**](#variables)

## Interfaces

### OdsLinkAttributes
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`color`** | `OdsThemeColorIntent` | | | Link color theme|
|**`contrasted`** | _boolean_ | | | Link design as contrasted version|
|**`disabled`** | _boolean_ | | | Link should be disabled or not|
|**`download`** | _string_ | | | Link as download source|
|**`href`** | _string_ | | | Link URL|
|**`referrerpolicy`** | `OdsLinkReferrerpolicy` | | | Link referrer policy|
|**`rel`** | `OdsHTMLAnchorElementRel` | | | Link relationship|
|**`target`** | `OdsHTMLAnchorElementTarget` | | | Link target typeIf href is set the default value `_self` is set|
|**`type`** | _string_ | | | Link type (for download source)|

### OdsLinkBehavior
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`beforeRender`** | _void_ | ✴️ | | before render component functionshould be called before component renderit have to check the validity of attributes.|

## Types

### OdsLinkReferrerpolicy
| |
|:---:|
| `no-referrer` |
| `no-referrer-when-downgrade` |
| `origin` |
| `origin-when-cross-origin` |
| `same-origin` |
| `strict-origin-when-cross-origin` |
| `unsafe-url` |

## Classes

### OdsLinkController
_common controller logic for link component used by the different implementations._
_it contains all the glue between framework implementation and the third party service._

#### Methods
> **validateAttributes**() => _unknown_


### OdsLinkMock

## Type alias

### OdsLink

interface description of all implementation of `ods-link`.
each implementation must have defined events, methods, attributes
and one controller for the common behavior logic

> - `OdsComponentGenericMethods`
> - `OdsComponentGenericEvents`
### OdsLinkAttributes

> _Based on `OdsComponentAttributes`_
### OdsLinkEvents

> _Based on `OdsComponentEvents`_
### OdsLinkMethods

> _Based on `OdsComponentMethods`_
## Variables

### odsLinkDefaultAttributes
`OdsLinkAttributes`
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Description} from '@storybook/addon-docs';
import Specs from './spec.md';
import SpecsLinkContents from './specifications-link-contents.mdx';
import SpecsLinkTests from './specifications-link-tests.mdx';

## Description
The link component has many combinations of features.

<Description>{Specs}</Description>

## Contents
<SpecsLinkContents />

## Tests
<SpecsLinkTests />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Config } from '@jest/types';
import { OdsGetJestConfig } from '@ovhcloud/ods-testing';
import { OdsGetJestConfig } from '@ovhcloud/ods-common-testing';

const args = process.argv.slice(2);

Expand All @@ -15,8 +15,9 @@ const args = process.argv.slice(2);
* };
* ```
*/
// @ts-ignore until dependencies are fixed to one unique version of @jest/types
const config: Config.InitialOptions = OdsGetJestConfig({
basePath: '<rootDir>/../../../..',
basePath: '<rootDir>/../../..',
args
});
export default config;
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "@ovhcloud/ods-stencil-link",
"name": "@ovhcloud/ods-component-link",
"version": "15.0.1",
"private": true,
"description": "Link component",
"description": "ODS Link component",
"author": "OVH SAS",
"license": "Apache-2.0",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"es2015": "dist/esm/index.js",
"es2017": "dist/esm/index.js",
"types": "dist/types/components.d.ts",
"types": "dist/types/index.d.ts",
"collection": "dist/collection/collection-manifest.json",
"collection:main": "dist/collection/index.js",
"scripts": {
Expand All @@ -35,9 +34,13 @@
"test:e2e:ci:screenshot:update": "stencil test --config stencil.config.ts --e2e --ci --screenshot --update-screenshot --passWithNoTests"
},
"dependencies": {
"@ovhcloud/ods-stencil-component": "^15.0.1"
"@ovhcloud/ods-common-core": "^15.0.1",
"@ovhcloud/ods-common-stencil": "^15.0.1",
"@ovhcloud/ods-component-icon": "^15.0.1",
"@ovhcloud/ods-theming": "^15.0.1"
},
"devDependencies": {
"@ovhcloud/ods-stencil-component-dev": "^15.0.1"
"@ovhcloud/ods-common-testing": "^15.0.1",
"@ovhcloud/ods-stencil-dev": "^15.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@ovhcloud/ods-stencil-link-react",
"name": "@ovhcloud/ods-component-link-react",
"version": "15.0.1",
"private": true,
"description": "React specific wrapper for ods",
Expand All @@ -20,19 +20,13 @@
"dist/"
],
"dependencies": {
"@ovhcloud/ods-stencil-cart": "^15.0.1",
"tslib": "*"
"@ovhcloud/ods-component-link": "^15.0.1"
},
"peerDependencies": {
"react": ">=16.8.6",
"react-dom": ">=16.8.6"
},
"devDependencies": {
"@types/react": "17.0.37",
"@types/react-dom": "17.0.11",
"react": "16.14.0",
"react-dom": "16.14.0",
"rimraf": "^3.0.2",
"typescript": "4.7.4"
"@ovhcloud/ods-react-dev": "^15.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { OdsLinkAttributes } from './ods-link-attributes';
import type { OdsLinkAttribute } from '../interfaces/attributes';
import { OdsThemeColorIntent } from '@ovhcloud/ods-theming';

/**
* default attribute values of link
*/
export const odsLinkDefaultAttributesDoc = {
const DEFAULT_ATTRIBUTE: OdsLinkAttribute = Object.freeze({
color: OdsThemeColorIntent.default,
contrasted: false,
disabled: false,
Expand All @@ -14,6 +11,8 @@ export const odsLinkDefaultAttributesDoc = {
rel: undefined,
target: undefined,
type: undefined,
} as const;
});

export const odsLinkDefaultAttributes = odsLinkDefaultAttributesDoc as OdsLinkAttributes;
export {
DEFAULT_ATTRIBUTE,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
enum ODS_LINK_REFERRER_POLICY {
noReferrer = 'no-referrer',
noReferrerWhenDowngrade = 'no-referrer-when-downgrade',
origin = 'origin',
originWhenCrossOrigin = 'origin-when-cross-origin',
sameOrigin = 'same-origin',
strictOriginWhenCrossOrigin = 'strict-origin-when-cross-origin',
unsafeUrl = 'unsafe-url',
}

const ODS_LINK_REFERRER_POLICIES = Object.freeze(Object.values(ODS_LINK_REFERRER_POLICY));

export {
ODS_LINK_REFERRER_POLICIES,
ODS_LINK_REFERRER_POLICY,
};
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
import {
OdsClearLoggerSpy,
OdsInitializeLoggerSpy,
OdsLoggerSpyReferences
} from '@ovhcloud/ods-testing/src';

import { Ods } from '../../configure/ods';
import { OdsLink } from './ods-link';
import { OdsLinkController } from './ods-link-controller';
import { OdsLinkMock } from './ods-link-mock';
import { OdsLinkReferrerpolicy } from './ods-link-referrerpolicy';
import { OdsHTMLAnchorElementRel } from '../../types/ods-html-anchor-element-rel';
import { OdsHTMLAnchorElementTarget } from '../../types/ods-html-anchor-element-target';
import { OdsLogger } from '../../logger/ods-logger';
import type { OdsLoggerSpyReferences } from '@ovhcloud/ods-common-testing';
import { Ods, OdsHTMLAnchorElementRel, OdsHTMLAnchorElementTarget, OdsLogger } from '@ovhcloud/ods-common-core';
import { OdsClearLoggerSpy, OdsInitializeLoggerSpy } from '@ovhcloud/ods-common-testing';
import { OdsThemeColorIntent } from '@ovhcloud/ods-theming';
import { ODS_LINK_REFERRER_POLICY } from '../constants/referrer-policies';
import { OdsLinkController } from './controller';
import { OsdsLink } from '../osds-link';

class OdsLinkMock extends OsdsLink {
constructor(attribute: Partial<OsdsLink>) {
super();
Object.assign(this, attribute)
}
}

describe('spec:ods-link-controller', () => {
let controller: OdsLinkController;
let component: OdsLink;
let component: OsdsLink;
let loggerSpyReferences: OdsLoggerSpyReferences;

Ods.instance().logging(false);

function setup(attributes: Partial<OdsLink> = {}) {
component = { ...component, ...attributes };
function setup(attributes: Partial<OsdsLink> = {}) {
component = new OdsLinkMock(attributes);
controller = new OdsLinkController(component);
}

beforeEach(() => {
component = new OdsLinkMock();

const loggerMocked = new OdsLogger('myLoggerMocked');
loggerSpyReferences = OdsInitializeLoggerSpy({
loggerMocked: loggerMocked as never,
Expand All @@ -45,7 +42,7 @@ describe('spec:ods-link-controller', () => {
beforeEach(() => {
setup({
color: OdsThemeColorIntent.default,
referrerpolicy: OdsLinkReferrerpolicy.origin,
referrerpolicy: ODS_LINK_REFERRER_POLICY.origin,
rel: OdsHTMLAnchorElementRel.noreferrer,
target: OdsHTMLAnchorElementTarget._blank,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { OdsComponentController } from '../ods-component-controller';
import { OdsLink } from './ods-link';
import { OdsLogger } from '../../logger/ods-logger';
import type { OsdsLink } from '../osds-link';
import { OdsHTMLAnchorElementTarget, OdsLogger, OdsWarnComponentAttribute } from '@ovhcloud/ods-common-core';
import { OdsThemeColorIntent } from '@ovhcloud/ods-theming';
import { OdsWarnComponentAttribute } from '../../logger/ods-warn-logger';
import { OdsHTMLAnchorElementTarget } from '../../types/ods-html-anchor-element-target';

/**
* common controller logic for link component used by the different implementations.
* it contains all the glue between framework implementation and the third party service.
*/
export class OdsLinkController extends OdsComponentController<OdsLink> {

class OdsLinkController {
private readonly logger = new OdsLogger('OdsLinkController');
protected component: OsdsLink;

constructor(component: OdsLink) {
super(component);
constructor(component: OsdsLink) {
this.component = component;
}

/**
Expand All @@ -23,20 +20,27 @@ export class OdsLinkController extends OdsComponentController<OdsLink> {
*/
validateAttributes(): void {
const logger = this.logger;
OdsWarnComponentAttribute<OdsThemeColorIntent, OdsLink>({

OdsWarnComponentAttribute<OdsThemeColorIntent, OsdsLink>({
logger,
attributeValues: OdsThemeColorIntent as Record<string, unknown>,
attributeName: 'color',
attribute: this.component.color
});

if (this.component.href && !this.component.target) {
this.component.target = OdsHTMLAnchorElementTarget._self;
}
this.component.href && OdsWarnComponentAttribute<OdsHTMLAnchorElementTarget, OdsLink>({

this.component.href && OdsWarnComponentAttribute<OdsHTMLAnchorElementTarget, OsdsLink>({
logger,
attributeValues: OdsHTMLAnchorElementTarget as Record<string, unknown>,
attributeName: 'target',
attribute: this.component.target,
});
}
}

export {
OdsLinkController,
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { OdsLinkReferrerpolicy } from './ods-link-referrerpolicy';
import { OdsThemeColorIntent } from '@ovhcloud/ods-theming';
import { OdsComponentAttributes } from '../ods-component-attributes';
import { OdsHTMLAnchorElementRel } from '../../types/ods-html-anchor-element-rel';
import { OdsHTMLAnchorElementTarget } from '../../types/ods-html-anchor-element-target';
import type { ODS_LINK_REFERRER_POLICY } from '../constants/referrer-policies';
import type { OdsThemeColorIntent } from '@ovhcloud/ods-theming';
import type { OdsHTMLAnchorElementRel, OdsHTMLAnchorElementTarget } from '@ovhcloud/ods-common-core'

export interface OdsLinkAttributes extends OdsComponentAttributes {
interface OdsLinkAttribute {
/** Link color theme */
color?: OdsThemeColorIntent
/** Link design as contrasted version */
Expand All @@ -16,14 +14,18 @@ export interface OdsLinkAttributes extends OdsComponentAttributes {
/** Link URL */
href?: string
/** Link referrer policy */
referrerpolicy?: OdsLinkReferrerpolicy
referrerpolicy?: ODS_LINK_REFERRER_POLICY
/** Link relationship */
rel?: OdsHTMLAnchorElementRel
/**
/**
* Link target type
* If href is set the default value `_self` is set
*/
target?: OdsHTMLAnchorElementTarget
/** Link type (for download source) */
type?: string
}

export {
OdsLinkAttribute,
};
Loading

0 comments on commit 034064d

Please sign in to comment.