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

Convert right-to-left demo to TS #10164

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion packages/react-core/src/demos/RTL/RTL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ This demonstrates how the UI adapts to the writing mode of the page.

### Paginated table

```js file="./examples/PaginatedTable.jsx" isFullscreen
```ts file="./examples/PaginatedTable.tsx" isFullscreen
ajaypratap003 marked this conversation as resolved.
Show resolved Hide resolved

```
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-ico
import HandPaperIcon from '@patternfly/react-icons/dist/esm/icons/hand-paper-icon';
import imgAvatar from '@patternfly/react-core/src/components/assets/avatarImg.svg';

export const PaginatedTableAction = () => {
const [translation, setTranslation] = React.useState(translationsEn);
const [page, setPage] = React.useState(1);
const [perPage, setPerPage] = React.useState(10);
interface Row {
name: string;
status: string[];
location: string[];
lastModified: string[];
wise-king-sullyman marked this conversation as resolved.
Show resolved Hide resolved
url: string;
}

export const PaginatedTableAction: React.FunctionComponent = () => {
const [translation, setTranslation] = React.useState<string>(translationsEn);
wise-king-sullyman marked this conversation as resolved.
Show resolved Hide resolved
const [page, setPage] = React.useState<number>(1);
const [perPage, setPerPage] = React.useState<number>(10);

const columns = [
translation.table.columns.servers,
Expand All @@ -71,13 +79,13 @@ export const PaginatedTableAction = () => {
translation.table.columns.url
];

const numRows = 25;
const getRandomInteger = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
const numRows: number = 25;
const getRandomInteger = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;
const createRows = () => {
const rows = [];
const rows: Row[] = [];
for (let i = 0; i < numRows; i++) {
const num = i + 1;
const rowObj = {
const rowObj: Row = {
name: translation.table.rows.node + num,
status: [
translation.table.rows.status.stopped,
Expand Down Expand Up @@ -110,14 +118,14 @@ export const PaginatedTableAction = () => {

const rows = createRows();
const [managedRows, setManagedRows] = React.useState(rows);
const [paginatedRows, setPaginatedRows] = React.useState(rows.slice(0, 10));
const [isDirRTL, setIsDirRTL] = React.useState(false);
const [paginatedRows, setPaginatedRows] = React.useState<Row[]>(rows.slice(0, 10));
const [isDirRTL, setIsDirRTL] = React.useState<boolean>(false);

const capitalize = (input) => input[0].toUpperCase() + input.substring(1);
const capitalize = (input: string) => input[0].toUpperCase() + input.substring(1);

const switchTranslation = () => {
setIsDirRTL((prevIsDirRTL) => !prevIsDirRTL);
setTranslation((prevTranslation) => (prevTranslation === translationsEn ? translationsHe : translationsEn));
setTranslation((prevTranslation: string) => (prevTranslation === translationsEn ? translationsHe : translationsEn));
};

React.useEffect(() => {
Expand All @@ -133,17 +141,17 @@ export const PaginatedTableAction = () => {

// Pagination logic

const handleSetPage = (_evt, newPage, _perPage, startIdx, endIdx) => {
const handleSetPage = (_evt: Event, newPage: number, _perPage: number, startIdx: number, endIdx: number) => {
setPaginatedRows(managedRows.slice(startIdx, endIdx));
setPage(newPage);
};

const handlePerPageSelect = (_evt, newPerPage, _newPage, startIdx, endIdx) => {
const handlePerPageSelect = (_evt: Event, newPerPage: number, _newPage: number, startIdx: number, endIdx: number) => {
wise-king-sullyman marked this conversation as resolved.
Show resolved Hide resolved
setPaginatedRows(managedRows.slice(startIdx, endIdx));
setPerPage(newPerPage);
};

const renderPagination = (variant) => {
const renderPagination = (variant: PaginationVariant) => {
const { pagination } = translation;

return (
Expand Down Expand Up @@ -181,7 +189,7 @@ export const PaginatedTableAction = () => {
}
};

const renderLabel = (labelText) => {
const renderLabel = (labelText: string) => {
switch (labelText) {
case 'Running':
case 'רץ':
Expand Down Expand Up @@ -280,9 +288,9 @@ export const PaginatedTableAction = () => {
</PageSidebar>
);

const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);
const [isKebabDropdownOpen, setIsKebabDropdownOpen] = React.useState(false);
const [isFullKebabDropdownOpen, setIsFullKebabDropdownOpen] = React.useState(false);
const [isDropdownOpen, setIsDropdownOpen] = React.useState<boolean>(false);
const [isKebabDropdownOpen, setIsKebabDropdownOpen] = React.useState<boolean>(false);
const [isFullKebabDropdownOpen, setIsFullKebabDropdownOpen] = React.useState<boolean>(false);

const kebabDropdownItems = (
<>
Expand Down Expand Up @@ -434,15 +442,17 @@ export const PaginatedTableAction = () => {
</Masthead>
);

const breadcrumbItemsLength = Object.keys(breadcrumbItems).length;

return (
<React.Fragment>
<Page sidebar={sidebar} header={masthead} isManagedSidebar>
<PageBreadcrumb>
<Breadcrumb aria-label={translation.breadcrumbs.ariaLabel || undefined}>
{Object.keys(breadcrumbItems).map((key, idx, arr) => (
{Object.keys(breadcrumbItems).map((key: string, idx: number, arr: string[]) => (
<BreadcrumbItem key={idx} isActive={arr.length - 1 === idx} to={`${breadcrumbItems[key].url}`}>
{translation.breadcrumbs[key]}
{breadcrumbItems.length}
{breadcrumbItemsLength}
</BreadcrumbItem>
))}
</Breadcrumb>
Expand All @@ -465,7 +475,7 @@ export const PaginatedTableAction = () => {
</Tr>
</Thead>
<Tbody>
{paginatedRows.map((row, rowIndex) => (
{paginatedRows.map((row: Row, rowIndex: number) => (
<Tr key={rowIndex}>
<>
{Object.entries(row).map(([key, value]) => {
Expand Down
Loading