Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
3f980813
Unverified
Commit
3f980813
authored
5 years ago
by
Paul Rosenzweig
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Sort fields before checking if a query has been updated (#11311)
parent
4a7509a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/query_builder/selectors.js
+30
-4
30 additions, 4 deletions
frontend/src/metabase/query_builder/selectors.js
frontend/test/metabase/query_builder/selectors.unit.spec.js
+71
-0
71 additions, 0 deletions
frontend/test/metabase/query_builder/selectors.unit.spec.js
with
101 additions
and
4 deletions
frontend/src/metabase/query_builder/selectors.js
+
30
−
4
View file @
3f980813
...
...
@@ -2,7 +2,7 @@
import
{
createSelector
}
from
"
reselect
"
;
import
_
from
"
underscore
"
;
import
{
getIn
}
from
"
icepick
"
;
import
{
getIn
,
updateIn
}
from
"
icepick
"
;
// Needed due to wrong dependency resolution order
// eslint-disable-next-line no-unused-vars
...
...
@@ -149,10 +149,36 @@ export const getIsResultDirty = createSelector(
getNextRunDatasetQuery
,
getLastRunParameterValues
,
getNextRunParameterValues
,
getTableMetadata
,
],
(
lastDatasetQuery
,
nextDatasetQuery
,
lastParameters
,
nextParameters
)
=>
!
Utils
.
equals
(
lastDatasetQuery
,
nextDatasetQuery
)
||
!
Utils
.
equals
(
lastParameters
,
nextParameters
),
(
lastDatasetQuery
,
nextDatasetQuery
,
lastParameters
,
nextParameters
,
tableMetadata
,
)
=>
{
// this function sorts fields so that reordering doesn't dirty the result
const
queryWithSortedFields
=
query
=>
query
&&
query
.
query
&&
tableMetadata
?
updateIn
(
query
,
[
"
query
"
,
"
fields
"
],
fields
=>
{
fields
=
fields
?
// if the query has fields, copy them before sorting
[...
fields
]
:
// if the fields aren't set, we get them from the table metadata
tableMetadata
.
fields
.
map
(({
id
})
=>
[
"
field-id
"
,
id
]);
return
fields
.
sort
((
a
,
b
)
=>
JSON
.
stringify
(
b
).
localeCompare
(
JSON
.
stringify
(
a
)),
);
})
:
query
;
lastDatasetQuery
=
queryWithSortedFields
(
lastDatasetQuery
);
nextDatasetQuery
=
queryWithSortedFields
(
nextDatasetQuery
);
return
(
!
Utils
.
equals
(
lastDatasetQuery
,
nextDatasetQuery
)
||
!
Utils
.
equals
(
lastParameters
,
nextParameters
)
);
},
);
export
const
getQuestion
=
createSelector
(
...
...
This diff is collapsed.
Click to expand it.
frontend/test/metabase/query_builder/selectors.unit.spec.js
0 → 100644
+
71
−
0
View file @
3f980813
import
{
getIsResultDirty
}
from
"
metabase/query_builder/selectors
"
;
import
{
state
as
sampleState
}
from
"
__support__/sample_dataset_fixture
"
;
describe
(
"
getIsResultDirty
"
,
()
=>
{
function
getState
(
q1
,
q2
)
{
const
card
=
query
=>
({
dataset_query
:
{
database
:
1
,
type
:
"
query
"
,
query
},
});
const
qb
=
{
lastRunCard
:
card
(
q1
),
card
:
card
(
q2
)
};
return
{
...
sampleState
,
qb
};
}
it
(
"
should not be dirty for empty queries
"
,
()
=>
{
const
state
=
getState
({},
{});
expect
(
getIsResultDirty
(
state
)).
toBe
(
false
);
});
it
(
"
should be dirty if the table was changed
"
,
()
=>
{
const
state
=
getState
({
"
source-table
"
:
1
},
{
"
source-table
"
:
2
});
expect
(
getIsResultDirty
(
state
)).
toBe
(
true
);
});
it
(
"
should be dirty if the fields were changed
"
,
()
=>
{
const
state
=
getState
(
{
"
source-table
"
:
1
,
fields
:
[[
"
field-id
"
,
1
]]
},
{
"
source-table
"
:
1
,
fields
:
[[
"
field-id
"
,
2
]]
},
);
expect
(
getIsResultDirty
(
state
)).
toBe
(
true
);
});
it
(
"
should not be dirty if the fields were reordered
"
,
()
=>
{
const
state
=
getState
(
{
"
source-table
"
:
1
,
fields
:
[[
"
field-id
"
,
1
],
[
"
field-id
"
,
2
]]
},
{
"
source-table
"
:
1
,
fields
:
[[
"
field-id
"
,
2
],
[
"
field-id
"
,
1
]]
},
);
expect
(
getIsResultDirty
(
state
)).
toBe
(
false
);
});
it
(
"
should not be dirty if fields with fk refs were reordered
"
,
()
=>
{
const
state
=
getState
(
{
"
source-table
"
:
1
,
fields
:
[[
"
fk->
"
,
[
"
field-id
"
,
1
],
[
"
field-id
"
,
2
]],
[
"
field-id
"
,
1
]],
},
{
"
source-table
"
:
1
,
fields
:
[[
"
field-id
"
,
1
],
[
"
fk->
"
,
[
"
field-id
"
,
1
],
[
"
field-id
"
,
2
]]],
},
);
expect
(
getIsResultDirty
(
state
)).
toBe
(
false
);
});
it
(
"
should not be dirty if fields were just made explicit
"
,
()
=>
{
const
state
=
getState
(
{
"
source-table
"
:
1
},
{
"
source-table
"
:
1
,
fields
:
[
[
"
field-id
"
,
1
],
[
"
field-id
"
,
2
],
[
"
field-id
"
,
3
],
[
"
field-id
"
,
4
],
[
"
field-id
"
,
5
],
[
"
field-id
"
,
6
],
[
"
field-id
"
,
7
],
],
},
);
expect
(
getIsResultDirty
(
state
)).
toBe
(
false
);
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment