Skip to content

Commit

Permalink
chore/removed metric value field (#475)
Browse files Browse the repository at this point in the history
* remove metric value field

* review

* removed export
  • Loading branch information
EduardZaydler authored Jan 22, 2024
1 parent b1eea65 commit 1017cee
Show file tree
Hide file tree
Showing 9 changed files with 439 additions and 453 deletions.
Binary file modified playwright/snapshots/EventList/eventlist--default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 25 additions & 36 deletions src/Components/EventList/EventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,34 @@ export default function EventList(props: Props): React.ReactElement {
</div>
{Object.keys(items).map((key) => (
<div key={key} className={cn("group")}>
{items[key].map(
({ old_state: oldState, state, timestamp, value, values }, i) => {
const oldValue = items[key][i + 1] && items[key][i + 1].value;
const oldValues = items[key][i + 1] && items[key][i + 1].values;
return (
<div key={`${key}-${timestamp}`} className={cn("row")}>
<div className={cn("name")}>{i === 0 && key}</div>
<div className={cn("state-change")}>
<div className={cn("prev-value")}>
<MetricValues
value={oldValue}
values={oldValues}
placeholder={false}
/>
</div>
<div className={cn("prev-state")}>
<StatusIndicator statuses={[oldState]} size={14} />
</div>
<div className={cn("arrow")}>
<ArrowBoldRightIcon />
</div>
<div className={cn("curr-state")}>
<StatusIndicator statuses={[state]} size={14} />
</div>
<div className={cn("curr-value")}>
<MetricValues
value={value}
values={values}
placeholder={false}
/>
</div>
{items[key].map(({ old_state: oldState, state, timestamp, values }, i) => {
const oldValues = items[key][i + 1] && items[key][i + 1].values;
return (
<div key={`${key}-${timestamp}`} className={cn("row")}>
<div className={cn("name")}>{i === 0 && key}</div>
<div className={cn("state-change")}>
<div className={cn("prev-value")}>
<MetricValues values={oldValues} placeholder={false} />
</div>
<div className={cn("date")}>
{format(fromUnixTime(timestamp), "MMM d, y, HH:mm:ss")}
<div className={cn("prev-state")}>
<StatusIndicator statuses={[oldState]} size={14} />
</div>
<div className={cn("arrow")}>
<ArrowBoldRightIcon />
</div>
<div className={cn("curr-state")}>
<StatusIndicator statuses={[state]} size={14} />
</div>
<div className={cn("curr-value")}>
<MetricValues values={values} placeholder={false} />
</div>
</div>
<div className={cn("date")}>
{format(fromUnixTime(timestamp), "MMM d, y, HH:mm:ss")}
</div>
);
}
)}
</div>
);
})}
</div>
))}
</section>
Expand Down
8 changes: 4 additions & 4 deletions src/Components/MetricListItem/MetricListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function maintenanceDelta(maintenance?: number | null): number {
return (maintenance || 0) - getUnixTime(getUTCDate());
}

const hideTargetsNames = ({ values }: Metric) => !values || Object.keys(values).length === 1;
const hideTargetsNames = (values: { [metric: string]: number } | undefined) => {
return !values || Object.keys(values).length === 1;
};

type MetricListItemProps = {
status: boolean;
Expand All @@ -43,7 +45,6 @@ export function MetricListItem({
onRemove,
}: MetricListItemProps) {
const {
value,
values,
event_timestamp: eventTimestamp = 0,
state,
Expand All @@ -64,10 +65,9 @@ export function MetricListItem({
</div>
<div className={cn("value")}>
<MetricValues
value={value}
values={values}
placeholder
hideTargetsNames={hideTargetsNames(metricData)}
hideTargetsNames={hideTargetsNames(metricData.values)}
/>
</div>
<div className={cn("maintenance")}>
Expand Down
8 changes: 4 additions & 4 deletions src/Components/MetricValues/MetricValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ type Props = {
values?: {
[metric: string]: number;
};
value?: number;
placeholder: boolean;
hideTargetsNames?: boolean;
};

export default function MetricValues(props: Props): React.ReactElement {
const { value, values, placeholder, hideTargetsNames } = props;
const { values, placeholder, hideTargetsNames } = props;
if (values === undefined) {
return <div>{roundValue(value, placeholder)}</div>;
return <div>{roundValue(values, placeholder)}</div>;
}
const arr = Object.keys(values).map((key) => {
return {
key,
value: values[key],
};
});
if (arr.length === 1 && hideTargetsNames === true) {
if (arr.length === 1 && hideTargetsNames) {
return <div id="targetsNames">{roundValue(arr[0].value, placeholder)}</div>;
}

return (
<div>
{arr.map((val) => (
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export type Event = {
state: Status;
old_state: Status;
timestamp: number;
value?: number;
values?: {
[metric: string]: number;
};
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type Metric = {
timestamp: number;
suppressed?: boolean;
event_timestamp?: number;
value?: number;
values?: {
[metric: string]: number;
};
Expand Down
Loading

0 comments on commit 1017cee

Please sign in to comment.