Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix table filter builder that partially works #2001

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/studio/src/components/CoreTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
:tab="tab"
:active="activeTab === tab"
:connection="connection"
:initial-filters="tab.getFilters()"
:table="slotProps.table"
/>
</template>
Expand Down Expand Up @@ -788,8 +787,12 @@ export default Vue.extend({
tab.setFilters(filters)
tab.titleScope = "all"
const existing = this.tabItems.find((t) => t.matches(tab))
if (existing) return this.$store.dispatch('tabs/setActive', existing)
this.addTab(tab)
if (existing) {
existing.setFilters(filters)
this.$store.dispatch('tabs/setActive', existing)
} else {
this.addTab(tab)
}
},
openExportModal(options) {
this.tableExportOptions = options
Expand Down
23 changes: 13 additions & 10 deletions apps/studio/src/components/tableview/RowFilterBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const BUILDER = "builder";
const RAW = "raw";

export default Vue.extend({
props: ["columns", "initialFilters"],
props: ["columns", "reactiveFilters"],
data() {
return {
filterTypes: {
Expand All @@ -235,14 +235,7 @@ export default Vue.extend({
"greater than or equal": ">=",
in: "in",
},
filters: this.initialFilters ?? [
{
op: "AND",
field: this.columns[0]?.columnName,
type: "=",
value: "",
},
],
filters: this.reactiveFilters,
filterRaw: "",
filterMode: BUILDER,
RAW,
Expand All @@ -259,7 +252,10 @@ export default Vue.extend({
return {
[this.ctrlOrCmd('f')]: this.focusOnInput,
}
}
},
externalFilters() {
return this.reactiveFilters;
},
},
methods: {
focusOnInput() {
Expand Down Expand Up @@ -335,6 +331,13 @@ export default Vue.extend({
filterRaw() {
if (this.filterRaw === "") this.submit();
},
externalFilters() {
if (platformInfo.isCommunity) {
this.filters = this.externalFilters.slice(0, 2);
} else {
this.filters = this.externalFilters;
}
},
},
});
</script>
19 changes: 16 additions & 3 deletions apps/studio/src/components/tableview/TableTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<row-filter-builder
v-if="table.columns?.length"
:columns="table.columns"
:initial-filters="initialFilters"
:reactive-filters="tableFilters"
@input="handleRowFilterBuilderInput"
@submit="triggerFilter"
/>
Expand Down Expand Up @@ -283,13 +283,18 @@ const log = rawLog.scope('TableTable')

let draftFilters: TableFilter[] | string | null;

function createTableFilter(field: string) {
return { op: "AND", field, type: "=", value: "" }
}

export default Vue.extend({
components: { Statusbar, ColumnFilterModal, TableLength, RowFilterBuilder, EditorModal },
mixins: [data_converter, DataMutators, FkLinkMixin],
props: ["connection", "initialFilters", "active", 'tab', 'table'],
props: ["connection", "active", 'tab', 'table'],
data() {
return {
filters: [],
tableFilters: [createTableFilter(this.table.columns?.[0]?.columnName)],
headerFilter: true,
columnsSet: false,
tabulator: null,
Expand Down Expand Up @@ -688,6 +693,13 @@ export default Vue.extend({
} else {
this.$nextTick(() => this.tabulator.redraw())
}

// If the filters in this.tab have changed, reapply them. We probably
// clicked a foreign key cell from other tab.
if (!_.isEqual(this.tab.getFilters(), this.tableFilters)) {
this.tableFilters = this.tab.getFilters()
this.triggerFilter(this.tableFilters)
}
} else {
this.tabulator.blockRedraw()
}
Expand Down Expand Up @@ -799,7 +811,8 @@ export default Vue.extend({
this.rawTableKeys = await this.connection.getTableKeys(this.table.name, this.table.schema)
const rawPrimaryKeys = await this.connection.getPrimaryKeys(this.table.name, this.table.schema);
this.primaryKeys = rawPrimaryKeys.map((key) => key.columnName);
this.filters = normalizeFilters(this.initialFilters || [])
this.tableFilters = this.tab.getFilters() || [createTableFilter(this.table.columns?.[0]?.columnName)]
this.filters = normalizeFilters(this.tableFilters || [])

this.tabulator = new TabulatorFull(this.$refs.table, {
spreadsheet: true,
Expand Down