Skip to content

Commit

Permalink
feat(Templates): extend the tutorial table
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Jan 10, 2025
1 parent 648a567 commit 33a42d2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 42 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/tables-archive.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Archive tables/views', () => {
it('can archive tables', () => {
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true })

cy.intercept({ method: 'PUT', url: '**/apps/tables/api/2/tables/*'}).as('archiveTableReq')
Expand All @@ -38,7 +38,7 @@ describe('Archive tables/views', () => {
it('can unarchive tables', () => {
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true })

cy.intercept({ method: 'PUT', url: '**/apps/tables/api/2/tables/*' }).as('unarchiveTableReq')
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/tables-export-csv.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe('Import csv', () => {
})

it('Export csv', () => {
cy.loadTable('Tutorial')
cy.loadTable('Welcome to Nextcloud Tables!')
cy.clickOnTableThreeDotMenu('Export as CSV')
const hour = new Date().getHours().toString().length < 2 ? '0' + new Date().getHours() : new Date().getHours().toString()
const minutes = new Date().getMinutes().toString().length < 2 ? '0' + new Date().getMinutes() : new Date().getMinutes().toString()
const date = new Date().toISOString().slice(2, 10)
const fileName = date + '_' + hour + '-' + minutes + '_' + 'Tutorial.csv'
cy.log('filename: ' + fileName)
cy.readFile('cypress/downloads/' + fileName).should('contain', 'What,How to do,Ease of use,Done')
cy.readFile('cypress/downloads/' + fileName).should('contain', 'Open the tables app,Click on tables icon in the menu bar.,5,true')
cy.readFile('cypress/downloads/' + fileName).should('contain', 'Open the tables app,Reachable via the Tables icon in the apps list.,5,true')
})

})
14 changes: 7 additions & 7 deletions cypress/e2e/tables-favorite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Favorite tables/views', () => {
it('can favorite tables', () => {
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true })

cy.intercept({ method: 'POST', url: '**/ocs/v2.php/apps/tables/api/2/favorites/*/*'}).as('favoriteTableReq')
Expand All @@ -34,7 +34,7 @@ describe('Favorite tables/views', () => {
it('can remove favorite table', () => {
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true })

cy.intercept({ method: 'DELETE', url: '**/ocs/v2.php/apps/tables/api/2/favorites/*/*' }).as('unfavoriteTableReq')
Expand All @@ -45,12 +45,12 @@ describe('Favorite tables/views', () => {
})

it('can favorite views', () => {
cy.loadTable('Tutorial')
cy.loadTable('Welcome to Nextcloud Tables!')
cy.createView('test')

cy.get('[data-cy="navigationViewItem"]').first().as('testView')

cy.get('@testView').parent().parent().parent().should('contain.text', 'Tutorial')
cy.get('@testView').parent().parent().parent().should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@testView').find('[aria-haspopup="menu"]').click({ force: true })

cy.intercept({ method: 'POST', url: '**/ocs/v2.php/apps/tables/api/2/favorites/*/*' }).as('favoriteViewReq')
Expand All @@ -70,20 +70,20 @@ describe('Favorite tables/views', () => {
cy.contains('Remove from favorites').click({ force: true })
cy.wait('@unfavoriteViewReq').its('response.statusCode').should('equal', 200)

cy.get('@testView').parent().parent().parent().should('contain.text', 'Tutorial')
cy.get('@testView').parent().parent().parent().should('contain.text', 'Welcome to Nextcloud Tables!')
})

it('can (un)favorite views with favorited parent tables', () => {
cy.get('[data-cy="navigationViewItem"]').first().as('testView')
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@testView').parent().parent().parent().should('contain.text', 'Tutorial')
cy.get('@testView').parent().parent().parent().should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@testView').find('[aria-haspopup="menu"]').click({ force: true })
cy.contains('Add to favorites').click({ force: true })

cy.get('@testView').parent().should('contain.text', 'Favorites')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').first().click({ force: true })
cy.contains('Add to favorites').click({ force: true })

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/tables-fe-filters.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('FE sorting and filtering', () => {
})

it('FE Search in table', () => {
cy.get('.app-navigation-entry-link').contains('Tutorial').click({ force: true })
cy.get('.app-navigation-entry-link').contains('Welcome to Nextcloud Tables!').click({ force: true })

// test case-sensitive
cy.contains('Edit a row').should('exist')
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/tables-import.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Import csv', () => {
})

it('Import csv from Files', () => {
cy.loadTable('Tutorial')
cy.loadTable('Welcome to Nextcloud Tables!')
cy.clickOnTableThreeDotMenu('Import')
cy.get('.modal__content button').contains('Select from Files').click()
cy.get('.file-picker__files').contains('test-import').click()
Expand All @@ -42,7 +42,7 @@ describe('Import csv', () => {
})

it('Import csv from device', () => {
cy.loadTable('Tutorial')
cy.loadTable('Welcome to Nextcloud Tables!')
cy.clickOnTableThreeDotMenu('Import')
cy.get('.modal__content button').contains('Upload from device').click()
cy.get('input[type="file"]').selectFile('cypress/fixtures/test-import.csv', { force: true })
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/tables-rows.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Rows for a table', () => {
})

it('Create', () => {
cy.get('.app-navigation-entry-link').contains('Tutorial').click({ force: true })
cy.get('.app-navigation-entry-link').contains('Welcome to Nextcloud Tables!').click({ force: true })
cy.get('.NcTable').contains('Create row').click({ force: true })
cy.get('.modal__content .slot input').first().type('My first task')
cy.get('.modal__content .ProseMirror').first().click()
Expand All @@ -32,7 +32,7 @@ describe('Rows for a table', () => {
})

it('Edit', () => {
cy.get('.app-navigation-entry-link').contains('Tutorial').click({ force: true })
cy.get('.app-navigation-entry-link').contains('Welcome to Nextcloud Tables!').click({ force: true })
cy.get('.custom-table table').contains('My first task').parent().parent().find('[aria-label="Edit row"]').click()
cy.get('.modal__content .slot input').first().clear().type('Changed column value')
cy.get('.modal__content [aria-label="Increase stars"]').click().click()
Expand All @@ -43,7 +43,7 @@ describe('Rows for a table', () => {
})

it('Delete', () => {
cy.get('.app-navigation-entry-link').contains('Tutorial').click({ force: true })
cy.get('.app-navigation-entry-link').contains('Welcome to Nextcloud Tables!').click({ force: true })
cy.get('.custom-table table').contains('Changed column value').parent().parent().find('[aria-label="Edit row"]').click()
cy.get('.modal-container button').contains('Delete').click()
cy.get('.modal-container button').contains('I really want to delete this row!').click()
Expand Down
5 changes: 4 additions & 1 deletion lib/Service/TableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCA\Tables\Helper\UserHelper;
use OCA\Tables\Model\TableScheme;
use OCA\Tables\ResponseDefinitions;
use OCA\Theming\ThemingDefaults;
use OCP\App\IAppManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
Expand Down Expand Up @@ -72,6 +73,7 @@ public function __construct(
ContextService $contextService,
IAppManager $appManager,
IL10N $l,
protected ThemingDefaults $themingDefaults,

Check failure on line 76 in lib/Service/TableService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Service/TableService.php:76:3: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)

Check failure on line 76 in lib/Service/TableService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

UndefinedClass

lib/Service/TableService.php:76:3: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)
) {
parent::__construct($logger, $userId, $permissionsService);
$this->appManager = $appManager;
Expand Down Expand Up @@ -119,7 +121,8 @@ public function findAll(?string $userId = null, bool $skipTableEnhancement = fal
// if there are no own tables found, create the tutorial table
if (count($allTables) === 0 && $createTutorial) {
try {
$tutorialTable = $this->create($this->l->t('Tutorial'), 'tutorial', '🚀');
$productName = $this->themingDefaults->getName();

Check failure on line 124 in lib/Service/TableService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Service/TableService.php:124:20: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)

Check failure on line 124 in lib/Service/TableService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

UndefinedClass

lib/Service/TableService.php:124:20: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)
$tutorialTable = $this->create($this->l->t('Welcome to %s Tables!', [$productName]), 'tutorial', '🚀');
$allTables[$tutorialTable->getId()] = $tutorialTable;
} catch (InternalError|PermissionError|DoesNotExistException|MultipleObjectsReturnedException|OcpDbException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
Expand Down
64 changes: 40 additions & 24 deletions lib/Service/TableTemplateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,26 @@
use OCA\Tables\Errors\InternalError;
use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Errors\PermissionError;
use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\DB\Exception;
use OCP\IL10N;
use Psr\Log\LoggerInterface;

class TableTemplateService {
private IL10N $l;

private ColumnService $columnService;

private RowService $rowService;

private ViewService $viewService;

protected LoggerInterface $logger;

private ?string $userId;

private string $textRichColumnTypeName = 'rich';

public function __construct(LoggerInterface $logger, IL10N $l, ColumnService $columnService, ?string $userId, RowService $rowService, ViewService $viewService) {
$this->logger = $logger;
$this->l = $l;
$this->columnService = $columnService;
$this->rowService = $rowService;
$this->viewService = $viewService;
$this->userId = $userId;
public function __construct(
protected LoggerInterface $logger,
private IL10N $l,
private ColumnService $columnService,
private ?string $userId,
private RowService $rowService,
private ViewService $viewService,
protected ThemingDefaults $themingDefaults,

Check failure on line 34 in lib/Service/TableTemplateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Service/TableTemplateService.php:34:3: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)

Check failure on line 34 in lib/Service/TableTemplateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

UndefinedClass

lib/Service/TableTemplateService.php:34:3: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)
) {
}

/**
Expand Down Expand Up @@ -679,7 +671,7 @@ private function makeTodo(Table $table): void {
// TRANSLATORS This is an example target
$columns['target']->getId() => $this->l->t('We know what we are doing.'),
// TRANSLATORS This is an example comment
$columns['comments']->getId() => $this->l->t('We have heard that Nextcloud could be a nice solution for it, should give it a try.'),
$columns['comments']->getId() => $this->l->t('We have heard that %s could be a nice solution for it, should give it a try.', [$this->themingDefaults->getName()]),

Check failure on line 674 in lib/Service/TableTemplateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Service/TableTemplateService.php:674:130: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)

Check failure on line 674 in lib/Service/TableTemplateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

UndefinedClass

lib/Service/TableTemplateService.php:674:130: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)
$columns['progress']->getId() => 10,
$columns['proofed']->getId() => 'false',
]);
Expand Down Expand Up @@ -744,42 +736,66 @@ private function makeStartupTable(Table $table):void {
// TRANSLATORS This is an example name
$columns['what']->getId() => $this->l->t('Open the tables app'),
// TRANSLATORS This is an example account manager
$columns['how']->getId() => 'Click on tables icon in the menu bar.',
$columns['how']->getId() => 'Reachable via the Tables icon in the apps list.',
$columns['ease']->getId() => 5,
$columns['done']->getId() => 'true',
]);
$this->createRow($table, [
// TRANSLATORS This is an example name
$columns['what']->getId() => $this->l->t('Add your first row'),
// TRANSLATORS This is an example account manager
$columns['how']->getId() => 'Just click on "new row" and enter some data inside of the form. At the end click on the bottom "save".',
$columns['how']->getId() => 'Use the *+ Create row* button and enter some data inside of the form.',
$columns['ease']->getId() => 5,
$columns['done']->getId() => 'false',
]);
$this->createRow($table, [
// TRANSLATORS This is an example name
$columns['what']->getId() => $this->l->t('Edit a row'),
// TRANSLATORS This is an example account manager
$columns['how']->getId() => 'Hover the mouse over a row you want to edit. Click on the pen on the right side. Maybe you want to add a "done" status to this row.',
$columns['how']->getId() => 'Go to a row you want to edit and use the *pencil* edit button. Maybe you want to add a *Done* status to this row?',
$columns['ease']->getId() => 5,
$columns['done']->getId() => 'false',
]);
$this->createRow($table, [
// TRANSLATORS This is an example name
$columns['what']->getId() => $this->l->t('Add a new column'),
// TRANSLATORS This is an example account manager
$columns['how']->getId() => 'You can add, remove and adjust columns as you need it. Click on the three-dot-menu on the upper right of this table and choose "create column". Fill in the data you want, at least a title and column type.',
$columns['how']->getId() => 'You can add, remove and adjust columns as you need. Open the three-dot-menu on the upper right of this table and choose *Create column*. Fill in the data you want, at least a title and column type.',
$columns['ease']->getId() => 4,
$columns['done']->getId() => 'false',
]);
$this->createRow($table, [
// TRANSLATORS This is an example name
$columns['what']->getId() => $this->l->t('Create views for tables'),
// TRANSLATORS This is an example account manager
$columns['how']->getId() => 'Filter data and save table presets as views to share and combine them into applications.',
$columns['ease']->getId() => 4,
$columns['done']->getId() => 'false',
]);
$this->createRow($table, [
// TRANSLATORS This is an example name
$columns['what']->getId() => $this->l->t('Create applications'),
// TRANSLATORS This is an example account manager
$columns['how']->getId() => 'Combine different tables and views into no-code applications for any purpose. This makes them easily accessible directly in the app bar.',
$columns['ease']->getId() => 3,
$columns['done']->getId() => 'false',
]);
$this->createRow($table, [
// TRANSLATORS This is an example name
$columns['what']->getId() => $this->l->t('Read the docs'),
// TRANSLATORS This is an example account manager
$columns['how']->getId() => 'If you want to go through the documentation, this can be found here: https://github.com/nextcloud/tables/wiki',
$columns['how']->getId() => 'If you want to go through the documentation, this can be found here: [Nextcloud Tables documentation](https://github.com/nextcloud/tables/wiki)',
$columns['ease']->getId() => 3,
$columns['done']->getId() => 'false',
]);


$this->createView($table, [
'title' => $this->l->t('Unexplored territory – get to know Tables further'),
'emoji' => '🥾',
'columns' => json_encode([$columns['what']->getId(), $columns['how']->getId(), $columns['ease']->getId(), $columns['done']->getId()]),
'filter' => json_encode([[['columnId' => $columns['done']->getId(), 'operator' => 'is-equal', 'value' => '@unchecked']]]),
]);
}

/**
Expand Down

0 comments on commit 33a42d2

Please sign in to comment.