Skip to content

Commit 7cb65f3

Browse files
authored
fix: Storing view on server creates view key with hashed view name instead of UUID (#2995)
1 parent 918b9b1 commit 7cb65f3

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/dashboard/Data/Views/EditViewDialog.react.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default class EditViewDialog extends React.Component {
3030
}
3131

3232
this.state = {
33+
id: view.id, // Preserve the view ID
3334
name: view.name || '',
3435
className: view.className || '',
3536
dataSourceType,
@@ -73,6 +74,7 @@ export default class EditViewDialog extends React.Component {
7374
onCancel={onCancel}
7475
onConfirm={() =>
7576
onConfirm({
77+
id: this.state.id, // Preserve the view ID
7678
name: this.state.name,
7779
className: this.state.dataSourceType === 'query' ? this.state.className : null,
7880
query: this.state.dataSourceType === 'query' ? JSON.parse(this.state.query) : null,

src/dashboard/Data/Views/Views.react.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,13 @@ class Views extends TableView {
721721
classes={classNames}
722722
onCancel={() => this.setState({ showCreate: false })}
723723
onConfirm={view => {
724+
// Generate UUID for new view
725+
const newView = {
726+
...view,
727+
id: this.viewPreferencesManager.generateViewId()
728+
};
724729
this.setState(
725-
state => ({ showCreate: false, views: [...state.views, view] }),
730+
state => ({ showCreate: false, views: [...state.views, newView] }),
726731
async () => {
727732
if (this.viewPreferencesManager) {
728733
try {

src/lib/ViewPreferencesManager.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export default class ViewPreferencesManager {
183183
);
184184

185185
// Delete views that are no longer in the new views array
186-
const newViewIds = views.map(view => view.id || this._generateViewId(view));
186+
const newViewIds = views.map(view => view.id || this._generateViewId());
187187
const viewsToDelete = existingViewIds.filter(id => !newViewIds.includes(id));
188188

189189
await Promise.all(
@@ -195,7 +195,7 @@ export default class ViewPreferencesManager {
195195
// Save or update current views
196196
await Promise.all(
197197
views.map(view => {
198-
const viewId = view.id || this._generateViewId(view);
198+
const viewId = view.id || this._generateViewId();
199199
const viewConfig = { ...view };
200200
delete viewConfig.id; // Don't store ID in the config itself
201201

@@ -263,18 +263,19 @@ export default class ViewPreferencesManager {
263263
}
264264

265265
/**
266-
* Generates a unique ID for a view
266+
* Generates a unique ID for a new view
267+
* @returns {string} A UUID string
268+
*/
269+
generateViewId() {
270+
return this._generateViewId();
271+
}
272+
273+
/**
274+
* Generates a unique ID for a view using UUID
267275
* @private
268276
*/
269-
_generateViewId(view) {
270-
if (view.id) {
271-
return view.id;
272-
}
273-
// Generate a unique ID based on view name, timestamp, and random component
274-
const timestamp = Date.now().toString(36);
275-
const random = Math.random().toString(36).substr(2, 5);
276-
const nameHash = view.name ? view.name.replace(/[^a-zA-Z0-9]/g, '').toLowerCase() : 'view';
277-
return `${nameHash}_${timestamp}_${random}`;
277+
_generateViewId() {
278+
return crypto.randomUUID();
278279
}
279280
}
280281

0 commit comments

Comments
 (0)