Skip to content

Commit

Permalink
feat(uirefresh): component refresh - positions table (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn authored Oct 16, 2024
1 parent 44282c2 commit 32586d8
Show file tree
Hide file tree
Showing 11 changed files with 850 additions and 249 deletions.
2 changes: 1 addition & 1 deletion src/components/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ const $Text = styled.output<{ withParentheses?: boolean }>`
opacity: 0.5;
&:after {
content: '-' var(--output-afterString);
content: '' var(--output-afterString);
}
}
Expand Down
25 changes: 13 additions & 12 deletions src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export type ColumnDef<TableRowData extends BaseTableRowData | CustomRowConfig> =
isActionable?: boolean;
hideOnBreakpoint?: MediaQueryKeys;
width?: ColumnSize;
align?: 'start' | 'center' | 'end';
} & (SortableColumnDef<TableRowData> | NonSortableColumnDef);

export type TableElementProps<TableRowData extends BaseTableRowData | CustomRowConfig> = {
Expand Down Expand Up @@ -406,17 +407,14 @@ const TableRoot = <TableRowData extends BaseTableRowData | CustomRowConfig>(prop
state={state}
withScrollSnapRows={withScrollSnapRows}
>
{[...headerRow.childNodes].map(
(column) => (
<TableColumnHeader
key={column.key}
column={column}
state={state}
withScrollSnapColumns={withScrollSnapColumns}
/>
)
// )
)}
{[...headerRow.childNodes].map((column) => (
<TableColumnHeader
key={column.key}
column={column}
state={state}
withScrollSnapColumns={withScrollSnapColumns}
/>
))}
</TableHeaderRow>
))}
</TableHeadRowGroup>
Expand Down Expand Up @@ -568,7 +566,10 @@ const TableColumnHeader = <TableRowData extends BaseTableRowData>({
<$Th
{...mergeProps(columnHeaderProps, focusProps)}
// data-focused={isFocusVisible || undefined}
style={{ width: column.props?.width }}
style={{
width: column.props?.width,
textAlign: (column?.value as any)?.align,
}}
ref={ref}
allowSorting={column.props?.allowsSorting ?? true}
withScrollSnapColumns={withScrollSnapColumns}
Expand Down
14 changes: 11 additions & 3 deletions src/components/Table/ActionsTableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ type ElementProps = {
children: React.ReactNode;
};

export const ActionsTableCell = ({ children }: ElementProps) => (
type StyleProps = {
className?: string;
};

export const ActionsTableCell = ({ children, className }: ElementProps & StyleProps) => (
<div tw="flex justify-end">
<$Toolbar $numChildren={React.Children.toArray(children).length}>{children}</$Toolbar>
<$Toolbar className={className} $numChildren={React.Children.toArray(children).length}>
{children}
</$Toolbar>
</div>
);
const $Toolbar = styled(Toolbar)<{ $numChildren: number }>`
Expand All @@ -20,11 +26,13 @@ const $Toolbar = styled(Toolbar)<{ $numChildren: number }>`
width: calc(${$numChildren} * 2rem + (${$numChildren} - 1) * 0.5rem);
`}
--toolbar-margin: 0.5rem;
display: flex;
justify-content: flex-end;
padding: 0;
> *:not(:last-child) {
margin-right: 0.5rem;
margin-right: var(--toolbar-margin);
}
`;
4 changes: 3 additions & 1 deletion src/icons/share.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 36 additions & 12 deletions src/pages/trade/HorizontalPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,41 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
PositionsTableColumnKey.IndexEntry,
PositionsTableColumnKey.PnL,
]
: [
PositionsTableColumnKey.Market,
PositionsTableColumnKey.Size,
PositionsTableColumnKey.Margin,
PositionsTableColumnKey.UnrealizedPnl,
!isDesktopSmall && PositionsTableColumnKey.RealizedPnl,
PositionsTableColumnKey.NetFunding,
PositionsTableColumnKey.AverageOpenAndClose,
PositionsTableColumnKey.LiquidationAndOraclePrice,
shouldRenderTriggers && PositionsTableColumnKey.Triggers,
shouldRenderActions && PositionsTableColumnKey.Actions,
].filter(isTruthy)
: uiRefresh
? [
PositionsTableColumnKey.Market,
PositionsTableColumnKey.Leverage,
PositionsTableColumnKey.Type,
PositionsTableColumnKey.Size,
PositionsTableColumnKey.Value,
PositionsTableColumnKey.PnL,
PositionsTableColumnKey.Margin,
PositionsTableColumnKey.AverageOpen,
PositionsTableColumnKey.Oracle,
PositionsTableColumnKey.Liquidation,
shouldRenderTriggers && PositionsTableColumnKey.Triggers,
PositionsTableColumnKey.NetFunding,
shouldRenderActions && PositionsTableColumnKey.Actions,
].filter(isTruthy)
: [
PositionsTableColumnKey.Market,
PositionsTableColumnKey.Size,
PositionsTableColumnKey.Margin,
PositionsTableColumnKey.UnrealizedPnl,
!isDesktopSmall && PositionsTableColumnKey.RealizedPnl,
PositionsTableColumnKey.NetFunding,
PositionsTableColumnKey.AverageOpenAndClose,
PositionsTableColumnKey.LiquidationAndOraclePrice,
shouldRenderTriggers && PositionsTableColumnKey.Triggers,
shouldRenderActions && PositionsTableColumnKey.Actions,
].filter(isTruthy)
}
columnWidths={
uiRefresh
? {
[PositionsTableColumnKey.Actions]: 100,
}
: undefined
}
showClosePositionAction={shouldRenderActions}
initialPageSize={initialPageSize}
Expand All @@ -174,6 +197,7 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
shouldRenderTriggers,
numTotalPositions,
onViewOrders,
uiRefresh,
]
);

Expand Down
Loading

0 comments on commit 32586d8

Please sign in to comment.