Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Carina Ursu <[email protected]>
  • Loading branch information
ursucarina committed May 5, 2022
1 parent 4abde81 commit 553f5ed
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@ const stories = storiesOf('Literals/Collection', module);
stories.addDecorator(CardDecorator);

function renderCollection(label: string, collection: LiteralCollection) {
const map = { literals: { [label]: { collection, value: 'collection' } } };
return (
<>
<div style={{ display: 'flex' }}>
<div style={{ marginRight: '16px' }}>
OLD
<Card>
<CardContent>
<DeprecatedLiteralMapViewer
map={{ literals: { [label]: { collection, value: 'collection' } } }}
/>
<DeprecatedLiteralMapViewer map={map} />
</CardContent>
</Card>
</div>
<div>
NEW
<Card>
<CardContent>
<LiteralMapViewer
map={{ literals: { [label]: { collection, value: 'collection' } } }}
/>
<LiteralMapViewer map={map} />
</CardContent>
</Card>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ const stories = storiesOf('Literals/Map', module);
stories.addDecorator(CardDecorator);

function renderMap(label: string, map: LiteralMap) {
const fullMap = { literals: { [label]: { map, value: 'map' } } };
return (
<>
<div style={{ display: 'flex' }}>
<div style={{ marginRight: '16px' }}>
OLD
<Card>
<CardContent>
<DeprecatedLiteralMapViewer map={{ literals: { [label]: { map, value: 'map' } } }} />
<DeprecatedLiteralMapViewer map={fullMap} />
</CardContent>
</Card>
</div>
<div>
NEW
<Card>
<CardContent>
<LiteralMapViewer map={{ literals: { [label]: { map, value: 'map' } } }} />
<LiteralMapViewer map={fullMap} />
</CardContent>
</Card>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,27 @@ const stories = storiesOf('Literals/ProtobufStruct', module);
stories.addDecorator(CardDecorator);

function renderStruct(label: string, struct: ProtobufStruct) {
const map = {
literals: {
[label]: { scalar: { value: 'generic', generic: struct }, value: 'scalar' },
},
};
return (
<>
<div style={{ display: 'flex' }}>
<div style={{ marginRight: '16px' }}>
OLD
<Card>
<CardContent>
<DeprecatedLiteralMapViewer
map={{
literals: {
[label]: { scalar: { value: 'generic', generic: struct }, value: 'scalar' },
},
}}
/>
<DeprecatedLiteralMapViewer map={map} />
</CardContent>
</Card>
</div>
<div>
NEW
<Card>
<CardContent>
<LiteralMapViewer
map={{
literals: {
[label]: { scalar: { value: 'generic', generic: struct }, value: 'scalar' },
},
}}
/>
<LiteralMapViewer map={map} />
</CardContent>
</Card>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/zapp/console/src/components/Literals/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function processPrimitive(primitive: Core.IPrimitive) {
case 'duration':
return protobufDurationToHMS(primitive.duration!);
case 'integer': {
return Long.fromValue(primitive[type] as any as Long).toNumber();
return Long.fromValue(primitive[type] as Long).toNumber();
}
case 'boolean':
case 'floatValue':
Expand Down Expand Up @@ -311,7 +311,7 @@ function processLiteralValue(literal: Core.ILiteral) {
export function transformLiteralMap(json: Core.ILiteralMap) {
const obj = sortedObjectEntries(json as any)
.map(([key, literal]) => ({
[key]: processLiteralValue(literal as any as Core.Literal),
[key]: processLiteralValue(literal as Core.Literal),
}))
.reduce(
(acc, cur) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ const collection = {

export default {
...collection,
} as any as TestCaseList<Core.ILiteral>;
} as TestCaseList<Core.ILiteral>;
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ export function getIValue(
| Protobuf.IStruct
| Protobuf.IListValue
| null,
): Core.Primitive | Core.IPrimitive {
): Protobuf.IValue & Pick<Protobuf.Value, 'kind'> {
return {
kind,
[kind]: value,
} as any as Protobuf.Value;
};
}

export function getPrimitive(
key: 'integer' | 'floatValue' | 'stringValue' | 'boolean' | 'datetime' | 'duration',
value?: Long | number | string | boolean | Protobuf.ITimestamp | Protobuf.IDuration | null,
): Core.Primitive | Core.IPrimitive {
): Core.IPrimitive & Pick<Core.Primitive, 'value'> {
return {
[key]: value,
value: key,
} as any as Core.Primitive;
};
}

export function generateBlobType(
Expand All @@ -43,18 +43,43 @@ export function generateBlobType(
};
}

const getScalar = (
value:
| Core.IPrimitive
| Core.IBlob
| Core.IBinary
| Core.ISchema
| Core.IVoid
| Core.IError
| Protobuf.IStruct
| Core.IStructuredDataset
| Core.IUnion,
scalarType: any,
): Core.IScalar & Pick<Core.Scalar, 'value'> => {
return {
[scalarType]: value,
value: scalarType,
};
};

// TOP LEVEL SCHEMA GENERATORS:
export const getScalar = (
value: Core.IPrimitive | Core.IBlob | Core.IBinary,
scalarType: string,
) => {
export const getScalarLiteral = (
value:
| Core.IPrimitive
| Core.IBlob
| Core.IBinary
| Core.ISchema
| Core.IVoid
| Core.IError
| Protobuf.IStruct
| Core.IStructuredDataset
| Core.IUnion,
scalarType: any,
): Core.ILiteral & Pick<Core.Literal, 'value' | 'scalar'> => {
return {
scalar: {
[scalarType]: value,
value: scalarType,
},
scalar: getScalar(value, scalarType),
value: 'scalar',
} as Core.IScalar;
};
};

export const getCollection = (literals: Core.ILiteral[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
collection,
map,
} from './helpers/index';
import { getCollection, getMap, getScalar } from './helpers/literalHelpers';
import { getCollection, getMap, getScalarLiteral } from './helpers/literalHelpers';

const literalTestCases = {
scalar: {
Expand All @@ -40,7 +40,7 @@ describe('scalar literal', () => {
const { value, expected } = cases?.[testKey]!;

it(`${testKey}: should return ${expected} for ${value}`, () => {
const scalar = { result_var: { ...getScalar(value, scalarTestType) } };
const scalar = { result_var: { ...getScalarLiteral(value, scalarTestType) } };
const result = transformLiteralMap(scalar as any);
expect(result).toEqual(expected);
});
Expand Down

0 comments on commit 553f5ed

Please sign in to comment.