forked from ytgov/internal-data-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from icefoganalytics/issue-70/visualize-tab-l…
…imit-view-not-implemented-as-intended Visualize Tab: Limit View Not Implemented As Intended
- Loading branch information
Showing
62 changed files
with
2,686 additions
and
892 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { WhereOptions } from "sequelize" | ||
import { isEmpty } from "lodash" | ||
|
||
import { DatasetEntryPreview } from "@/models" | ||
import { BaseScopeOptions } from "@/policies/base-policy" | ||
import { DatasetEntryPreviewsPolicy } from "@/policies" | ||
import BaseController from "@/controllers/base-controller" | ||
|
||
export class DatasetEntryPreviewsController extends BaseController { | ||
async index() { | ||
const where = this.query.where as WhereOptions<DatasetEntryPreview> | ||
const filters = this.query.filters as Record<string, unknown> | ||
|
||
const scopes: BaseScopeOptions[] = [] | ||
if (!isEmpty(filters)) { | ||
Object.entries(filters).forEach(([key, value]) => { | ||
scopes.push({ method: [key, value] }) | ||
}) | ||
} | ||
const scopedDatasetEntryPreview = DatasetEntryPreviewsPolicy.applyScope( | ||
scopes, | ||
this.currentUser | ||
) | ||
|
||
const totalCount = await scopedDatasetEntryPreview.count({ where }) | ||
const datasetEntryPreviews = await scopedDatasetEntryPreview.findAll({ | ||
where, | ||
limit: this.pagination.limit, | ||
offset: this.pagination.offset, | ||
}) | ||
|
||
return this.response.json({ datasetEntryPreviews, totalCount }) | ||
} | ||
} | ||
|
||
export default DatasetEntryPreviewsController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...5.16T23.36.54.update-visualization-controls-fields-to-operate-as-preview-modifications.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { DataTypes } from "sequelize" | ||
|
||
import type { Migration } from "@/db/umzug" | ||
|
||
export const up: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.addColumn("visualization_controls", "has_preview", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE visualization_controls | ||
SET has_preview = 0 -- instead of has_search_customizations for security reasons | ||
`) | ||
await queryInterface.removeColumn("visualization_controls", "has_search_customizations") | ||
|
||
await queryInterface.addColumn("visualization_controls", "has_fields_excluded_from_preview", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: true, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE visualization_controls | ||
SET has_fields_excluded_from_preview = 1 -- instead of has_fields_excluded_from_search for security reasons | ||
`) | ||
await queryInterface.removeColumn("visualization_controls", "has_fields_excluded_from_search") | ||
|
||
await queryInterface.addColumn("visualization_controls", "has_preview_row_limit", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: true, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE visualization_controls | ||
SET has_preview_row_limit = 1 -- instead of has_search_row_limits for security reasons | ||
`) | ||
await queryInterface.removeColumn("visualization_controls", "has_search_row_limits") | ||
|
||
await queryInterface.addColumn("visualization_controls", "preview_row_limit", { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
defaultValue: 10, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE visualization_controls | ||
SET preview_row_limit = ISNULL(search_row_limit_maximum, 10) | ||
`) | ||
await queryInterface.removeColumn("visualization_controls", "search_row_limit_maximum") | ||
} | ||
|
||
export const down: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.addColumn("visualization_controls", "search_row_limit_maximum", { | ||
type: DataTypes.INTEGER, | ||
allowNull: true, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE visualization_controls | ||
SET search_row_limit_maximum = preview_row_limit | ||
`) | ||
await queryInterface.removeColumn("visualization_controls", "preview_row_limit") | ||
|
||
await queryInterface.addColumn("visualization_controls", "has_search_row_limits", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE visualization_controls | ||
SET has_search_row_limits = has_preview_row_limit | ||
`) | ||
await queryInterface.removeColumn("visualization_controls", "has_preview_row_limit") | ||
|
||
await queryInterface.addColumn("visualization_controls", "has_search_customizations", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE visualization_controls | ||
SET has_search_customizations = has_preview | ||
`) | ||
await queryInterface.removeColumn("visualization_controls", "has_preview") | ||
|
||
await queryInterface.addColumn("visualization_controls", "has_fields_excluded_from_search", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE visualization_controls | ||
SET has_fields_excluded_from_search = has_fields_excluded_from_preview | ||
`) | ||
await queryInterface.removeColumn("visualization_controls", "has_fields_excluded_from_preview") | ||
} |
29 changes: 29 additions & 0 deletions
29
...2024.05.17T00.15.32.update-dataset-field-exclusion-flag-to-refer-to-preview-not-search.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { DataTypes } from "sequelize" | ||
|
||
import type { Migration } from "@/db/umzug" | ||
|
||
export const up: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.addColumn("dataset_fields", "is_excluded_from_preview", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: true, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE dataset_fields | ||
SET is_excluded_from_preview = 1 -- instead of is_excluded_from_search for security reasons | ||
`) | ||
await queryInterface.removeColumn("dataset_fields", "is_excluded_from_search") | ||
} | ||
|
||
export const down: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.addColumn("dataset_fields", "is_excluded_from_search", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
}) | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE dataset_fields | ||
SET is_excluded_from_search = 0 -- instead of is_excluded_from_preview as conceptually different | ||
`) | ||
await queryInterface.removeColumn("dataset_fields", "is_excluded_from_preview") | ||
} |
63 changes: 63 additions & 0 deletions
63
api/src/db/migrations/2024.05.17T20.38.17.create-dataset-entry-previews-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { DataTypes, Op } from "sequelize" | ||
|
||
import type { Migration } from "@/db/umzug" | ||
import { MssqlSimpleTypes } from "@/db/utils/mssql-simple-types" | ||
|
||
export const up: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.createTable("dataset_entry_previews", { | ||
id: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
allowNull: false, | ||
autoIncrement: true, | ||
}, | ||
dataset_id: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "datasets", | ||
key: "id", | ||
}, | ||
}, | ||
dataset_entry_id: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "dataset_entries", | ||
key: "id", | ||
}, | ||
}, | ||
json_data: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
}, | ||
created_at: { | ||
type: MssqlSimpleTypes.DATETIME2(0), | ||
allowNull: false, | ||
defaultValue: MssqlSimpleTypes.NOW, | ||
}, | ||
updated_at: { | ||
type: MssqlSimpleTypes.DATETIME2(0), | ||
allowNull: false, | ||
defaultValue: MssqlSimpleTypes.NOW, | ||
}, | ||
deleted_at: { | ||
type: MssqlSimpleTypes.DATETIME2(0), | ||
allowNull: true, | ||
}, | ||
}) | ||
|
||
await queryInterface.addIndex("dataset_entry_previews", ["dataset_id"]) | ||
await queryInterface.addIndex("dataset_entry_previews", ["dataset_entry_id"], { | ||
unique: true, | ||
where: { | ||
deleted_at: { | ||
[Op.is]: null, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
export const down: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.dropTable("dataset_entry_previews") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* See https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver16#return-value | ||
*/ | ||
export enum JsonDataType { | ||
NULL = 0, | ||
STRING = 1, | ||
NUMBER = 2, | ||
BOOLEAN = 3, | ||
ARRAY = 4, | ||
OBJECT = 5, | ||
} |
Oops, something went wrong.