Skip to content

Commit

Permalink
Merge branch 'release-2024-fall' into epic/FOUR-18012
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjacornelius committed Oct 9, 2024
2 parents 334408e + 0ee7dcb commit b6a207e
Show file tree
Hide file tree
Showing 19 changed files with 1,285 additions and 93 deletions.
43 changes: 42 additions & 1 deletion src/DataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export default {
if (authParams) {
query = `?${new URLSearchParams(authParams).toString()}`;
}

return query;
},

Expand Down Expand Up @@ -296,5 +295,47 @@ export default {
}
throw error;
});
},

getCollectionRecordsList(collectionId, options = null) {

return this.get(
`/collections/${collectionId}/records${this.authQueryString()}`,
options
)
.then((response) => {
const data = response ? response.data : null;
if (!data) {
throw new Error(i18next.t("No data returned"));
}
return data;
})
.catch((error) => {
if (error.response && error.response.status === 404) {
const data = { data: [] };
return [data];
}
throw error;
});
},

getCollectionRecordsView(collectionId, recordId) {
return this.get(
`/collections/${collectionId}/records/${recordId}`
)
.then((response) => {
const data = response ? response.data : null;
if (!data) {
throw new Error(i18next.t("No data returned"));
}
return data;
})
.catch((error) => {
if (error.response && error.response.status === 404) {
const data = { data: [] };
return data;
}
throw error;
});
}
};
7 changes: 6 additions & 1 deletion src/components/accordions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export default [
'initiallyChecked',
'screen',
'multipleUpload',
'linkUrl'
'linkUrl',
'collection',
'record',
'collectionmode',
'submitCollectionCheck',
],
open: true,
},
Expand Down Expand Up @@ -47,6 +51,7 @@ export default [
},
fields: [
'fields',
'paginationOption',
{ name: 'options', hideFor: 'FormMultiColumn' },
],
open: false,
Expand Down
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import accordions from "@/components/accordions";
import VariableNameGenerator from "@/components/VariableNameGenerator";
import { LinkButton } from "./renderer";
import "../assets/css/tabs.css";
import FormCollectionRecordControl from "./renderer/form-collection-record-control.vue";

const rendererComponents = {
...renderer,
Expand Down Expand Up @@ -163,6 +164,7 @@ export default {
Vue.use(Vuex);
Vue.component("FormListTable", FormListTable);
Vue.component("LinkButton", LinkButton);
Vue.component("FormCollectionRecordControl", FormCollectionRecordControl);
const store = new Vuex.Store({
modules: {
globalErrorsModule,
Expand Down
200 changes: 200 additions & 0 deletions src/components/inspector/collection-data-source.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<template>
<div>
<div>
<label for="collectionsource">{{ $t("Source of Record List") }}</label>
<b-form-select
id="collectionsource"
v-model="sourceOptions"
:options="sourceDisplayOptions"
data-cy="inspector-collection-data-source"
@change="displayOptionChange"
/>
<small class="mt-3 form-text text-muted">{{
$t("A record list can display the data of a defined variable or a collection")
}}</small>
</div>
<div class="mt-2" v-if="sourceOptions === 'Collection'">

<CollectionRecordsList
v-model="collectionFields"
:record-pmql="pmql"
@change="collectionChanged"/>

<pmql-input
v-model="pmql"
:search-type="'collections_w_mustaches'"
class="mt-3 mb-1"
data-cy="inspector-collection-pmql"
:input-label="'PMQL'"
:condensed="true"
:ai-enabled="true"
:placeholder="$t('PMQL')"
>
</pmql-input>
<small class="mt-3 form-text text-muted">{{
$t("Leave this field empty to show all the records of the collection")
}}</small>
<label class="mt-3" id="data-selection">{{ $t("Data Selection") }}</label>

<b-form-select
id="data-selection"
v-model="dataSelectionOptions"
:options="dataSelectionDisplayOptions"
data-cy="inspector-collection-data-selection"
/>
<small class="mt-3 form-text text-muted">{{
$t("The user can select specific data to be stored into a variable")
}}</small>

<div class="mt-3" v-if="dataSelectionOptions === 'single-field'">
<label id="single-columns">{{ $t('Column') }}</label>
<b-form-select
id="single-columns"
v-model="singleField"
:options="singleFieldOptions"
data-cy="inspector-collection-single-field"
>
<option disabled value="">{{ $t("Select a column") }}</option>
</b-form-select>
</div>
</div>
</div>
</template>
<script>
import CollectionRecordsList from "./collection-records-list.vue"
import { cloneDeep } from "lodash";
const CONFIG_FIELDS = [
"collectionFields",
"collectionFieldsColumns",
"pmql",
"sourceOptions",
"variableStore",
"dataSelectionOptions",
"singleField"
];
export default {
components: {
CollectionRecordsList
},
props: ["value", "screenType"],
data() {
return {
fields: [],
sourceOptions: "Variable",
submitCollectionCheck: true,
sourceDisplayOptions: [],
collectionFields: [],
collectionFieldsColumns: [],
variableStore: null,
pmql: null,
sourceDisplayOptions: [
{
text: this.$t('Variable'),
value: 'Variable',
},
{
text: this.$t('Collection'),
value: 'Collection',
},
],
dataSelectionDisplayOptions: [
{
text: this.$t('Do not allow selection'),
value: 'no-selection',
},
{
text: this.$t('Single field of record'),
value: 'single-field',
},
{
text: this.$t('Single record'),
value: 'single-record',
},
{
text: this.$t('Multiple records'),
value: 'multiple-records',
},
],
dataSelectionOptions: "no-selection",
collectionColumns: [],
singleFieldOptions: [],
singleField: null
};
},
methods: {
displayOptionChange() {
this.collectionFields = [];
this.collectionFieldsColumns = [];
this.pmql = null;
this.$root.$emit("collection-changed", true);
},
collectionChanged(data) {
if (Array.isArray(data)) {
const [firstItem] = data;
const collectionId = firstItem?.collection_id;
if(collectionId !== this.collectionFields.collectionId) {
this.$root.$emit("collection-changed", true);
}
}
},
getCollectionColumns(records) {
const [firstRecord] = records?.dataRecordList || [];
if (firstRecord?.data) {
const dataObject = firstRecord.data;
for (const [key, value] of Object.entries(dataObject)) {
this.singleFieldOptions.push({ text: key, value: key });
}
}
},
},
computed: {
options() {
return Object.fromEntries(
CONFIG_FIELDS.map((field) => [field, this[field]])
);
}
},
watch: {
value: {
handler(value) {
if (!value) {
return;
}
CONFIG_FIELDS.forEach((field) => (this[field] = value[field]));
},
immediate: true
},
sourceOptions: {
handler(changeOption) {
this.$root.$emit("record-list-option", changeOption);
}
},
collectionFields: {
handler(collectionFieldsData) {
this.getCollectionColumns(collectionFieldsData);
this.$root.$emit("record-list-collection", collectionFieldsData);
},
deep: true
},
pmql: {
handler(newPmql) {
this.$root.$emit("change-pmql", newPmql);
}
},
submitCollectionCheck(newValue) {
this.submitCollectionCheck = newValue;
},
options: {
handler() {
this.$emit("input", this.options);
},
deep: true
},
},
};
</script>
87 changes: 87 additions & 0 deletions src/components/inspector/collection-display-mode.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<template>
<div>
<div>
<label for="collectionmode">{{ $t("Mode") }}</label>
<b-form-select
id="collectionmode"
v-model="modeId"
:options="displayOptions"
data-cy="inspector-collection"
/>
</div>
<div class="mt-2" v-if="modeId !== 'View'">
<b-form-checkbox v-model="submitCollectionCheck">
{{ $t("Update collection on submit") }}
</b-form-checkbox>
</div>
</div>
</template>

<script>
import ScreenVariableSelector from "../screen-variable-selector.vue";
const CONFIG_FIELDS = ["modeId", "submitCollectionCheck"];
export default {
components: {
ScreenVariableSelector
},
props: ["value", "screenType"],
data() {
return {
fields: [],
modeId: null,
submitCollectionCheck: true,
displayOptions: []
};
},
mounted() {
this.getFields();
},
computed: {
options() {
return Object.fromEntries(
CONFIG_FIELDS.map((field) => [field, this[field]])
);
}
},
watch: {
value: {
handler(value) {
if (!value) {
return;
}
CONFIG_FIELDS.forEach((field) => (this[field] = value[field]));
},
immediate: true
},
modeId: {
handler() {
this.getFields();
}
},
submitCollectionCheck(newValue) {
this.submitCollectionCheck = newValue;
},
screenType: {
handler() {
this.getFields();
},
immediate: true
},
options: {
handler() {
this.$emit("input", this.options);
},
deep: true
}
},
methods: {
getFields() {
this.displayOptions = [
{ value: "Edit", text: "Edit" },
{ value: "View", text: "View" }
];
}
}
};
</script>
Loading

0 comments on commit b6a207e

Please sign in to comment.