Skip to content

Commit

Permalink
mob next [ci-skip] [ci skip] [skip ci]
Browse files Browse the repository at this point in the history
lastFile:frontend/src/stores/useReportStore.ts
  • Loading branch information
augustebaum committed Sep 10, 2024
1 parent f3c2fa5 commit 0b7db29
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 20 deletions.
26 changes: 13 additions & 13 deletions frontend/src/components/DataStoreCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import HtmlSnippetWidget from "@/components/HtmlSnippetWidget.vue";
import ImageWidget from "@/components/ImageWidget.vue";
import MarkdownWidget from "@/components/MarkdownWidget.vue";
import type { KeyLayoutSize, KeyMoveDirection } from "@/models";
import { useReportStore } from "@/stores/reports";
import { useReportStore } from "@/stores/useReportStore";
const reportStore = useReportStore();
// const items = computed(() => {
Expand All @@ -32,15 +32,15 @@ const reportStore = useReportStore();
// });
function onLayoutChange(key: string, size: KeyLayoutSize) {
reportsStore.setKeyLayoutSize(key, size);
reportStore.setKeyLayoutSize(key, size);
}
function onCardRemoved(key: string) {
reportsStore.hideKey(key);
reportStore.hideKey(key);
}
function onPositionChanged(key: string, direction: KeyMoveDirection) {
reportsStore.moveKey(key, direction);
reportStore.moveKey(key, direction);
}
const props = defineProps({
Expand All @@ -56,16 +56,16 @@ const props = defineProps({
<DataStoreCard
v-for="({ item_type, media_type, serialized }, key) in reportStore.report"
:key="key"
:title="key"
:title="key.toString()"
subtitle="FIXME"
:class="'FIXME'"
:showButtons="props.showCardButtons"
:can-move-up="true"
:can-move-down="true"
class="canvas-element"
@layout-changed="onLayoutChange(key, $event)"
@position-changed="onPositionChanged(key, $event)"
@card-removed="onCardRemoved(key)"
@layout-changed="onLayoutChange(key.toString(), $event)"
@position-changed="onPositionChanged(key.toString(), $event)"
@card-removed="onCardRemoved(key.toString())"
>
<DataFrameWidget
v-if="item_type === 'pandas_dataframe'"
Expand All @@ -74,18 +74,18 @@ const props = defineProps({
/>
<ImageWidget
v-if="
item_type === 'media' &&
item_type === 'media' && media_type &&
['image/svg+xml', 'image/png', 'image/jpeg', 'image/webp'].includes(media_type)
"
:mime-type="data['mime-type']"
:base64-src="data.data"
:alt="key"
:mime-type="media_type"
:base64-src="serialized"
:alt="key.toString()"
/>
<ImageWidget
v-if="type === 'matplotlib_figure'"
mime-type="image/svg+xml"
:base64-src="data"
:alt="key"
:alt="key.toString()"
/>
<MarkdownWidget
v-if="
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/DataStoreKey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { computed, ref } from "vue";
import type { IPayloadItemMetadata } from "@/models";
import { useReportStore } from "@/stores/reports";
import { useReportStore } from "@/stores/useReportStore";
import { formatDistance } from "date-fns";
const props = defineProps<{ itemKey: string; metadata?: IPayloadItemMetadata }>();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/DataStoreKeyList.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import DataStoreKey from "@/components/DataStoreKey.vue";
import { useReportStore } from "@/stores/reports";
import { useReportStore } from "@/stores/useReportStore";
const reportsStore = useReportStore();
const props = defineProps<{ icon: string; title: string; keys: string[] }>();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/FileTreeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRouter } from "vue-router";
import { type FileTreeNode } from "@/components/FileTree.vue";
import { ROUTE_NAMES } from "@/router";
import { remap, sha1 } from "@/services/utils";
import { useReportStore } from "@/stores/reports";
import { useReportStore } from "@/stores/useReportStore";
const router = useRouter();
const props = defineProps<FileTreeNode>();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createPinia } from "pinia";
import { createApp } from "vue";

import App from "@/ShareApp.vue";
import { useReportStore } from "@/stores/reports";
import { useReportStore } from "./stores/useReportStore";

export default function share() {
const app = createApp(App);
Expand Down
134 changes: 134 additions & 0 deletions frontend/src/stores/useReportStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { defineStore } from "pinia";
import { ref, shallowRef } from "vue";
import { type KeyLayoutSize, type KeyMoveDirection, type Layout, type Report } from "@/models";
import { fetchReport } from "@/services/api";
import { poll, swapItemsInArray } from "@/services/utils";


export const useReportStore = defineStore("reports", () => {
// this object is not deeply reactive as it may be very large
const report = shallowRef<Report | null>(null);
const layout = ref<Layout>([]);

/**
* Return true if the the given key is in the list of displayed keys, false otherwise.
* @param key the key to look for
*/
function isKeyDisplayed(key: string) {
const visibleKeys = layout.value.map(({ key: k }) => k);
return visibleKeys.includes(key);
}

/**
* Add the value of a key to the report.
* @param key the key to add to the report
*/
async function displayKey(key: string) {
stopBackendPolling();
if (!isKeyDisplayed(key)) {
layout.value.push({ key, size: "large" });
await persistLayout();
}
await startBackendPolling();
}

/**
* Hide the value of a key from the report.
* @param key the key to hide
*/
async function hideKey(key: string) {
stopBackendPolling();
if (isKeyDisplayed(key)) {
layout.value = layout.value.filter(({ key: k }) => key != k);
await persistLayout();
}
await startBackendPolling();
}

/**
* Change the visual size of the value of a key in the report.
* @param key the key which changes
* @param size the target size
*/
async function setKeyLayoutSize(key: string, size: KeyLayoutSize) {
stopBackendPolling();
if (isKeyDisplayed(key)) {
const index = layout.value.findIndex(({ key: k }) => key == k);
if (index !== -1) {
layout.value[index].size = size;
}
await persistLayout();
}
await startBackendPolling();
}

/**
* Move a displayed key up or down in the list
* @param key the key to replace
* @param direction up or down
*/
async function moveKey(key: string, direction: KeyMoveDirection) {
stopBackendPolling();
const offset = direction == "up" ? -1 : 1;
const index = layout.value.findIndex(({ key: k }) => key == k);
swapItemsInArray(layout.value, index, index + offset);
await persistLayout();
await startBackendPolling();
}

/**
* Fetch all reports URI
* and eventually the detail of the currently selected report
*/
let _isCanceledCall = false;
async function fetch() {
if (!_isCanceledCall) {

const newReport = await fetchReport();
report.value = newReport;
}
}
/**
* Start real time sync with the server.
*/
let _stopBackendPolling: Function | null = null;
async function startBackendPolling() {
_isCanceledCall = false;
_stopBackendPolling = await poll(fetch, 1500);
}

/**
* Stop real time sync with the server.
*/
function stopBackendPolling() {
_isCanceledCall = true;
_stopBackendPolling && _stopBackendPolling();
}

/**
* Send new layout to backend
*/
async function persistLayout() {
if (report.value && layout.value) {
// FIXME p
//const report = await putLayout(report.value.uri, layout.value);
}
}

function setReport(r: Report) {
report.value = r;
// FIXME setup layout
}

return {
layout,
report,
displayKey,
hideKey,
setKeyLayoutSize,
startBackendPolling,
stopBackendPolling,
setReport,
moveKey,
};
});
2 changes: 1 addition & 1 deletion frontend/src/views/ReportBuilderView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DataStoreCanvas from "@/components/DataStoreCanvas.vue";
import DataStoreKeyList from "@/components/DataStoreKeyList.vue";
import SectionHeader from "@/components/SectionHeader.vue";
import SimpleButton from "@/components/SimpleButton.vue";
import { useReportStore } from "@/stores/reports";
import { useReportStore } from "@/stores/useReportStore";
const reportStore = useReportStore();
const isDropIndicatorVisible = ref(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/stores/reports.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ItemType, type KeyLayoutSize } from "@/models";
import { fetchAllManderUris, fetchMander, putLayout } from "@/services/api";
import { useReportStore } from "@/stores/reports";
import { useReportStore } from "@/stores/useReportStore";
import { createTestingPinia } from "@pinia/testing";
import { setActivePinia } from "pinia";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
Expand Down
Binary file added project/cache.db
Binary file not shown.
Binary file added project/cache.db-shm
Binary file not shown.
Binary file added project/cache.db-wal
Binary file not shown.
2 changes: 1 addition & 1 deletion src/skore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def cli(args: list[str]):
"directory",
nargs="?",
help="the directory to open (default: %(default)s)",
default="project",
default="project.skore",
)
parser_launch.add_argument(
"--port",
Expand Down

0 comments on commit 0b7db29

Please sign in to comment.