Skip to content

Commit

Permalink
fix: time zone and share
Browse files Browse the repository at this point in the history
  • Loading branch information
jacovinus committed Sep 14, 2023
1 parent 22294ba commit dd33b21
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
26 changes: 19 additions & 7 deletions packages/main/plugins/Cardinality/DayPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ export const MenuStyles = (theme: any) => ({
},
});


export const formatUTC = (dateInt, addOffset = false) => {
let date = (!dateInt || dateInt.length < 1) ? new Date : new Date(dateInt);
if (typeof dateInt === "string") {
return date;
} else {
const offset = addOffset ? date.getTimezoneOffset() : - (date.getTimezoneOffset());
const offsetDate = new Date();
offsetDate.setTime(date.getTime() + offset * 60000)
return offsetDate;
}
}

export default function PickerMenu() {
const theme = useTheme();
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
Expand All @@ -94,16 +107,16 @@ export default function PickerMenu() {
}

const handleSelect = (dateSelected: Date) => {
setSelected(() => dateSelected);
setDate(dayjs(dateSelected).format(DATE_FORMAT));
setSelected(() => formatUTC(dateSelected));
setDate(dayjs(formatUTC(dateSelected)).format(DATE_FORMAT));
setAnchorEl(null);
};

const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
// setAnchorEl(null);
setAnchorEl(null);
};

return (
Expand Down Expand Up @@ -144,11 +157,10 @@ export default function PickerMenu() {
</Tooltip>
</Box>
<Menu
anchorEl={anchorEl}
id="account-menu"
anchorEl={anchorEl}
open={open}
// onClose={handleClose}
onClick={handleClose}
onClose={handleClose}
PaperProps={{
elevation: 0,
sx: MenuStyles(theme),
Expand All @@ -158,7 +170,7 @@ export default function PickerMenu() {
>
<DayPicker
mode="single"
selected={selected}
selected={formatUTC(selected,true)}
onSelect={handleSelect}
footer={footer}
/>
Expand Down
5 changes: 4 additions & 1 deletion packages/main/plugins/Cardinality/SeriesGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const SeriesGroupContainer = (theme: any) => css`
export type SeriesGroupProps = {
rows: SeriesRowProps[];
sectionHeader: string;
sectionHeaderName:string;
} & SeriesHeaderProps;

// format the header according to the header type
Expand All @@ -35,6 +36,7 @@ export const SeriesGroup: React.FC<SeriesGroupProps> = ({
title,
rows,
sectionHeader,
sectionHeaderName
}: SeriesGroupProps) => {
const theme = useTheme();

Expand Down Expand Up @@ -66,14 +68,15 @@ export const SeriesGroup: React.FC<SeriesGroupProps> = ({
{rows && (
<SeriesRowHeaders
handleSort={handleSort}
headerName={sectionHeaderName}
name={sectionHeader}
theme={theme}
/>
)}
{sortedRows &&
sortedRows?.length > 0 &&
sortedRows.map((row: SeriesRowProps, key: number) => (
<SeriesRow key={key} {...row} />
<SeriesRow key={key} headerName={sectionHeaderName} {...row} />
))}
</div>
</div>
Expand Down
32 changes: 21 additions & 11 deletions packages/main/plugins/Cardinality/SeriesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type SeriesRowProps = {
value: number;
share: number;
theme: any;
headerName: string;
source: any;
onFilter: (e: any, val: any) => void;
};
Expand Down Expand Up @@ -97,7 +98,7 @@ export const SeriesRowStyle = (theme: any) => css`
border-radius: 3px;
height: 12px;
border: 1px solid ${theme.accentNeutral};
border: 1px solid ${theme.ultraDeep};
display: flex;
flex: 1;
}
Expand All @@ -121,9 +122,11 @@ export const SeriesRow = ({
diff,
share,
theme,
headerName,
onFilter,
source,
}: SeriesRowProps) => {
console.log(headerName, "at series row")
const { handleDelete } = useCardinalityRequest();
return (
<div className={cx(SeriesRowStyle(theme))}>
Expand Down Expand Up @@ -152,14 +155,17 @@ export const SeriesRow = ({
</span>
</div>
</div>
<div className="cell">
<div className="c-share-cont">
<div className="c-progress">
<progress value={share} max={100} />
<span className="c-share">{share.toFixed(2)}%</span>
</div>
</div>
</div>
{ headerName !== "labelValueCountByLabelName" && (<div className="cell">
<div className="c-share-cont">
<div className="c-progress">
<progress value={share} max={100} />
<span className="c-share">{share.toFixed(2)}%</span>
</div>
</div>
</div>)
}


<div className="cell">
<CardinalityDialog
clearFingerPrints={(query) => handleDelete(query)}
Expand All @@ -172,7 +178,8 @@ export const SeriesRow = ({
);
};

export const SeriesRowHeaders = ({ theme, name, handleSort }) => {
export const SeriesRowHeaders = ({ theme, name, headerName, handleSort }) => {
console.log(headerName);
return (
<div className={cx(SeriesRowStyle(theme))}>
<div
Expand All @@ -187,7 +194,10 @@ export const SeriesRowHeaders = ({ theme, name, handleSort }) => {
>
Number of Series
</div>
<div className="cell-header cell">Share in Total</div>
{headerName !== "labelValueCountByLabelName" && (
<div className="cell-header cell">Share in Total</div>
)}

<div className="cell-header cell center">Delete</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions packages/main/plugins/Cardinality/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export const Cardinality = () => {
title={
sectionsTitles("metric")[Object.keys(series)[0]]
}
sectionHeaderName={Object.keys(series)[0] as string}
sectionHeader={tableHeaders[Object.keys(series)[0]]}
rows={series[Object.keys(series)[0]]}
/>
Expand Down

0 comments on commit dd33b21

Please sign in to comment.