Skip to content

Commit

Permalink
feat: the hardwareDetails endpoint only need a limit time
Browse files Browse the repository at this point in the history
- The endpoint just need to use a limit time, there is no need
to use a start time
  • Loading branch information
lfjnascimento committed Nov 27, 2024
1 parent 0abd22d commit 0a07989
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 34 deletions.
20 changes: 6 additions & 14 deletions backend/kernelCI_app/views/hardwareDetailsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def sanitize_records(self, records, selected_trees, filters):

return (builds, tests, boots)

def get_trees(self, hardware_id, origin, start_datetime, end_datetime):
def get_trees(self, hardware_id, origin, limit_datetime):
tree_id_fields = [
"build__checkout__tree_name",
"build__checkout__git_repository_branch",
Expand All @@ -253,8 +253,7 @@ def get_trees(self, hardware_id, origin, start_datetime, end_datetime):
trees_query_set = Tests.objects.filter(
environment_compatible__contains=[hardware_id],
origin=origin,
build__checkout__start_time__gte=start_datetime,
build__checkout__start_time__lte=end_datetime,
build__checkout__start_time__lte=limit_datetime,
).values(
*tree_id_fields,
"build__checkout__git_commit_name",
Expand Down Expand Up @@ -342,17 +341,12 @@ def get_records(self, *, hardware_id, origin, trees):

# Using post to receive a body request
def post(self, request, hardware_id):

try:
body = json.loads(request.body)

origin = body.get("origin", DEFAULT_ORIGIN)
start_datetime = datetime.fromtimestamp(
int(body.get('startTimestampInSeconds')),
timezone.utc
)
end_datetime = datetime.fromtimestamp(
int(body.get('endTimestampInSeconds')),
limit_datetime = datetime.fromtimestamp(
int(body.get('limitTimestampInSeconds')),
timezone.utc
)
filters = body.get("filter", {})
Expand All @@ -364,12 +358,10 @@ def post(self, request, hardware_id):
)
except (ValueError, TypeError):
return HttpResponseBadRequest(
getErrorResponseBody(
"startTimestampInSeconds and endTimestampInSeconds must be a Unix Timestamp"
)
getErrorResponseBody("limitTimestampInSeconds must be a Unix Timestamp")
)

trees = self.get_trees(hardware_id, origin, start_datetime, end_datetime)
trees = self.get_trees(hardware_id, origin, limit_datetime)
selected_trees = self.get_selected_trees(trees, body.get('selectedTrees', {}))

params = {
Expand Down
3 changes: 1 addition & 2 deletions backend/requests/hardware-details-post.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Content-Type:application/json \
"1": "selected"
},
"origin": "maestro",
"startTimestampInSeconds": 1731275753,
"endTimestampInSeconds": 1731448553
"limitTimestampInSeconds": 1731448553
}'

9 changes: 3 additions & 6 deletions dashboard/src/api/hardwareDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import type { TOrigins } from '@/types/general';
import http from './api';

type fetchHardwareDetailsBody = {
startTimestampInSeconds: number;
endTimestampInSeconds: number;
limitTimestampInSeconds: number;
origin: TOrigins;
selectedTrees: Record<string, string>;
filter?: Record<string, string[]>;
Expand Down Expand Up @@ -67,8 +66,7 @@ const mapIndexesToSelectedTrees = (

export const useHardwareDetails = (
hardwareId: string,
startTimestampInSeconds: number,
endTimestampInSeconds: number,
limitTimestampInSeconds: number,
origin: TOrigins,
filter: { [key: string]: string[] },
selectedIndexes: number[],
Expand All @@ -80,8 +78,7 @@ export const useHardwareDetails = (

const body: fetchHardwareDetailsBody = {
origin,
startTimestampInSeconds,
endTimestampInSeconds,
limitTimestampInSeconds,
selectedTrees,
filter: filtersFormatted,
};
Expand Down
1 change: 0 additions & 1 deletion dashboard/src/pages/Hardware/HardwareListingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const HardwareListingPage = ({
<div className="flex flex-col gap-6">
<HardwareTable
treeTableRows={listItems}
startTimestampInSeconds={startTimestampInSeconds}
endTimestampInSeconds={endTimestampInSeconds}
/>
</div>
Expand Down
7 changes: 2 additions & 5 deletions dashboard/src/pages/Hardware/HardwareTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,11 @@ const columns: ColumnDef<HardwareTableItem>[] = [

interface ITreeTable {
treeTableRows: HardwareTableItem[];
startTimestampInSeconds: number;
endTimestampInSeconds: number;
}

export function HardwareTable({
treeTableRows,
startTimestampInSeconds,
endTimestampInSeconds,
}: ITreeTable): JSX.Element {
const [sorting, setSorting] = useState<SortingState>([]);
Expand All @@ -163,12 +161,11 @@ export function HardwareTable({
params: { hardwareId: row.original.hardwareName },
search: previousSearch => ({
...previousSearch,
startTimestampInSeconds,
endTimestampInSeconds,
limitTimestampInSeconds: endTimestampInSeconds,
}),
};
},
[endTimestampInSeconds, startTimestampInSeconds],
[endTimestampInSeconds],
);

const data = useMemo(() => {
Expand Down
6 changes: 2 additions & 4 deletions dashboard/src/pages/hardwareDetails/HardwareDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ function HardwareDetails(): JSX.Element {
const {
treeIndexes,
treeCommits,
startTimestampInSeconds,
endTimestampInSeconds,
limitTimestampInSeconds,
diffFilter,
origin,
} = useSearch({ from: '/hardware/$hardwareId' });
Expand All @@ -69,8 +68,7 @@ function HardwareDetails(): JSX.Element {

const { data, isLoading } = useHardwareDetails(
hardwareId,
startTimestampInSeconds,
endTimestampInSeconds,
limitTimestampInSeconds,
origin,
reqFilter,
treeIndexes ?? [],
Expand Down
3 changes: 1 addition & 2 deletions dashboard/src/routes/hardware/$hardwareId/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const hardwareDetailsSearchSchema = z.object({
treeIndexes: z.array(z.number().int()).optional(),
treeCommits: zTreeCommits,
tableFilter: zTableFilterInfoValidator,
startTimestampInSeconds: z.number(),
endTimestampInSeconds: z.number(),
limitTimestampInSeconds: z.number(),
diffFilter: zDiffFilter,
});

Expand Down

0 comments on commit 0a07989

Please sign in to comment.