Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions src/dashboard/Data/Views/EditViewDialog.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class EditViewDialog extends React.Component {
}

this.state = {
id: view.id, // Preserve the view ID
name: view.name || '',
className: view.className || '',
dataSourceType,
Expand Down Expand Up @@ -73,6 +74,7 @@ export default class EditViewDialog extends React.Component {
onCancel={onCancel}
onConfirm={() =>
onConfirm({
id: this.state.id, // Preserve the view ID
name: this.state.name,
className: this.state.dataSourceType === 'query' ? this.state.className : null,
query: this.state.dataSourceType === 'query' ? JSON.parse(this.state.query) : null,
Expand Down
7 changes: 6 additions & 1 deletion src/dashboard/Data/Views/Views.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,13 @@ class Views extends TableView {
classes={classNames}
onCancel={() => this.setState({ showCreate: false })}
onConfirm={view => {
// Generate UUID for new view
const newView = {
...view,
id: this.viewPreferencesManager.generateViewId()
};
this.setState(
state => ({ showCreate: false, views: [...state.views, view] }),
state => ({ showCreate: false, views: [...state.views, newView] }),
async () => {
if (this.viewPreferencesManager) {
try {
Expand Down
25 changes: 13 additions & 12 deletions src/lib/ViewPreferencesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default class ViewPreferencesManager {
);

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

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

Expand Down Expand Up @@ -263,18 +263,19 @@ export default class ViewPreferencesManager {
}

/**
* Generates a unique ID for a view
* Generates a unique ID for a new view
* @returns {string} A UUID string
*/
generateViewId() {
return this._generateViewId();
}

/**
* Generates a unique ID for a view using UUID
* @private
*/
_generateViewId(view) {
if (view.id) {
return view.id;
}
// Generate a unique ID based on view name, timestamp, and random component
const timestamp = Date.now().toString(36);
const random = Math.random().toString(36).substr(2, 5);
const nameHash = view.name ? view.name.replace(/[^a-zA-Z0-9]/g, '').toLowerCase() : 'view';
return `${nameHash}_${timestamp}_${random}`;
_generateViewId() {
return crypto.randomUUID();
}
}

Expand Down
Loading