Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(model-form): Glimmer Components #539

Draft
wants to merge 22 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f68770b
feat: install TypeScript and add first model-form integration test
guidojw May 10, 2022
31f9e3a
feat(checkbox-button): add more tests
guidojw May 10, 2022
8939835
feat: add stub tests
guidojw May 11, 2022
d5c408a
feat: add missing deps to yarn.lock
guidojw Dec 31, 2022
a98b8be
Merge branch 'staging' of https://github.com/csvalpha/amber-ui into r…
guidojw Dec 31, 2022
046b3c9
fix: run yarn install
guidojw Dec 31, 2022
0785387
fix: add @types/eslint resolution to v7
guidojw Dec 31, 2022
4de1ac0
refactor: rename alpha-amber to amber-ui
guidojw Dec 31, 2022
8b8f26e
revert: yarn.lock updates
guidojw Dec 31, 2022
3524eb5
feat: run yarn install, dedupe and update express-serve-static-core
guidojw Dec 31, 2022
eeadc67
fix: immutable install
guidojw Dec 31, 2022
87f365d
chore: fix lint
guidojw Dec 31, 2022
7d4f25e
refactor: move rendering tests to integration tests
guidojw Dec 31, 2022
faeea33
refactor: make advertisement-tool-test ts
guidojw Dec 31, 2022
f206f9f
fix: md-editor test
guidojw Dec 31, 2022
36593a2
feat: install TypeScript and add first model-form integration tests
renovate[bot] May 5, 2022
c143779
Merge remote-tracking branch 'origin/refactor/glimmer-components-mode…
guidojw Dec 31, 2022
121d987
Merge branch 'staging' into refactor/glimmer-components-model-form
guidojw Oct 14, 2023
b3189f7
fix: yarn.lock
guidojw Oct 14, 2023
5c0cca7
refactor(model-form): first 5 components to Glimmer
guidojw Oct 15, 2023
d03cbe4
refactor: change to Signature type parameter
guidojw Oct 15, 2023
998fcf2
refactor(model-form): Glimmer RadioGroup and RadioButton
guidojw Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

module.exports = {
root: true,
parser: 'babel-eslint',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
ecmaVersion: 'latest',
},
plugins: ['ember'],
plugins: ['ember', '@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
Expand All @@ -37,6 +33,15 @@ module.exports = {
],
},
overrides: [
// ts files
{
files: ['**/*.ts'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {},
},
// node files
{
files: [
Expand All @@ -52,9 +57,6 @@ module.exports = {
'./.stylelintrc.js',
'./.stylelintrc.order.js',
],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
Expand All @@ -72,5 +74,17 @@ module.exports = {
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
// js files // TODO: remove when fully over to ts
{
files: ['**/*.js'],
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
},
],
};
File renamed without changes.
6 changes: 5 additions & 1 deletion app/components/advertisement-tool.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<div class='d-flex adv-row flex-column flex-wrap justify-content-center'>
{{#each advertisements as |advertisement index|}}
{{#if advertisement.links}}
<div class='advertisement-item advertisement-item--full col-auto'>
<div
class='advertisement-item advertisement-item--full col-auto'
data-test-advertisement-item
>
{{#each advertisement.links as |link|}}
<a
class='d-block text-primary'
Expand All @@ -22,6 +25,7 @@
href={{advertisement.link}}
title={{advertisement.title}}
target='_blank'
data-test-advertisement-item
>
<img
src={{advertisement.image}}
Expand Down
2 changes: 1 addition & 1 deletion app/components/advertisement-tool.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Component from '@ember/component';

Check warning on line 1 in app/components/advertisement-tool.js

View workflow job for this annotation

GitHub Actions / Lint

Use Glimmer components(@glimmer/component) instead of classic components(@ember/component)
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';

export default Component.extend({

Check warning on line 5 in app/components/advertisement-tool.js

View workflow job for this annotation

GitHub Actions / Lint

Native JS classes should be used instead of classic classes

Check warning on line 5 in app/components/advertisement-tool.js

View workflow job for this annotation

GitHub Actions / Lint

Please switch to a tagless component by setting `tagName: ''` or converting to a Glimmer component
classNames: ['advertisement-tool'],
media: service(),
advertisements: computed(
Expand All @@ -16,7 +16,7 @@

// Don't forget to also increment the 'amountOfAdvertisements' variable in
// styles/components/advertisement-tool.scss and the number of advertisements
// in tests/rendering/components/advertisement-tool-test.js
// in tests/integration/components/advertisement-tool-test.js
advertisementItems: [
{
title: 'Qorting.nl',
Expand Down
3 changes: 2 additions & 1 deletion app/components/md-editor.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
@value={{@content}}
class='form-control md-editor'
rows='15'
data-test-md-editor-textarea
/>
{{else}}
<div class='alert alert-info mx-2' role='alert'>
Heb je een foto ingevoegd in dit artikel? Deze worden pas getoond als je het
artikel hebt opgeslagen.
</div>
<div class="px-2">
<div class='px-2'>
{{markdown-to-html @content extensions='youtubeEmbed bootstrapTable'}}
</div>
{{/if}}
Expand Down
34 changes: 18 additions & 16 deletions app/components/model-form/checkbox-input.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<div class='{{labelClass}}'></div>
<div class='{{inputWrapperClass}}'>
<div class='form-check'>
<Input
data-test-input={{property}}
@type='checkbox'
id={{inputIdentifier}}
@checked={{mut (get model property)}}
class={{concat 'form-check-input ' inputValidityClass}}
required={{required}}
disabled={{disabled}}
/>
<label class='form-check-label'>
{{label}}{{if required ' *'}}
{{form-control-feedback (get @model.errors property)}}
</label>
<div class='mb-3 {{if this.usesGrid 'row'}}'>
<div class='{{this.labelClass}}'></div>
<div class='{{this.inputWrapperClass}}'>
<div class='form-check'>
<Input
data-test-input={{@property}}
@type='checkbox'
id={{this.inputIdentifier}}
@checked={{mut (get @model @property)}}
class={{concat 'form-check-input ' this.inputValidityClass}}
required={{@required}}
disabled={{@disabled}}
/>
<label class='form-check-label'>
{{@label}}{{if @required ' *'}}
{{form-control-feedback (get @model.errors @property)}}
</label>
</div>
</div>
</div>
3 changes: 0 additions & 3 deletions app/components/model-form/checkbox-input.js

This file was deleted.

3 changes: 3 additions & 0 deletions app/components/model-form/checkbox-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import TextInput from './text-input';

export default class CheckboxInput extends TextInput {}
36 changes: 19 additions & 17 deletions app/components/model-form/datetime-input.hbs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<label
class='col-sm-2 col-form-label form-label'
for={{inputIdentifier}}
>
{{label}}{{if required ' *'}}
</label>
<div class='col-sm-10'>
<Input::DatetimeInput
@inputId={{inputIdentifier}}
@dateValue={{mut (get model property)}}
@inputClass={{concat 'form-control ' inputValidityClass}}
@placeholder={{placeholder}}
@required={{required}}
@disabled={{disabled}}
@yearRange={{yearRange}}
/>
<div class='mb-3 {{if this.usesGrid 'row'}}'>
<label
class='col-sm-2 col-form-label form-label'
for={{this.inputIdentifier}}
>
{{@label}}{{if @required ' *'}}
</label>
<div class='col-sm-10'>
<Input::DatetimeInput
@inputId={{this.inputIdentifier}}
@dateValue={{mut (get @model @property)}}
@inputClass={{concat 'form-control ' this.inputValidityClass}}
@placeholder={{this.placeholder}}
@required={{@required}}
@disabled={{@disabled}}
@yearRange={{@yearRange}}
/>

{{form-control-feedback (get @model.errors property)}}
{{form-control-feedback (get @model.errors @property)}}
</div>
</div>
3 changes: 0 additions & 3 deletions app/components/model-form/datetime-input.js

This file was deleted.

3 changes: 3 additions & 0 deletions app/components/model-form/datetime-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import TextInput from './text-input';

export default class DatetimeInput extends TextInput {}
95 changes: 61 additions & 34 deletions app/components/model-form/file-input.hbs
Original file line number Diff line number Diff line change
@@ -1,36 +1,63 @@
<label class='col-form-label form-label {{labelClass}}'>
{{label}}{{if required ' *'}}
</label>
<div class='{{inputWrapperClass}}'>
{{#let (file-queue name="fileUpload" onFileAdded=(action 'fileLoaded')) as |queue|}}
<label for="upload-file" class="form-label {{if not (get model property) "border rounded p-2 w-100"}}">
{{#if (get model property)}}
<img id={{inputIdentifier}} src={{mut (get model property)}} alt={{label}} role="button" tabindex="0"
aria-controls="upload-file" />
<br />
{{else}}
<span class='image-upload-text' role="button" tabindex="0" aria-controls="upload-file">
Sleep hier een nieuwe bestand naartoe of klik om een bestand te kiezen
</span>
{{/if}}
</label>
<input type="file" id="upload-file" class="" hidden accept={{validMimetypes}} {{queue.selectFile}}>
{{/let}}
{{#if fileToBig}}
<br />
<div class='alert alert-danger'>
Dit bestand is te groot om te uploaden, gebruik een bestand kleiner dan
{{maxFileSize}}MB
</div>
{{/if}}
{{#if extensionNotPermitted}}
<br />
<div class='alert alert-danger'>
Deze bestandsextensie wordt niet ondersteund. Geaccepteerde extensies
zijn:
<b>{{validExtensionsString}}</b>
</div>
{{/if}}
<div class='mb-3 {{if this.usesGrid "row"}}'>
<label class='col-form-label form-label {{this.labelClass}}'>
{{@label}}{{if @required ' *'}}
</label>
<div class={{this.inputWrapperClass}}>
{{#let
(file-queue name='fileUpload' onFileAdded=this.fileLoaded)
as |queue|
}}
<label
for='upload-file'
class='form-label
{{if not (get @model @property) "border rounded p-2 w-100"}}'
>
{{#if (get @model @property)}}
<img
id={{this.inputIdentifier}}
src={{mut (get @model @property)}}
alt={{@label}}
role='button'
tabindex='0'
aria-controls='upload-file'
/>
<br />
{{else}}
<span
class='image-upload-text'
role='button'
tabindex='0'
aria-controls='upload-file'
>
Sleep hier een nieuwe bestand naartoe of klik om een bestand te
kiezen
</span>
{{/if}}
</label>
<input
type='file'
id='upload-file'
hidden
accept={{this.validMimeTypes}}
{{queue.selectFile}}
/>
{{/let}}
{{#if this.fileTooBig}}
<br />
<div class='alert alert-danger'>
Dit bestand is te groot om te uploaden, gebruik een bestand kleiner dan
{{this.maxFilesize}}
</div>
{{/if}}
{{#if this.extensionNotPermitted}}
<br />
<div class='alert alert-danger'>
Deze bestandsextensie wordt niet ondersteund. Geaccepteerde extensies
zijn:
<b>{{join ', ' this.validExtensions}}</b>
</div>
{{/if}}

{{form-control-feedback (get @model.errors property)}}
{{form-control-feedback (get @model.errors @property)}}
</div>
</div>
38 changes: 0 additions & 38 deletions app/components/model-form/file-input.js

This file was deleted.

53 changes: 53 additions & 0 deletions app/components/model-form/file-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import TextInput, { type TextInputSignature } from './text-input';
import ENV from 'amber-ui/config/environment';
import type { UploadFile } from 'ember-file-upload';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export interface FileInputSignature extends TextInputSignature {
Args: TextInputSignature['Args'] & {
validMimeTypes?: string[];
validExtensions?: string[];
loadedCallback: (
file: UploadFile,
data: Awaited<ReturnType<UploadFile['readAsDataURL']>>
) => void;
};
}

export default class FileInput extends TextInput<FileInputSignature> {
@tracked fileTooBig = false;
@tracked extensionNotPermitted = false;

maxFilesize = `${ENV.maxFilesize}MB`;

get validMimeTypes() {
return this.args.validMimeTypes ?? ['image/jpeg', 'image/png'];
}

get validExtensions() {
return this.args.validExtensions ?? ['jpeg', 'jpg', 'png'];
}

extensionInvalid(file: UploadFile): boolean {
const fileExtension = file.name.split('.').slice(-1)[0]?.toLowerCase();
if (typeof fileExtension === 'undefined') {
throw new Error('Could not parse file extension');
}
return !this.validExtensions.includes(fileExtension);
}

@action async fileLoaded(file: UploadFile): Promise<void> {
this.fileTooBig = false;
this.extensionNotPermitted = false;

// File.size is in bytes
if (file.size > ENV.maxFilesize * 1048576) {
this.fileTooBig = true;
} else if (this.extensionInvalid(file)) {
this.extensionNotPermitted = true;
} else {
this.args.loadedCallback(file, await file.readAsDataURL());
}
}
}
1 change: 1 addition & 0 deletions app/components/model-form/radio-button.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type='radio' ...attributes />
Loading
Loading