Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: consolidate TimeRange components and improve responsive layout (#19566)

boojack310e018ea10c
diff --git a/frontend/src/components/AdvancedSearch/AdvancedSearch.vue b/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
index 11a95de3f2..a937ce23bc 100644
--- a/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
+++ b/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
@@ -1,5 +1,5 @@
<template>
- <div ref="containerRef" class="w-full relative">
+ <div ref="containerRef" class="w-full min-w-0 relative">
<NInput
ref="inputRef"
v-bind="$attrs"
@@ -16,7 +16,7 @@
>
<div class="flex items-center gap-x-2">
<FilterIcon class="w-4 h-4 text-control-placeholder" />
- <span class="textinfolabel">
+ <span v-if="isMdOrAbove" class="textinfolabel">
{{ $t("issue.advanced-search.filter") }}
</span>
</div>
@@ -89,6 +89,7 @@ import scrollIntoView from "scroll-into-view-if-needed";
import { zindexable as vZindexable } from "vdirs";
import { computed, nextTick, onMounted, reactive, ref, watch } from "vue";
import { useRouter } from "vue-router";
+import { useWideScreen } from "@/composables/useWideScreen";
import { useCurrentUserV1 } from "@/store";
import { DEBOUNCE_SEARCH_DELAY } from "@/types";
import type { SearchParams, SearchScope, SearchScopeId } from "@/utils";
@@ -150,6 +151,7 @@ interface LocalState {
const router = useRouter();
const me = useCurrentUserV1();
+const isMdOrAbove = useWideScreen();
const cachedQuery = useDynamicLocalStorage<string>(
computed(() =>
diff --git a/frontend/src/components/AdvancedSearch/TimeRange.vue b/frontend/src/components/AdvancedSearch/TimeRange.vue
index 699c6507f4..f9d293d043 100644
--- a/frontend/src/components/AdvancedSearch/TimeRange.vue
+++ b/frontend/src/components/AdvancedSearch/TimeRange.vue
@@ -1,55 +1,91 @@
<template>
<NDatePicker
+ v-if="isMdOrAbove"
:key="timeRange ? 'filled' : 'empty'"
:value="timeRange"
:is-date-disabled="isDateDisabled"
type="datetimerange"
clearable
- class="time-range-picker"
- @update:value="handleUpdate"
+ class="time-range-picker min-w-0"
+ @update:value="emitUpdate"
+ />
+ <NPopover
+ v-else
+ trigger="click"
+ placement="bottom-end"
+ :show="showPopover"
+ @update:show="showPopover = $event"
>
- </NDatePicker>
+ <template #trigger>
+ <NButton quaternary size="small" :type="timeRange ? 'primary' : 'default'">
+ <template #icon>
+ <CalendarIcon class="w-4 h-4" />
+ </template>
+ </NButton>
+ </template>
+ <NDatePicker
+ :key="timeRange ? 'filled-sm' : 'empty-sm'"
+ :value="timeRange"
+ :is-date-disabled="isDateDisabled"
+ type="datetimerange"
+ clearable
+ panel
+ @update:value="handleSmallScreenUpdate"
+ />
+ </NPopover>
</template>
<script setup lang="ts">
import dayjs from "dayjs";
-import { NDatePicker } from "naive-ui";
-import { computed } from "vue";
+import { CalendarIcon } from "lucide-vue-next";
+import { NButton, NDatePicker, NPopover } from "naive-ui";
+import { computed, ref } from "vue";
+import { useWideScreen } from "@/composables/useWideScreen";
import type { SearchParams } from "@/utils";
import { getTsRangeFromSearchParams, upsertScope } from "@/utils";
-const props = defineProps<{
- params: SearchParams;
-}>();
+const props = withDefaults(
+ defineProps<{
+ params: SearchParams;
+ scope?: "created" | "updated";
+ }>(),
+ {
+ scope: "created",
+ }
+);
const emit = defineEmits<{
(event: "update:params", params: SearchParams): void;
}>();
+const isMdOrAbove = useWideScreen();
+const showPopover = ref(false);
+
const timeRange = computed(() => {
- return getTsRangeFromSearchParams(props.params, "created");
+ return getTsRangeFromSearchParams(props.params, props.scope);
});
const isDateDisabled = (ts: number) => {
- const today = dayjs().add(1, "day").endOf("day").valueOf();
- if (ts > today) {
- return true;
- }
- return false;
+ return ts > dayjs().add(1, "day").endOf("day").valueOf();
};
-const handleUpdate = (values: [number, number] | null) => {
- const from = values ? dayjs(values[0]) : null;
- const to = values ? dayjs(values[1]) : null;
+const emitUpdate = (values: [number, number] | null) => {
+ const from = values ? dayjs(values[0]).startOf("day") : null;
+ const to = values ? dayjs(values[1]).endOf("day") : null;
const updated = upsertScope({
params: props.params,
scopes: {
- id: "created",
+ id: props.scope,
value: from && to ? `${from.valueOf()},${to.valueOf()}` : "",
},
});
emit("update:params", updated);
};
+
+const handleSmallScreenUpdate = (values: [number, number] | null) => {
+ emitUpdate(values);
+ showPopover.value = false;
+};
</script>
<style lang="postcss" scoped>
diff --git a/frontend/src/components/AdvancedSearch/UpdatedTimeRange.vue b/frontend/src/components/AdvancedSearch/UpdatedTimeRange.vue
deleted file mode 100644
index f78a6eeca2..0000000000
--- a/frontend/src/components/AdvancedSearch/UpdatedTimeRange.vue
+++ /dev/null
@@ -1,60 +0,0 @@
-<template>
- <NDatePicker
- :key="timeRange ? 'filled' : 'empty'"
- :value="timeRange"
- :is-date-disabled="isDateDisabled"
- type="datetimerange"
- clearable
- class="time-range-picker"
- @update:value="handleUpdate"
- >
- </NDatePicker>
-</template>
-
-<script setup lang="ts">
-import dayjs from "dayjs";
-import { NDatePicker } from "naive-ui";
-import { computed } from "vue";
-import type { SearchParams } from "@/utils";
-import { getTsRangeFromSearchParams, upsertScope } from "@/utils";
-
-const props = defineProps<{
- params: SearchParams;
-}>();
-
-const emit = defineEmits<{
- (event: "update:params", params: SearchParams): void;
-}>();
-
-const timeRange = computed(() => {
- return getTsRangeFromSearchParams(props.params, "updated");
-});
-
-const isDateDisabled = (ts: number) => {
- const today = dayjs().add(1, "day").endOf("day").valueOf();
- if (ts > today) {
- return true;
- }
- return false;
-};
-
-const handleUpdate = (values: [number, number] | null) => {
- const from = values ? dayjs(values[0]).startOf("day") : null;
- const to = values ? dayjs(values[1]).endOf("day") : null;
- const updated = upsertScope({
- params: props.params,
- scopes: {
- id: "updated",
- value: from && to ? `${from.valueOf()},${to.valueOf()}` : "",
- },
- });
- emit("update:params", updated);
-};
-</script>
-
-<style lang="postcss" scoped>
-.time-range-picker :deep(.n-input) {
- --n-padding-left: 6px !important;
- --n-padding-right: 6px !important;
-}
-</style>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
index 65eac4e43a..23fa870f91 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
@@ -1,9 +1,8 @@
<template>
<div class="flex flex-col gap-y-2">
- <!-- Advanced Search Bar - Always Visible -->
- <div class="flex flex-row items-center gap-x-2">
+ <div class="flex items-center md:gap-2">
<AdvancedSearch
- class="flex-1"
+ class="flex-1 min-w-0"
:params="params"
:scope-options="scopeOptions"
:default-params="defaultParams"
@@ -11,7 +10,6 @@
/>
<TimeRange
v-if="components.includes('time-range')"
- v-model:show="showTimeRange"
:params="params"
v-bind="componentProps?.['time-range']"
@update:params="$emit('update:params', $event)"
@@ -24,21 +22,16 @@
<slot name="searchbox-suffix" />
</div>
- <slot name="default" />
-
- <!-- Preset Buttons -->
<PresetButtons
v-if="components.includes('presets') && !componentProps?.presets?.hidden"
:params="params"
@update:params="$emit('update:params', $event)"
/>
-
- <slot name="primary" />
</div>
</template>
<script lang="ts" setup>
-import { computed, ref } from "vue";
+import { computed } from "vue";
import AdvancedSearch from "@/components/AdvancedSearch";
import TimeRange from "@/components/AdvancedSearch/TimeRange.vue";
import type { SearchParams, SearchScopeId } from "@/utils";
@@ -53,7 +46,6 @@ const props = withDefaults(
defineProps<{
params: SearchParams;
overrideScopeIdList?: SearchScopeId[];
- autofocus?: boolean;
components?: SearchComponent[];
componentProps?: Partial<Record<SearchComponent, Record<string, unknown>>>;
defaultParams?: SearchParams;
@@ -73,8 +65,6 @@ defineEmits<{
(event: "update:orderBy", value: string): void;
}>();
-const showTimeRange = ref(false);
-
const allowedScopes = computed((): SearchScopeId[] => {
if (props.overrideScopeIdList && props.overrideScopeIdList.length > 0) {
return props.overrideScopeIdList;
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/IssueSortDropdown.vue b/frontend/src/components/IssueV1/components/IssueSearch/IssueSortDropdown.vue
index c1c6cb9f56..2c41bd53f1 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/IssueSortDropdown.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/IssueSortDropdown.vue
@@ -8,6 +8,7 @@
>
<NButton
quaternary
+ :size="isMdOrAbove?'medium':'small'"
:class="
orderBy
? 'text-accent! hover:text-accent'
@@ -18,7 +19,7 @@
<template #icon>
<ArrowUpDownIcon class="w-4 h-4" />
</template>
- {{ $t("issue.sort.sort") }}
+ <span v-if="isMdOrAbove">{{ $t("issue.sort.sort") }}</span>
</NButton>
</NDropdown>
</template>
@@ -29,6 +30,7 @@ import type { DropdownOption } from "naive-ui";
import { NButton, NDropdown } from "naive-ui";
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
+import { useWideScreen } from "@/composables/useWideScreen";
const props = defineProps<{
orderBy: string;
@@ -39,6 +41,7 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
+const isMdOrAbove = useWideScreen();
const showDropdown = ref(false);
const checkIcon = (value: string) => {
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/index.ts b/frontend/src/components/IssueV1/components/IssueSearch/index.ts
index 63c13b52fc..80c736535b 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/index.ts
+++ b/frontend/src/components/IssueV1/components/IssueSearch/index.ts
@@ -1,3 +1 @@
export { default as IssueSearch } from "./IssueSearch.vue";
-export { default as IssueSortDropdown } from "./IssueSortDropdown.vue";
-export { default as PresetButtons } from "./PresetButtons.vue";
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
index 0983ef3d00..ae479b744b 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
+++ b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
@@ -286,20 +286,7 @@ export const useIssueSearchScopeOptions = (
return scopes.filter((scope) => supportOptionIdSet.has(scope.id));
});
- // filteredScopeOptions will filter search options by chosen scope.
- // For example, if users select a specific project, we should only allow them select instances related with this project.
- const filteredScopeOptions = computed((): ScopeOption[] => {
- const clone = fullScopeOptions.value.map((scope) => ({
- ...scope,
- options: scope.options?.map((option) => ({
- ...option,
- })),
- }));
-
- return clone;
- });
-
- return filteredScopeOptions;
+ return fullScopeOptions;
};
const renderSpan = (content: string) => {
diff --git a/frontend/src/components/RolloutV1/components/shared/useWideScreen.ts b/frontend/src/composables/useWideScreen.ts
similarity index 57%
rename from frontend/src/components/RolloutV1/components/shared/useWideScreen.ts
rename to frontend/src/composables/useWideScreen.ts
index 54197ef429..9da0e6270e 100644
--- a/frontend/src/components/RolloutV1/components/shared/useWideScreen.ts
+++ b/frontend/src/composables/useWideScreen.ts
@@ -1,7 +1,8 @@
import { useWindowSize } from "@vueuse/core";
import { computed } from "vue";
+import { TailwindBreakpoints } from "@/utils";
-export const useWideScreen = (breakpoint = 768) => {
+export const useWideScreen = (breakpoint: number = TailwindBreakpoints.md) => {
const { width } = useWindowSize();
return computed(() => width.value >= breakpoint);
};
diff --git a/frontend/src/layouts/IssuesLayout.vue b/frontend/src/layouts/IssuesLayout.vue
index 8e0a5eb01f..6f40dc2054 100644
--- a/frontend/src/layouts/IssuesLayout.vue
+++ b/frontend/src/layouts/IssuesLayout.vue
@@ -18,7 +18,7 @@
<div
id="bb-layout-main"
ref="mainContainerRef"
- class="md:min-w-0 flex-1 overflow-y-auto"
+ class="min-w-0 flex-1 overflow-y-auto"
>
<!-- Start main area-->
<router-view name="content" />
diff --git a/frontend/src/views/project/ProjectRolloutDashboard.vue b/frontend/src/views/project/ProjectRolloutDashboard.vue
index 6a4616d57a..23062de254 100644
--- a/frontend/src/views/project/ProjectRolloutDashboard.vue
+++ b/frontend/src/views/project/ProjectRolloutDashboard.vue
@@ -10,8 +10,9 @@
class="flex-1"
:scope-options="scopeOptions"
/>
- <UpdatedTimeRange
+ <TimeRange
:params="state.params"
+ scope="updated"
@update:params="state.params = $event"
/>
</div>
@@ -38,9 +39,8 @@
<script lang="ts" setup>
import { computed, reactive, ref, watch } from "vue";
import type { ComponentExposed } from "vue-component-type-helpers";
-import AdvancedSearch from "@/components/AdvancedSearch";
+import AdvancedSearch, { TimeRange } from "@/components/AdvancedSearch";
import type { ScopeOption } from "@/components/AdvancedSearch/types";
-import UpdatedTimeRange from "@/components/AdvancedSearch/UpdatedTimeRange.vue";
import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
import { RolloutDataTable } from "@/components/RolloutV1";
import PagedTable from "@/components/v2/Model/PagedTable.vue";