Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d7ce9fb
initial conversion of size-selecotr to ts
zamoore Aug 22, 2024
e6a09c9
finished converting SizeSelector
zamoore Aug 22, 2024
6a9dcb6
initial conversion of Pagination::Info to ts
zamoore Aug 22, 2024
6b51e97
finished initial conversion of HdsPaginationInfo component
zamoore Aug 22, 2024
9daa2b3
initial conversion of pagination::numbered component
zamoore Aug 22, 2024
1b025fb
finished initial conversion of hds::pagination::numbered
zamoore Aug 22, 2024
deef851
finished conversion
zamoore Aug 23, 2024
befa2bf
ts conversion in-progress
zamoore Aug 26, 2024
dcf4b32
initial conversion of the compact navigation component to ts
zamoore Aug 26, 2024
0e72ea3
finished conversion of the compact pagination component
zamoore Aug 26, 2024
3a84751
added ts files to component registry
zamoore Aug 26, 2024
26b5e6c
cleaned up the number component
zamoore Aug 26, 2024
e009344
finished converting the arrow component
zamoore Aug 26, 2024
e35600c
cleaned up the info component
zamoore Aug 26, 2024
b00aa80
added to template-registry:
zamoore Aug 26, 2024
180807b
cleaning up types
zamoore Aug 26, 2024
37d2576
cleaning up types
zamoore Aug 26, 2024
12a64d0
cleaning up types
zamoore Aug 26, 2024
7722795
no more type errors
zamoore Aug 27, 2024
eb5ed48
fixed ts errors after rebase
zamoore Aug 27, 2024
c16f8e6
fixing tests
zamoore Aug 27, 2024
0fafc62
fixing tests
zamoore Aug 27, 2024
fa1156b
Update changeset to be more inline with others
zamoore Aug 28, 2024
ed4ef8f
responding to PR feedback
zamoore Aug 28, 2024
b665e93
responding to PR feedback
zamoore Aug 28, 2024
8f5a3b2
removed dev comments
zamoore Aug 28, 2024
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
6 changes: 6 additions & 0 deletions .changeset/hungry-cycles-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@hashicorp/design-system-components": minor
---

`Hds::Pagination` - Converted component to Typescript
- Converted to Typescript
14 changes: 14 additions & 0 deletions packages/components/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ import HdsModalBodyComponent from './components/hds/modal/body.ts';
import HdsModalFooter from './components/hds/modal/footer.ts';
import HdsModalHeader from './components/hds/modal/header.ts';
import HdsPageHeader from './components/hds/page-header/index.ts';
import HdsPaginationCompactComponent from './components/hds/pagination/compact/index.ts';
import HdsPaginationControlInfoComponent from './components/hds/pagination/info/index.ts';
import HdsPaginationControlArrowComponent from './components/hds/pagination/nav/arrow.ts';
import HdsPaginationControlEllipsisComponent from './components/hds/pagination/nav/ellipsis.ts';
import HdsPaginationControlNumberComponent from './components/hds/pagination/nav/number.ts';
import HdsPaginationNumberedComponent from './components/hds/pagination/numbered/index.ts';
import HdsPaginationSizeSelectorComponent from './components/hds/pagination/size-selector/index.ts';
import HdsPopoverPrimitive from './components/hds/popover-primitive/index.ts';
import HdsReveal from './components/hds/reveal/index.ts';
import HdsRichTooltip from './components/hds/rich-tooltip/index.ts';
Expand Down Expand Up @@ -201,6 +208,13 @@ export {
HdsModalFooter,
HdsModalHeader,
HdsPageHeader,
HdsPaginationCompactComponent,
HdsPaginationControlInfoComponent,
HdsPaginationControlArrowComponent,
HdsPaginationControlEllipsisComponent,
HdsPaginationControlNumberComponent,
HdsPaginationNumberedComponent,
HdsPaginationSizeSelectorComponent,
HdsPopoverPrimitive,
HdsReveal,
HdsRichTooltip,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{! @glint-nocheck: not typesafe yet }}
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,47 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { assert } from '@ember/debug';
import { HdsPaginationDirectionValues } from '../types.ts';

import type {
HdsPaginationRoutingProps,
HdsPaginationDirections,
} from '../types';
import type { HdsInteractiveSignature } from '../../interactive';

type HdsInteractiveQuery = HdsInteractiveSignature['Args']['query'];

type HdsPaginationCompactRoutingQueryProps = HdsPaginationRoutingProps & {
queryNext?: HdsInteractiveQuery;
queryPrev?: HdsInteractiveQuery;
};

interface HdsPaginationCompactArgs {
ariaLabel?: string;
showLabels?: boolean;
isDisabledPrev?: boolean;
isDisabledNext?: boolean;
showSizeSelector?: boolean;
sizeSelectorLabel?: string;
pageSizes?: number[];
currentPageSize?: number;
queryFunction?: (
page: HdsPaginationDirections,
pageSize?: number
) => HdsInteractiveQuery;
onPageChange?: (page: HdsPaginationDirections) => void;
onPageSizeChange?: (pageSize: number) => void;
}

interface HdsPaginationCompactSignature {
Args: HdsPaginationCompactArgs & HdsPaginationRoutingProps;
Element: HTMLDivElement;
}

// for context about the decision to use these values, see:
// https://hashicorp.slack.com/archives/C03A0N1QK8S/p1673546329082759
export const DEFAULT_PAGE_SIZES = [10, 30, 50];

export default class HdsPaginationCompactIndexComponent extends Component {
export default class HdsPaginationCompactComponent extends Component<HdsPaginationCompactSignature> {
// This private variable is used to differentiate between
// "uncontrolled" component (where the state is handled internally) and
// "controlled" component (where the state is handled externally, by the consumer's code).
Expand All @@ -27,10 +62,10 @@ export default class HdsPaginationCompactIndexComponent extends Component {
showLabels = this.args.showLabels ?? true; // if the labels for the "prev/next" controls are visible
showSizeSelector = this.args.showSizeSelector ?? false; // if the "size selector" block is visible

constructor() {
super(...arguments);
constructor(owner: unknown, args: HdsPaginationCompactSignature['Args']) {
super(owner, args);

let { queryFunction } = this.args;
const { queryFunction } = this.args;

// This component works in two different ways, depending if we need to support
// routing through links (`LinkTo`) for the "navigation controls", or not.
Expand All @@ -51,12 +86,7 @@ export default class HdsPaginationCompactIndexComponent extends Component {
}
}

/**
* @param ariaLabel
* @type {string}
* @default 'Pagination'
*/
get ariaLabel() {
get ariaLabel(): string {
return this.args.ariaLabel ?? 'Pagination';
}

Expand All @@ -73,14 +103,13 @@ export default class HdsPaginationCompactIndexComponent extends Component {
// is *always* determined by the component's internal logic (and updated according to the user interaction with it).
// For this reason the "get" and "set" methods always read from or write to the private internal state (_variable).

get currentPageSize() {
get currentPageSize(): number | undefined {
if (this.isControlled) {
return this.args.currentPageSize;
} else {
return this._currentPageSize;
}
}

set currentPageSize(value) {
if (this.isControlled) {
// noop
Expand All @@ -89,33 +118,31 @@ export default class HdsPaginationCompactIndexComponent extends Component {
}
}

/**
* @param pageSizes
* @type {array of numbers}
* @description Set the page sizes users can select from.
* @default [10, 30, 50]
*/
get pageSizes() {
let { pageSizes = DEFAULT_PAGE_SIZES } = this.args;
get pageSizes(): number[] {
const { pageSizes = DEFAULT_PAGE_SIZES } = this.args;

assert(
`pageSizes argument must be an array. Received: ${pageSizes}`,
Array.isArray(pageSizes) === true
Array.isArray(pageSizes) === true && pageSizes.length > 0
);

return pageSizes;
}

buildQueryParamsObject(page, pageSize) {
buildQueryParamsObject(
page: HdsPaginationDirections,
pageSize?: number
): HdsInteractiveQuery {
if (this.isControlled) {
return this.args.queryFunction(page, pageSize);
// if the component is controlled, we can assert that the queryFunction is defined
return this.args.queryFunction!(page, pageSize);
} else {
return {};
}
}

get routing() {
let routing = {
get routing(): HdsPaginationCompactRoutingQueryProps {
const routing: HdsPaginationCompactRoutingQueryProps = {
route: this.args.route ?? undefined,
model: this.args.model ?? undefined,
models: this.args.models ?? undefined,
Expand All @@ -125,11 +152,11 @@ export default class HdsPaginationCompactIndexComponent extends Component {
// the "query" is dynamic and needs to be calculated
if (this.isControlled) {
routing.queryPrev = this.buildQueryParamsObject(
'prev',
HdsPaginationDirectionValues.Prev,
this.currentPageSize
);
routing.queryNext = this.buildQueryParamsObject(
'next',
HdsPaginationDirectionValues.Next,
this.currentPageSize
);
} else {
Expand All @@ -141,19 +168,17 @@ export default class HdsPaginationCompactIndexComponent extends Component {
}

@action
onPageChange(newPage) {
this.currentPage = newPage;

let { onPageChange } = this.args;
onPageChange(newPage: HdsPaginationDirections): void {
const { onPageChange } = this.args;

if (typeof onPageChange === 'function') {
onPageChange(newPage);
}
}

@action
onPageSizeChange(newPageSize) {
let { onPageSizeChange } = this.args;
onPageSizeChange(newPageSize: number): void {
const { onPageSizeChange } = this.args;

// invoke the callback function
if (typeof onPageSizeChange === 'function') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{! @glint-nocheck: not typesafe yet }}
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
Expand Down
17 changes: 0 additions & 17 deletions packages/components/src/components/hds/pagination/info/index.js

This file was deleted.

23 changes: 23 additions & 0 deletions packages/components/src/components/hds/pagination/info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

import Component from '@glimmer/component';
import type { HdsPaginationNumberedSignature } from '../numbered/index';
import type { HdsTextBodySignature } from '../../text/body';
interface HdsPaginationInfoSignature {
Args: {
itemsRangeStart: number;
itemsRangeEnd: number;
showTotalItems?: HdsPaginationNumberedSignature['Args']['showTotalItems'];
totalItems: HdsPaginationNumberedSignature['Args']['totalItems'];
};
Element: HdsTextBodySignature['Element'];
}

export default class HdsPaginationInfoComponent extends Component<HdsPaginationInfoSignature> {
get showTotalItems(): boolean {
return this.args.showTotalItems ?? true;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{! @glint-nocheck: not typesafe yet }}
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
Expand Down
77 changes: 0 additions & 77 deletions packages/components/src/components/hds/pagination/nav/arrow.js

This file was deleted.

Loading