Skip to content

Commit

Permalink
createdAt - timeRun
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Nov 13, 2024
1 parent f6c7c82 commit 7d7e206
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface EsqlStarredQueriesServices {
}

interface EsqlStarredQueriesParams {
client: FavoritesClient<QueryHistoryItem>;
client: FavoritesClient<StarredQueryMetadata>;
starredQueries: StarredQueryItem[];
storage: Storage;
}
Expand All @@ -57,8 +57,14 @@ function generateId() {
return uuidv4();
}

interface StarredQueryMetadata {
queryString: string;
createdAt: string;
status: 'success' | 'warning' | 'error';
}

export class EsqlStarredQueriesService {
private client: FavoritesClient<QueryHistoryItem>;
private client: FavoritesClient<StarredQueryMetadata>;
private starredQueries: StarredQueryItem[] = [];
private queryToEdit: string = '';
private storage: Storage;
Expand All @@ -73,7 +79,7 @@ export class EsqlStarredQueriesService {
}

static async initialize(services: EsqlStarredQueriesServices) {
const client = new FavoritesClient<QueryHistoryItem>('esql_editor', 'esql_query', {
const client = new FavoritesClient<StarredQueryMetadata>('esql_editor', 'esql_query', {
http: services.http,
usageCollection: services.usageCollection,
});
Expand All @@ -90,8 +96,8 @@ export class EsqlStarredQueriesService {
}
Object.keys(favoriteMetadata).forEach((id) => {
const item = favoriteMetadata[id];
const { queryString, timeRan, status } = item;
retrievedQueries.push({ id, queryString, timeRan, status });
const { queryString, createdAt, status } = item;
retrievedQueries.push({ id, queryString, timeRan: createdAt, status });
});

return new EsqlStarredQueriesService({
Expand All @@ -110,12 +116,12 @@ export class EsqlStarredQueriesService {
}

async addStarredQuery(item: Pick<QueryHistoryItem, 'queryString' | 'status'>) {
const favoriteItem = {
const favoriteItem: { id: string; metadata: StarredQueryMetadata } = {
id: generateId(),
metadata: {
queryString: getTrimmedQuery(item.queryString),
timeRan: new Date().toISOString(),
status: item.status,
createdAt: new Date().toISOString(),
status: item.status ?? 'success',
},
};

Expand All @@ -131,7 +137,7 @@ export class EsqlStarredQueriesService {

starredQueries.push({
queryString: favoriteItem.metadata.queryString,
timeRan: favoriteItem.metadata.timeRan,
timeRan: favoriteItem.metadata.createdAt,
status: favoriteItem.metadata.status,
id: favoriteItem.id,
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/esql/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class EsqlServerPlugin implements Plugin {
plugins.contentManagement.favorites.registerFavoriteType('esql_query', {
typeMetadataSchema: schema.object({
queryString: schema.string(),
timeRan: schema.string(),
createdAt: schema.string(),
status: schema.string(),
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ export default function ({ getService }: FtrProviderContext) {
const type = 'esql_query';
const metadata1 = {
queryString: 'SELECT * FROM test1',
timeRan: '2021-09-01T00:00:00Z',
createdAt: '2021-09-01T00:00:00Z',
status: 'success',
};

const metadata2 = {
queryString: 'SELECT * FROM test2',
timeRan: '2023-09-01T00:00:00Z',
createdAt: '2023-09-01T00:00:00Z',
status: 'success',
};

Expand Down

0 comments on commit 7d7e206

Please sign in to comment.