Skip to content

Commit

Permalink
Add meaningful names to tabs (close #214)
Browse files Browse the repository at this point in the history
It will follow the this pattern: [db: <database_name>][tb: <table_name>] #<query_id>
  • Loading branch information
maxcnunes committed Sep 5, 2016
1 parent 9e66458 commit d37f279
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/renderer/actions/queries.js
Expand Up @@ -58,10 +58,10 @@ export function executeDefaultSelectQueryIfNeeded (database, table) {
}

if (needNewQuery(currentState, database, queryDefaultSelect)) {
dispatch({ type: NEW_QUERY, database });
dispatch({ type: NEW_QUERY, database, table });
}

dispatch({ type: UPDATE_QUERY, query: queryDefaultSelect });
dispatch({ type: UPDATE_QUERY, query: queryDefaultSelect, table });
dispatch(executeQuery(queryDefaultSelect, true, dbConn));
};
}
Expand Down
27 changes: 23 additions & 4 deletions src/renderer/reducers/queries.js
Expand Up @@ -83,7 +83,7 @@ export default function (state = INITIAL_STATE, action) {
query: action.query,
selectedQuery: action.selectedQuery,
copied: false,
});
}, { table: action.table });
}
case types.COPY_QUERY_RESULT_TO_CLIPBOARD_REQUEST: {
return changeStateByCurrentQuery(state, {
Expand Down Expand Up @@ -145,7 +145,7 @@ function addNewQuery(state, action) {
const newQuery = {
id: newId,
database: action.database,
name: `SQL File ${newId}`,
name: createQueryName(newId, action.database, action.table),
filename: null,
isExecuting: false,
isDefaultSelect: false,
Expand Down Expand Up @@ -175,15 +175,34 @@ function addNewQuery(state, action) {
}


function changeStateByCurrentQuery(oldFullState, newCurrentQueryState) {
function changeStateByCurrentQuery(oldFullState, newCurrentQueryState, options = {}) {
const oldQueryState = oldFullState.queriesById[oldFullState.currentQueryId];

oldQueryState.name = newCurrentQueryState.name || oldQueryState.name;
if (options.table) {
oldQueryState.name = createQueryName(
oldFullState.currentQueryId,
oldQueryState.database,
options.table
);
}

return {
...oldFullState,
queriesById: {
...oldFullState.queriesById,
[oldFullState.currentQueryId]: {
...oldFullState.queriesById[oldFullState.currentQueryId],
...oldQueryState,
...newCurrentQueryState,
},
},
};
}

function createQueryName (id, database, table) {
return (
table
? `[db: ${database}][tb: ${table}] #${id}`
: `[db: ${database}] #${id}`
);
}

0 comments on commit d37f279

Please sign in to comment.