-
-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: last seen at rendering logic (#5136)
This PR fixes a bug where the rendering in the frontend would only render the last seen component if feature.lastSeenAt was set, the new changes considers whether or not environments last seen at is present and takes precedent over the legacy last seen at field.
- Loading branch information
1 parent
da2c46d
commit 5acf691
Showing
6 changed files
with
121 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...tend/src/component/feature/FeatureView/FeatureEnvironmentSeen/getLatestLastSeenAt.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { IEnvironments } from 'interfaces/featureToggle'; | ||
|
||
import { getLatestLastSeenAt } from './getLatestLastSeenAt'; | ||
|
||
describe('getLatestLastSeenAt', () => { | ||
test('should return the most recent lastSeenAt date', () => { | ||
const input: IEnvironments[] = [ | ||
{ | ||
name: 'test1', | ||
lastSeenAt: '2023-10-22T08:48:11.869Z', | ||
enabled: false, | ||
variantCount: 0, | ||
}, | ||
{ | ||
name: 'test2', | ||
lastSeenAt: '2023-10-23T08:48:11.869Z', | ||
enabled: true, | ||
variantCount: 0, | ||
}, | ||
{ | ||
name: 'test3', | ||
lastSeenAt: '2023-10-24T08:48:11.869Z', | ||
enabled: true, | ||
variantCount: 0, | ||
}, | ||
]; | ||
const expected = '2023-10-24T08:48:11.869Z'; | ||
expect(getLatestLastSeenAt(input)).toBe(expected); | ||
}); | ||
|
||
test('should handle an empty array', () => { | ||
const input: IEnvironments[] = []; | ||
const expected = null; | ||
expect(getLatestLastSeenAt(input)).toBe(expected); | ||
}); | ||
|
||
test('should not fail with non-standard date formats', () => { | ||
const input: IEnvironments[] = [ | ||
{ | ||
name: 'test', | ||
lastSeenAt: 'Some Invalid Date', | ||
enabled: true, | ||
variantCount: 0, | ||
}, | ||
]; | ||
expect(() => getLatestLastSeenAt(input)).not.toThrow(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
frontend/src/component/feature/FeatureView/FeatureEnvironmentSeen/getLatestLastSeenAt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ILastSeenEnvironments } from 'interfaces/featureToggle'; | ||
|
||
export const getLatestLastSeenAt = ( | ||
environments: ILastSeenEnvironments[], | ||
): string | null => { | ||
try { | ||
if (!Array.isArray(environments) || environments.length === 0) { | ||
return null; | ||
} | ||
|
||
return environments | ||
.filter((item) => Boolean(item.lastSeenAt)) | ||
.map((item) => new Date(item.lastSeenAt!)) | ||
.reduce((latest, current) => (current > latest ? current : latest)) | ||
.toISOString(); | ||
} catch (error) { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters