Skip to content
This repository was archived by the owner on Feb 23, 2022. It is now read-only.
15 changes: 1 addition & 14 deletions src/Containers/SquareTable/SquareTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@ import React from 'react';
import { Meta, Story } from '@storybook/react';
import { ISquareTable, SquareTable } from '@Containers';


export default {
title: 'Components/TableManagement/SquareTable',
component: SquareTable,
argTypes: { onTableClick: {action: "Clicked table with index: "} },
} as Meta;

const Template: Story<ISquareTable> = (args) => <SquareTable {...args} />;

/**
* Prints the Selected Child index to the console when Table is clicked
* @param selectedChildIndex
*/
const handleTableClick = (selectedChildIndex: number) => {
console.log(selectedChildIndex);
};

/**
* Prints the Selected Child index to the console when Chair is clicked
* @param tableIndex
Expand Down Expand Up @@ -144,7 +136,6 @@ SevenTopSquareTable.args = {
],
isSquare: true,
tableUse: 'TableForManagement',
onTableClick: handleTableClick,
onChairClick: handleOnChairClick,
};

Expand Down Expand Up @@ -257,7 +248,6 @@ EightTopVertRectangleTable.args = {
],
isSquare: false,
tableUse: 'TableForManagement',
onTableClick: handleTableClick,
onChairClick: handleOnChairClick,
};

Expand Down Expand Up @@ -347,7 +337,6 @@ SixTopHorizontalRectangleTable.args = {
isSquare: false,
relativeSize: 0.5,
tableUse: 'TableForManagement',
onTableClick: handleTableClick,
onChairClick: handleOnChairClick,
};

Expand Down Expand Up @@ -410,7 +399,6 @@ SquareTableEditPage.args = {
},
],
tableUse: 'TableForEditCanvas',
onTableClick: handleTableClick,
onChairClick: handleOnChairClick,
};

Expand Down Expand Up @@ -472,6 +460,5 @@ BarRectangleTable.args = {
],
isSquare: false,
tableUse: 'TableForManagement',
onTableClick: handleTableClick,
onChairClick: handleOnChairClick,
};
64 changes: 49 additions & 15 deletions src/Containers/SquareTable/SquareTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Documentation – the order of chairs are in the chairs array will populate the table from top left to the bottom right
* “the purpose of the order in the array is to populate the chairs from top left to bottom right”
*/
import React, { useEffect, useRef } from 'react';
import React, {useEffect, useRef, useState} from 'react';
import styled, { useTheme } from 'styled-components';
import { Plus } from '@styled-icons/boxicons-regular';
import { IChair } from '../Chair/Chair';
Expand All @@ -24,7 +24,7 @@ type getSquareTableSizeType = (
type getRectangleTableType = (top: number, bottom: number, left: number, right : number) => number;

type addInvisibleChairs = (
invisibileChairs: Array<IChair>,
invisibleChairs: Array<IChair>,
targetSize: number,
position: Position,
) => void;
Expand Down Expand Up @@ -103,14 +103,11 @@ export interface ISquareTable {
isNotHighlightedWhenSelected?: boolean;
}



/**
* Primary UI component for user interaction
* Square Table
*/
export const SquareTable: React.FC<ISquareTable> = ({
// tableShape = 'Square',
tableID = 'T1',
partyName = 'Null',
occupancyStatus = 'Vacant',
Expand All @@ -120,7 +117,6 @@ export const SquareTable: React.FC<ISquareTable> = ({
isSquare = false,
tableUse = 'TableForManagement',
arrayIndex = 0,
selectedIndex = -1,
onTableClick,
onChairClick,
isNotHighlightedWhenSelected = false,
Expand All @@ -129,12 +125,14 @@ export const SquareTable: React.FC<ISquareTable> = ({
// Create a reference to the TableBody styled component
const tableBodyRef = useRef(document.createElement('div'));

const [selectedTable, setSelectedTable] = useState(-1);

/**
* Use useEffect to keep focus on TableBody after re-render if the
* selectedIndex number matches the arrayIndex number for this table
*/
useEffect(() => {
if (selectedIndex === arrayIndex) {
if (selectedTable === arrayIndex) {
if (tableBodyRef != null) {
tableBodyRef.current.focus();
}
Expand Down Expand Up @@ -166,8 +164,10 @@ export const SquareTable: React.FC<ISquareTable> = ({
* Calls the onTableClick prop function with the arrayIndex prop as its
* parameter
*/
const callOnTableClick: callOnTableClickType = () =>
const callOnTableClick: callOnTableClickType = () => {
onTableClick(arrayIndex);
setSelectedTable(arrayIndex);
}

/**
* Determines how many chairs to put per each side
Expand Down Expand Up @@ -233,7 +233,7 @@ export const SquareTable: React.FC<ISquareTable> = ({
tableUse,
chairIndex: invisibileChairs.length,
tableIndex: arrayIndex,
selectedIndex,
selectedIndex: selectedTable,
onChairClick,
});
}
Expand Down Expand Up @@ -296,14 +296,19 @@ export const SquareTable: React.FC<ISquareTable> = ({
};

return (
<div {...props}>
<div{...props}>
<TableContainer
relativeSize = {relativeSize}
tableIndex = {arrayIndex}
selectedIndex = {selectedTable}
>
{/** chairs top */}
<ChairRow
position="top"
chairs={topArray}
relativeSize={relativeSize}
tableUse={tableUse}
selectedIndex={selectedIndex}
selectedIndex={selectedTable}
/>

{/** table itself */}
Expand All @@ -315,7 +320,7 @@ export const SquareTable: React.FC<ISquareTable> = ({
position="left"
chairs={leftArray}
tableUse={tableUse}
selectedIndex={selectedIndex}
selectedIndex={selectedTable}
/>

<TableBody
Expand All @@ -341,7 +346,7 @@ export const SquareTable: React.FC<ISquareTable> = ({
position="right"
chairs={rightArray}
tableUse={tableUse}
selectedIndex={selectedIndex}
selectedIndex={selectedTable}
/>
</Row>
</div>
Expand All @@ -352,8 +357,9 @@ export const SquareTable: React.FC<ISquareTable> = ({
position="bottom"
chairs={bottomArray}
tableUse={tableUse}
selectedIndex={selectedIndex}
selectedIndex={selectedTable}
/>
</TableContainer>
</div>
);
};
Expand All @@ -380,8 +386,36 @@ const getOccupancyColor: getOccupancyColorType = (occupancyStatus) => {
};

/**
* variables for the styled components
* Variables for the styled components
*/
interface ITableContainer {
relativeSize: number;
tableIndex: number;
selectedIndex: number;
}

const TableContainer = styled.div<ITableContainer>`
${({ selectedIndex, tableIndex, relativeSize, theme }):string =>
{
const BASE_BORDER_RADIUS = 3;
const PADDING = 1.5;

if(tableIndex === selectedIndex){
return`
background-color: ${theme.colors.tableOutline.background};
border-radius: ${BASE_BORDER_RADIUS * relativeSize}rem;
width: fit-content;
padding: ${PADDING * relativeSize}rem;
border-style: dashed;
border-color: ${theme.colors.tableOutline.border};
`;
}

return ``;
}
};

`;

interface ITableBody {
chairNumOnSide: number;
Expand Down
8 changes: 8 additions & 0 deletions src/Themes/MainTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export interface MainThemeInterface extends ThemeTemplateInterface {
green: string;
};
bannerBackgroundColor: string;
tableOutline: {
background: string;
border: string;
}
};
}

Expand Down Expand Up @@ -77,5 +81,9 @@ export const MainTheme: MainThemeInterface = {
yellow: '#d1b306',
green: '#09d106',
},
tableOutline: {
background: "#EDEEF5",
border: "#DDDFE5",
}
},
};