Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass start and end times to TimeDropdown #1139

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion dashboard/src/components/TimeDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const options: option[] = [

const props = defineProps<{
name: string;
label: string;
label?: string;
start?: Date;
end?: Date;
}>();

const el = ref<HTMLElement | null>(null);
Expand All @@ -41,6 +43,14 @@ const endTime = ref<Date | null>(null);

onMounted(() => {
if (el.value) dropdown.value = new Dropdown(el.value);
if (props.start) {
startTime.value = props.start;
btnLabel.value = defaultLabel + ": Custom";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but this could be misleading if the date comes from a preset value. The times will change for those preset values so it kind of makes sense to make it custom if you want to keep the exact time that was used at the time of filtering, although the end date will vary as it's never set in those presets.

I think it would make more sense to have the preset ranges as part of the dashboard URL createdAtRange=3h and then transform them before they are sent to the API to be able to keep showing the last 3 hour SIPs.

Just a note, maybe for the future if we think it deserves the effort, not saying we should change it now as it will require modifying the actual implementation quite a bit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good points @jraddaoui. I don't know if Enduro users will want to have URLs that represent a constant time span (in which case we'd need to set the end time as you've mentioned) or would prefer for the URL to always represent the 3 hours before the current time. 🤔

As you say, I think this is something we can address in the future based on user feedback.

}
if (props.end) {
endTime.value = props.end;
btnLabel.value = defaultLabel + ": Custom";
}
});

watch(selectedPreset, async (newValue) => {
Expand Down
25 changes: 24 additions & 1 deletion dashboard/src/components/__tests__/TimeDropdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flushPromises, mount } from "@vue/test-utils";
import { mount } from "@vue/test-utils";
import VueDatePicker from "@vuepic/vue-datepicker";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

Expand Down Expand Up @@ -90,3 +90,26 @@ describe("TimeDropdown.vue", () => {
]);
});
});

describe("TimeDropdown.vue initialized with start and end times", () => {
it("initializes with correct default values", async () => {
const wrapper = mount(TimeDropdown, {
props: {
name: "createdAt",
label: "Started",
start: new Date("2025-01-01T00:00:00Z"),
end: new Date("2025-01-31T23:59:59Z"),
},
});
await wrapper.vm.$nextTick();

expect(wrapper.find(".dropdown-toggle").text()).toBe("Started: Custom");

const start = wrapper.find("#tdd-createdAt-start input");
const end = wrapper.find("#tdd-createdAt-end input");

// Local times are offset -6 hours from UTC times.
expect(start.element.getAttribute("value")).toEqual("12/31/2024, 18:00");
expect(end.element.getAttribute("value")).toEqual("01/31/2025, 17:59");
});
});
2 changes: 2 additions & 0 deletions dashboard/src/pages/packages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ watch(
<TimeDropdown
name="createdAt"
label="Started"
:start="packageStore.filters.earliestCreatedTime"
:end="packageStore.filters.latestCreatedTime"
@change="
(
name: string,
Expand Down
Loading