Skip to content

Commit

Permalink
Merge pull request #18343 from davelopez/24.1_fix_visualizations_data…
Browse files Browse the repository at this point in the history
…set_filtering

[24.1] Fix visualizations compatible dataset filtering
  • Loading branch information
jdavcs authored Jun 7, 2024
2 parents d0f01af + 3aea494 commit bf60526
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
6 changes: 6 additions & 0 deletions client/src/components/DataDialog/DataDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface Props {
allowUpload?: boolean;
callback?: (results: Array<Record>) => void;
filterOkState?: boolean;
filterByTypeIds?: string[];
format?: string;
library?: boolean;
modalStatic?: boolean;
Expand All @@ -36,6 +37,7 @@ const props = withDefaults(defineProps<Props>(), {
allowUpload: true,
callback: () => {},
filterOkState: false,
filterByTypeIds: undefined,
format: "download",
library: true,
modalStatic: false,
Expand Down Expand Up @@ -96,6 +98,9 @@ function getHistoryUrl() {
if (props.filterOkState) {
queryString += "&q=state-eq&qv=ok";
}
if (props.filterByTypeIds && props.filterByTypeIds.length > 0) {
queryString += `&q=type_id-in&qv=${props.filterByTypeIds.join(",")}`;
}
return `${getAppRoot()}api/histories/${props.history}/contents?v=dev${queryString}`;
}
Expand Down Expand Up @@ -192,6 +197,7 @@ watch(
:disable-ok="!hasValue"
:fields="fields"
:items="items"
:total-items="items.length"
:modal-show="modalShow"
:multiple="multiple"
:options-show="optionsShow"
Expand Down
42 changes: 41 additions & 1 deletion client/src/components/Panels/VisualizationPanel.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { faEye } from "@fortawesome/free-solid-svg-icons";
import { BAlert, BModal } from "bootstrap-vue";
import { storeToRefs } from "pinia";
import { computed, onMounted, type Ref, ref } from "vue";
import { useRouter } from "vue-router/composables";
Expand All @@ -22,14 +23,25 @@ interface Plugin {
target?: string;
}
interface Dataset {
id: string;
name: string;
}
interface CompatibleDatasetsResponse {
hdas: Dataset[];
}
const { currentHistoryId } = storeToRefs(useHistoryStore());
const router = useRouter();
const plugins: Ref<Array<Plugin>> = ref([]);
const query = ref("");
const isLoading = ref(true);
const currentPlugin: Ref<Plugin | null> = ref(null);
const compatibleDatasetIdKeys = ref<string[]>([]);
const showDataDialog = ref(false);
const showNoCompatibleDatasetsModal = ref(false);
const filteredPlugins = computed(() => {
const queryLower = query.value.toLowerCase();
Expand All @@ -51,11 +63,31 @@ function createVisualization(dataset: any) {
}
}
function selectVisualization(plugin: Plugin) {
async function selectVisualization(plugin: Plugin) {
currentPlugin.value = plugin;
compatibleDatasetIdKeys.value = await getCompatibleDatasetsInCurrentHistory();
if (compatibleDatasetIdKeys.value.length === 0) {
showNoCompatibleDatasetsModal.value = true;
return;
}
showDataDialog.value = true;
}
/**
* Get compatible datasets in the current history for the selected visualization.
* @returns {Promise<string[]>} List of compatible datasets as "type-id" strings. In this case, type will be always "dataset".
*/
async function getCompatibleDatasetsInCurrentHistory(): Promise<string[]> {
if (!currentPlugin.value || !currentHistoryId.value) {
return [];
}
const result = (await urlData({
url: `/api/plugins/${currentPlugin.value.name}`,
params: { history_id: currentHistoryId.value },
})) as CompatibleDatasetsResponse;
return result.hdas.map((dataset: Dataset) => `dataset-${dataset.id}`);
}
async function getPlugins() {
plugins.value = await urlData({ url: "/api/plugins" });
isLoading.value = false;
Expand Down Expand Up @@ -97,8 +129,16 @@ onMounted(() => {
format=""
:history="currentHistoryId"
:filter-ok-state="true"
:filter-by-type-ids="compatibleDatasetIdKeys"
@onOk="createVisualization"
@onCancel="showDataDialog = false" />
<BModal v-model="showNoCompatibleDatasetsModal" title="No compatible datasets found" title-tag="h2" ok-only>
<p v-localize>
No datasets found in your current history that are compatible with
<b>{{ currentPlugin?.name ?? "this visualization" }}</b
>. Please upload a compatible dataset or select a different visualization.
</p>
</BModal>
</ActivityPanel>
</template>

Expand Down
2 changes: 1 addition & 1 deletion config/plugins/visualizations/editor/config/editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<data_sources>
<data_source>
<model_class>HistoryDatasetAssociation</model_class>
<test type="isinstance" test_attr="datatype" result_type="datatype">data.Data</test>
<test type="isinstance" test_attr="datatype" result_type="datatype">data.Text</test>
<to_param param_attr="id">dataset_id</to_param>
</data_source>
</data_sources>
Expand Down

0 comments on commit bf60526

Please sign in to comment.