-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
095aa46
commit 0d34385
Showing
51 changed files
with
1,390 additions
and
67 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
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,3 @@ | ||
import { configure } from '@testing-library/react' | ||
|
||
configure({ testIdAttribute: 'data-test-id' }) |
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,29 @@ | ||
import { getFormContextDefault } from './FormContext' | ||
import { inputAligns, inputSizes } from '../../components/Atomic/FormInput' | ||
|
||
describe('getFormContextDefault', () => { | ||
it('returns default form context with provided i18nDefault', () => { | ||
const i18nDefault = 'test' | ||
const context = getFormContextDefault(i18nDefault) | ||
|
||
expect(context.commonTimeoutControlProps.i18n.default).toBe(i18nDefault) | ||
expect(context.updateData).toBeInstanceOf(Function) | ||
expect(context.commonFormGroupProps).toEqual({ | ||
errorTooltip: true, | ||
fullSize: true, | ||
marginBottom: false, | ||
}) | ||
expect(context.commonInputProps).toEqual({ | ||
align: inputAligns.RIGHT, | ||
inlineStyle: true, | ||
size: inputSizes.SMALL, | ||
}) | ||
expect(context.compactFormComponentsView).toBe(false) | ||
}) | ||
|
||
it('returns default form context with empty i18nDefault when no argument is provided', () => { | ||
const context = getFormContextDefault() | ||
|
||
expect(context.commonTimeoutControlProps.i18n.default).toBe('') | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/common/utils/copy-to-clipboard.js → src/common/utils/copy-to-clipboard.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
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 was deleted.
Oops, something went wrong.
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,13 @@ | ||
type ErrorType = { | ||
response?: { | ||
data?: { | ||
err?: string | ||
message?: string | ||
} | ||
} | ||
message?: string | ||
} | ||
|
||
// Return a message from the error response of an API | ||
export const getApiErrorMessage = (error: ErrorType | string): string | undefined => | ||
typeof error === 'string' ? error : error?.response?.data?.err || error?.response?.data?.message || error?.message || undefined |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export const getValue = (value: any, emptyPlaceholder = '-') => (value !== undefined && value !== null ? value : emptyPlaceholder) |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export * from './get-value' | ||
export * from './cert-decoder.mjs' | ||
export * from './copy-to-clipboard' | ||
export * from './devices' | ||
export * from './get-api-error-message' | ||
export * from './get-app-mode' | ||
export * from './get-value' | ||
export * from './is-browser-tab-active' | ||
// export * from './play-random-fart-sound' | ||
export * from './parse-streamed-data' | ||
export * from './copy-to-clipboard' | ||
export * from './is-valid-guid' | ||
export * from './devices' | ||
export * from './parse-streamed-data' | ||
export * from './time' |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
export const isValidGuid = (guid: string) => | ||
/^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/i.test(guid) && | ||
((guid.charAt(0) === '{' && guid.charAt(guid.length - 1) === '}') || guid.charAt(0) !== '{') |
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 was deleted.
Oops, something went wrong.
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,136 @@ | ||
// @ts-nocheck | ||
const Converter = function (numerator, definitions) { | ||
this.definitions = definitions | ||
this.val = numerator | ||
} | ||
|
||
Converter.prototype.from = function (from) { | ||
if (this.destination) { | ||
throw new Error('.from must be called before .to') | ||
} | ||
|
||
this.origin = this.getUnit(from) | ||
|
||
if (!this.origin) { | ||
this.throwUnsupportedUnitError(from) | ||
} | ||
|
||
return this | ||
} | ||
|
||
Converter.prototype.to = function (to) { | ||
if (!this.origin) { | ||
throw new Error('.to must be called after .from') | ||
} | ||
|
||
this.destination = this.getUnit(to) | ||
|
||
let result | ||
|
||
if (!this.destination) { | ||
this.throwUnsupportedUnitError(to) | ||
} | ||
|
||
if (this.origin.abbr === this.destination.abbr) { | ||
return Object.assign({ value: this.val }, this.describe(this.destination.abbr)) | ||
} | ||
|
||
result = this.val * this.origin.unit.to_anchor | ||
|
||
if (this.origin.unit.anchor_shift) { | ||
result -= this.origin.unit.anchor_shift | ||
} | ||
|
||
if (this.origin.system !== this.destination.system) { | ||
result = this.definitions[this.origin.system].transform(result) | ||
} | ||
|
||
if (this.destination.unit.anchor_shift !== undefined) { | ||
result += this.destination.unit.anchor_shift | ||
} | ||
|
||
return Object.assign({ value: result / this.destination.unit.to_anchor }, this.describe(this.destination.abbr)) | ||
} | ||
|
||
Converter.prototype.toBest = function (options) { | ||
if (!this.origin) { | ||
throw new Error('.toBest must be called after .from') | ||
} | ||
|
||
options = Object.assign( | ||
{ | ||
exclude: [], | ||
cutOffNumber: 1, | ||
}, | ||
options | ||
) | ||
|
||
return this.list() | ||
.filter((item) => !options.exclude.includes(item.unit) && this.describe(item.unit).system === this.origin.system) | ||
.reduce((acc, item) => { | ||
const result = this.to(item.unit) | ||
if (!acc || (result.value >= options.cutOffNumber && result.value < acc.value)) { | ||
return result | ||
} else { | ||
return acc | ||
} | ||
}, undefined) | ||
} | ||
|
||
Converter.prototype.getUnit = function (abbr) { | ||
const systemNames = Object.keys(this.definitions) | ||
const found = systemNames | ||
.map((systemName) => { | ||
if (this.definitions[systemName][abbr]) { | ||
return { | ||
abbr: abbr, | ||
system: systemName, | ||
unit: this.definitions[systemName][abbr], | ||
} | ||
} else { | ||
return undefined | ||
} | ||
}) | ||
.filter((item) => item !== undefined) | ||
|
||
return Array.isArray(found) ? found[0] : undefined | ||
} | ||
|
||
Converter.prototype.list = function () { | ||
return this.possibilities().map((abbr) => this.describe(abbr)) | ||
} | ||
|
||
Converter.prototype.throwUnsupportedUnitError = function (what) { | ||
throw new Error('Unsupported unit ' + what) | ||
} | ||
|
||
Converter.prototype.describe = function (abbr) { | ||
if (!abbr) { | ||
throw new Error('You must select a unit') | ||
} | ||
|
||
const unit = this.getUnit(abbr) | ||
|
||
return { | ||
unit: unit.abbr, | ||
system: unit.system, | ||
singular: unit.unit.name.singular, | ||
plural: unit.unit.name.plural, | ||
} | ||
} | ||
|
||
Converter.prototype.possibilities = function () { | ||
return Array.prototype.concat( | ||
...Object.keys(this.definitions).map((systemName) => { | ||
return Object.keys(this.definitions[systemName]).splice(2) | ||
}) | ||
) | ||
} | ||
|
||
function converter(definitions) { | ||
return (val) => { | ||
return new Converter(val, definitions) | ||
} | ||
} | ||
|
||
export default converter |
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 |
---|---|---|
@@ -1,4 +1,92 @@ | ||
import utils from './time-utils' | ||
|
||
export function getMinutesBetweenDates(startDate: Date, endDate: Date) { | ||
const diff = endDate.getTime() - startDate.getTime() | ||
return diff / 60000 | ||
} | ||
|
||
const RATIO = 1 | ||
const daysInYear = 365.25 | ||
|
||
const time = { | ||
metric: { | ||
baseUnit: 's', | ||
transform: (val: any) => { | ||
return val * RATIO | ||
}, | ||
ns: { | ||
name: { | ||
singular: 'Nanosecond', | ||
plural: 'Nanoseconds', | ||
}, | ||
to_anchor: 1 / 1000000000, | ||
}, | ||
mu: { | ||
name: { | ||
singular: 'Microsecond', | ||
plural: 'Microseconds', | ||
}, | ||
to_anchor: 1 / 1000000, | ||
}, | ||
ms: { | ||
name: { | ||
singular: 'Millisecond', | ||
plural: 'Milliseconds', | ||
}, | ||
to_anchor: 1 / 1000, | ||
}, | ||
s: { | ||
name: { | ||
singular: 'Second', | ||
plural: 'Seconds', | ||
}, | ||
to_anchor: 1, | ||
}, | ||
min: { | ||
name: { | ||
singular: 'Minute', | ||
plural: 'Minutes', | ||
}, | ||
to_anchor: 60, | ||
}, | ||
h: { | ||
name: { | ||
singular: 'Hour', | ||
plural: 'Hours', | ||
}, | ||
to_anchor: 60 * 60, | ||
}, | ||
d: { | ||
name: { | ||
singular: 'Day', | ||
plural: 'Days', | ||
}, | ||
to_anchor: 60 * 60 * 24, | ||
}, | ||
week: { | ||
name: { | ||
singular: 'Week', | ||
plural: 'Weeks', | ||
}, | ||
to_anchor: 60 * 60 * 24 * 7, | ||
}, | ||
month: { | ||
name: { | ||
singular: 'Month', | ||
plural: 'Months', | ||
}, | ||
to_anchor: (60 * 60 * 24 * daysInYear) / 12, | ||
}, | ||
year: { | ||
name: { | ||
singular: 'Year', | ||
plural: 'Years', | ||
}, | ||
to_anchor: 60 * 60 * 24 * daysInYear, | ||
}, | ||
}, | ||
} | ||
|
||
const time$1 = utils(time) | ||
|
||
export default time$1 |
Oops, something went wrong.