Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@ import qs from 'qs';
import {AssetKey, AssetViewParams} from './types';

export const assetDetailsPathForKey = (key: AssetKey, query?: AssetViewParams) => {
return `/assets/${key.path.map(encodeURIComponent).join('/')}?${qs.stringify(query)}`;
if (!query) {
return `/assets/${key.path.map(encodeURIComponent).join('/')}`;
}
// Ensure partition comes before default_range in the URL
const queryString = qs.stringify(query, {
sort: (a, b) => {
// Ensure partition comes before default_range
if (a === 'partition' && b === 'default_range') {
return -1;
}
if (a === 'default_range' && b === 'partition') {
return 1;
}
// Otherwise maintain alphabetical order for other params
return a < b ? -1 : a > b ? 1 : 0;
},
});
return `/assets/${key.path.map(encodeURIComponent).join('/')}?${queryString}`;
};

export const assetDetailsPathForAssetCheck = (check: {assetKey: AssetKey; name: string}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ export function usePartitionKeyInParams({
if (dimensionKey) {
nextFocusedDimensionKeys.push(dimensionKey);
}
// Ensure partition comes before default_range in the URL by explicitly ordering properties
const {partition: _partition, default_range, ...restParams} = params;
setParams({
...params,
...restParams,
partition: nextFocusedDimensionKeys.join('|'),
...(default_range ? {default_range} : {}),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,20 @@ export function useQueryPersistedState<T extends QueryPersistedDataType>(
!areQueriesEqual(currentQueryString, next)
) {
currentQueryString = next;
const nextPath = `${history.location.pathname}?${qs.stringify(next, {arrayFormat: 'indices'})}`;
const nextPath = `${history.location.pathname}?${qs.stringify(next, {
arrayFormat: 'indices',
sort: (a, b) => {
// Ensure partition comes before default_range in the URL
if (a === 'partition' && b === 'default_range') {
return -1;
}
if (a === 'default_range' && b === 'partition') {
return 1;
}
// Otherwise maintain alphabetical order for other params
return COMMON_COLLATOR.compare(a, b);
},
})}`;
if (behavior === 'replace') {
history.replace(nextPath);
} else {
Expand All @@ -170,13 +183,24 @@ export function useQueryPersistedState<T extends QueryPersistedDataType>(
// Stringify two query objects to check whether they have the same value. Explicitly sort the
// keys, since key order is otherwise undefined.
function areQueriesEqual(queryA: qs.ParsedQs, queryB: qs.ParsedQs) {
const sortFn = (a: string, b: string) => {
// Ensure partition comes before default_range in the URL
if (a === 'partition' && b === 'default_range') {
return -1;
}
if (a === 'default_range' && b === 'partition') {
return 1;
}
// Otherwise maintain alphabetical order for other params
return COMMON_COLLATOR.compare(a, b);
};
const stringA = qs.stringify(queryA, {
arrayFormat: 'brackets',
sort: (a, b) => COMMON_COLLATOR.compare(a, b),
sort: sortFn,
});
const stringB = qs.stringify(queryB, {
arrayFormat: 'brackets',
sort: (a, b) => COMMON_COLLATOR.compare(a, b),
sort: sortFn,
});
return stringA === stringB;
}
Expand Down