Skip to content

Commit

Permalink
align multiview HistoryPanel details header based on content
Browse files Browse the repository at this point in the history
Adds a `pinnedHistoriesSummarizedStatus` computed ref to `historyStore` that Returns a string that indicates whether all the pinned histories have annotations, tags, both, or none of them. This is used to then adjust the `DetailsLayout` header height accordingly.
  • Loading branch information
ahmedhamidawan committed May 29, 2024
1 parent 32868aa commit f9e475e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import UtcDate from "@/components/UtcDate.vue";
interface Props {
history: HistorySummary;
writeable: boolean;
summarized: boolean;
summarized?: "both" | "annotation" | "tags" | "none";
}
const props = withDefaults(defineProps<Props>(), {
writeable: true,
summarized: false,
summarized: undefined,
});
const historyStore = useHistoryStore();
Expand Down
8 changes: 6 additions & 2 deletions client/src/components/History/CurrentHistory/HistoryPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const contentItemRefs = computed(() => {
const currItemFocused = useActiveElement();
const lastItemId = ref<string | null>(null);
const { currentFilterText, currentHistoryId } = storeToRefs(useHistoryStore());
const { currentFilterText, currentHistoryId, pinnedHistoriesSummarizedStatus } = storeToRefs(useHistoryStore());
const { lastCheckedTime, totalMatchesCount, isWatching } = storeToRefs(useHistoryItemsStore());
const historyStore = useHistoryStore();
Expand Down Expand Up @@ -136,6 +136,10 @@ const formattedSearchError = computed(() => {
};
});
const detailsSummarized = computed(() => {
return props.isMultiViewItem ? pinnedHistoriesSummarizedStatus.value : undefined;
});
const storeFilterText = computed(() => {
if (props.history.id !== currentHistoryId.value) {
return "";
Expand Down Expand Up @@ -532,7 +536,7 @@ function setItemDragstart(
<HistoryDetails
:history="history"
:writeable="canEditHistory"
:summarized="isMultiViewItem"
:summarized="detailsSummarized"
@update:history="historyStore.updateHistory($event)" />

<HistoryMessages :history="history" />
Expand Down
35 changes: 25 additions & 10 deletions client/src/components/History/Layout/DetailsLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface Props {
writeable?: boolean;
annotation?: string;
showAnnotation?: boolean;
summarized?: boolean;
summarized?: "both" | "annotation" | "tags" | "none";
}
const props = withDefaults(defineProps<Props>(), {
Expand All @@ -29,7 +29,7 @@ const props = withDefaults(defineProps<Props>(), {
writeable: true,
annotation: undefined,
showAnnotation: true,
summarized: false,
summarized: undefined,
});
const emit = defineEmits(["save"]);
Expand All @@ -47,6 +47,20 @@ const localProps = ref<{ name: string; annotation: string | null; tags: string[]
tags: [],
});
const detailsClass = computed(() => {
const classes: Record<string, boolean> = {
details: true,
"summarized-details": props.summarized && !editing.value,
"m-3": !props.summarized || editing.value,
};
if (props.summarized) {
classes[props.summarized] = true;
}
return classes;
});
const editButtonTitle = computed(() => {
if (isAnonymous.value) {
return l("Log in to Rename History");
Expand Down Expand Up @@ -90,10 +104,7 @@ function selectText() {
</script>

<template>
<section
class="details"
:class="summarized && !editing ? 'summarized-details' : 'm-3'"
data-description="edit details">
<section :class="detailsClass" data-description="edit details">
<BButton
:disabled="isAnonymous || !writeable"
class="edit-button ml-1 float-right"
Expand All @@ -114,7 +125,7 @@ function selectText() {
v-short="annotation"
class="mt-2"
data-description="annotation value" />
<div v-else-if="summarized" style="min-height: 2rem">
<div v-else-if="summarized" :class="{ annotation: ['both', 'annotation'].includes(summarized) }">
<TextSummary
v-if="annotation"
:description="annotation"
Expand All @@ -124,8 +135,7 @@ function selectText() {
</div>
<StatelessTags
v-if="tags"
class="tags"
:class="!summarized && 'mt-2'"
:class="{ 'mt-2': !summarized, tags: ['both', 'tags'].includes(summarized) }"
:value="tags"
disabled
:max-visible-tags="summarized ? 1 : 5" />
Expand Down Expand Up @@ -184,12 +194,17 @@ function selectText() {

<style lang="scss" scoped>
.summarized-details {
min-height: 8.5em;
margin: 1rem 1rem 0 1rem;
max-width: 15rem;
&.both {
min-height: 8.5em;
}
.tags {
min-height: 2rem;
}
.annotation {
min-height: 2rem;
}
}
</style>
37 changes: 37 additions & 0 deletions client/src/stores/historyStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,38 @@ export const useHistoryStore = defineStore("historyStore", () => {
};
});

const pinnedHistoriesSummarizedStatus = computed(() => {
let annotation = false;
let tags = false;
let loaded = true;

for (const h of pinnedHistories.value) {
const history = storedHistories.value[h.id];
if (!history) {
loaded = false;
break;
}

if (history.annotation) {
annotation = true;
}

if (history.tags.length > 0) {
tags = true;
}
}

if (!loaded || (annotation && tags)) {
return "both";
} else if (annotation) {
return "annotation";
} else if (tags) {
return "tags";
} else {
return "none";
}
});

async function setCurrentHistory(historyId: string) {
const currentHistory = (await setCurrentHistoryOnServer(historyId)) as HistoryDevDetailed;
selectHistory(currentHistory);
Expand Down Expand Up @@ -331,6 +363,11 @@ export const useHistoryStore = defineStore("historyStore", () => {
currentHistoryId,
currentFilterText,
pinnedHistories,
/** Returns a string that indicates whether all the pinned histories have annotations,
* tags, both, or none of them.
* This is used to format the `DetailsLayout` header uniformly for multi-view histories.
*/
pinnedHistoriesSummarizedStatus,
getHistoryById,
getHistoryNameById,
setCurrentHistory,
Expand Down

0 comments on commit f9e475e

Please sign in to comment.