-
Notifications
You must be signed in to change notification settings - Fork 0
Island rhythms/projection redesign #166
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
0329aaa
new projection view
IslandRhythms bfc8022
mongoose syntax
IslandRhythms d933d45
fix document duplication + dropdown input
IslandRhythms dbe4db2
resolve conflicts
IslandRhythms 3de1e55
projection scoring + UI updates
IslandRhythms 5fdb8b2
remove copy tooltip
IslandRhythms faef135
default 6
IslandRhythms 4e16bff
improve UI
IslandRhythms 1aac26a
improve projection modal
IslandRhythms ebaa07d
projection mode improvements
IslandRhythms 3ce1779
support only mongoose syntax
IslandRhythms 055695a
remove bloat
IslandRhythms 8293628
add tests
IslandRhythms 87a2d32
more tests
IslandRhythms 280c395
remove useless parameter, fix buttons and layout
IslandRhythms eef0a4a
remove passing filter to getSuggestedProjection
IslandRhythms 3fbbde5
Update getSuggestedProjection.js
IslandRhythms 1dc05bb
Potential fix for pull request finding
IslandRhythms f230d45
fix attachment
IslandRhythms 0f0a572
Update models.js
IslandRhythms 15f53df
support subtractions
IslandRhythms 94ea6ca
copilot suggestions
IslandRhythms 02b96af
Update models.html
IslandRhythms f705a89
minor feature: row numbers
IslandRhythms dd7d3c5
fix: lint
IslandRhythms c5a3916
Merge branch 'main' into IslandRhythms/projection-redesign
vkarpov15 6c4c80c
remove scoring system
IslandRhythms 92961e7
don't use , for delimiter
IslandRhythms 88a7f01
fix: only use projection when enabled via url
IslandRhythms 8d24187
show already loaded documents
vkarpov15 a04c025
Merge branch 'IslandRhythms/projection-redesign' of github.com:mongoo…
vkarpov15 ac8256b
Update frontend/src/models/models.js
vkarpov15 cc02c30
remove test global
vkarpov15 465048d
Merge branch 'IslandRhythms/projection-redesign' of github.com:mongoo…
vkarpov15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| 'use strict'; | ||
|
|
||
| const Archetype = require('archetype'); | ||
| const getSuggestedProjection = require('../../helpers/getSuggestedProjection'); | ||
| const authorize = require('../../authorize'); | ||
|
|
||
| const GetSuggestedProjectionParams = new Archetype({ | ||
| model: { | ||
| $type: 'string', | ||
| $required: true | ||
| }, | ||
| roles: { | ||
| $type: ['string'] | ||
| } | ||
| }).compile('GetSuggestedProjectionParams'); | ||
|
|
||
| module.exports = ({ db }) => async function getSuggestedProjectionAction(params) { | ||
| params = new GetSuggestedProjectionParams(params); | ||
| const { roles } = params; | ||
| await authorize('Model.getSuggestedProjection', roles); | ||
|
|
||
| const { model } = params; | ||
|
|
||
| const Model = db.models[model]; | ||
| if (Model == null) { | ||
| throw new Error(`Model ${model} not found`); | ||
| } | ||
|
|
||
| // Default columns: first N schema paths (no scoring). | ||
| const suggestedFields = getSuggestedProjection(Model); | ||
|
|
||
| return { suggestedFields }; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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,37 @@ | ||
| 'use strict'; | ||
|
|
||
| /** Max number of paths to use for the default table projection. */ | ||
| const DEFAULT_SUGGESTED_LIMIT = 6; | ||
|
|
||
| /** | ||
| * Default projection for the models table: the first N schema paths (definition order), | ||
| * excluding Mongoose internals. No scoring — stable and predictable. | ||
| * | ||
| * @param {import('mongoose').Model} Model - Mongoose model | ||
| * @param {{ limit?: number }} options - max paths returned | ||
| * @returns {string[]} Path names in schema order | ||
| */ | ||
| function getSuggestedProjection(Model, options = {}) { | ||
| const limit = typeof options.limit === 'number' && options.limit > 0 | ||
| ? options.limit | ||
| : DEFAULT_SUGGESTED_LIMIT; | ||
|
|
||
| const pathNames = Object.keys(Model.schema.paths).filter(key => | ||
| !key.includes('.$*') && | ||
| key !== '__v' | ||
| ); | ||
|
|
||
| pathNames.sort((k1, k2) => { | ||
| if (k1 === '_id' && k2 !== '_id') { | ||
| return -1; | ||
| } | ||
| if (k1 !== '_id' && k2 === '_id') { | ||
| return 1; | ||
| } | ||
| return 0; | ||
| }); | ||
|
|
||
| return pathNames.slice(0, limit); | ||
| } | ||
|
|
||
| module.exports = getSuggestedProjection; |
This file contains hidden or 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 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Parse the `fields` request param for Model.getDocuments / getDocumentsStream. | ||
| * Expects JSON: either `["a","b"]` (inclusion list) or `{"a":1,"b":1}` (Mongo projection). | ||
| * | ||
| * @param {string|undefined} fields | ||
| * @returns {string|object|null} Argument suitable for Query.select(), or null when unset/invalid. | ||
| */ | ||
| function parseFieldsParam(fields) { | ||
| if (fields == null || typeof fields !== 'string') { | ||
| return null; | ||
| } | ||
| const trimmed = fields.trim(); | ||
| if (!trimmed) { | ||
| return null; | ||
| } | ||
|
|
||
| let parsed; | ||
| try { | ||
| parsed = JSON.parse(trimmed); | ||
| } catch (e) { | ||
| return null; | ||
| } | ||
|
|
||
| if (Array.isArray(parsed)) { | ||
| const list = parsed.map(x => String(x).trim()).filter(Boolean); | ||
| return list.length > 0 ? list.join(' ') : null; | ||
| } | ||
| if (parsed != null && typeof parsed === 'object' && !Array.isArray(parsed)) { | ||
| return Object.keys(parsed).length > 0 ? parsed : null; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| module.exports = parseFieldsParam; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| <div class="list-mixed tooltip"> | ||
|
vkarpov15 marked this conversation as resolved.
|
||
| <pre> | ||
| <code ref="MixedCode" class="language-javascript">{{shortenValue}}</code> | ||
| <span class="tooltiptext" @click.stop="copyText(value)">copy 📋</span> | ||
| </pre> | ||
| </div> | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| <div class="list-string tooltip" ref="itemData"> | ||
| {{displayValue}} | ||
|
vkarpov15 marked this conversation as resolved.
|
||
| <span class="tooltiptext" @click.stop="copyText(value)">copy 📋</span> | ||
| </div> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.