Mattermost-server: Remove usage of findDOMNode from Analytics screens

Created on 1 Oct 2020  Â·  9Comments  Â·  Source: mattermost/mattermost-server

ReactDOM.findDOMNode is considered to be an escape hatch in React for when you need to access the DOM directly, but it's generally preferred to use Refs for this instead since it has better support with newer React features such as the experimental concurrent mode.

The usage of ReactDOM.findDOMNode should be removed, and refs should be added if necessary to keep the same functionality in the modified components. This will help us be prepared for new versions of React, and it'll let us try out newer React features that come along.

Since this is a campaign spread across multiple tickets, this ticket focuses on removing findDOMNode from the following components in the web app:

  • components/analytics/doughnut_chart.tsx
  • components/analytics/line_chart.tsx

These components are used in the analytics screens in the System Console. They use chart.js to draw different graphs to a Canvas which are displayed on the page. We should remove findDOMNode by either replacing the string ref for the canvas with React.createRef so that we don't need findDOMNode any more, or we should look at wrapping chart.js with a more React-friendly library instead.

Also, if possible, either E2E tests (using Cypress) or unit tests should be added to confirm that the previous behaviour still works.

For more details or if you have any questions, feel free to reach out to @hmhealey or message me on https://community.mattermost.com where I go by harrison.


If you're interested please comment here and come join our "Contributors" community channel on our daily build server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers" community channel.

New contributors please see our Developer's Guide.

JIRA: https://mattermost.atlassian.net/browse/MM-29000

Easy Hacktoberfest Help Wanted PR Exists TecReactJS

All 9 comments

Hello, may I work on this please? :) This will be my first contribution here.

Thanks for the help on this, @93lykevin. Let us know if you have any questions!

Hi, I'm running into an error when I run "make run-server". I am trying to get mattermost-server running on my machine.

INFO[2020-10-07T16:46:19.005093-07:00] Loaded system translations                    caller="utils/i18n.go:90" for locale=en from locale=/Users/kevintly1/Desktop/OpenSource/mattermost-server/i18n/en.json
DEBU[2020-10-07T16:46:19.00527-07:00] Parsing server templates                      caller="utils/html.go:30" templates_directory=/Users/kevintly1/Desktop/OpenSource/mattermost-server/templates
INFO[2020-10-07T16:46:19.0298922-07:00] Pinging SQL                                   caller="sqlstore/supplier.go:235" database=master
ERRO[2020-10-07T16:46:19.2324421-07:00] Failed to ping DB                             caller="sqlstore/supplier.go:247" error="pq: role \"mmuser\" does not exist" retrying in seconds=10
INFO[2020-10-07T16:46:29.233203-07:00] Pinging SQL                                   caller="sqlstore/supplier.go:235" database=master

I've followed the Developer Setup instructions. Any tips on how I could fix this would be greatly appreciated (: Thank you!

That's strange. The mmuser database user should have been created automatically by one of the steps of make run-server.

Just to confirm that the database is actually running and that the error is accurate, could you run docker ps? If the database is running, you should see a line with the IMAGE "postgres:9.4" and the NAME "mattermost-postgres".

If it shows up, then there's something wrong with how the database was configured. You could try to run make nuke to delete the Docker containers used by the Mattermost dev environment and then run make run-server again to see if that fixes some temporary failure.

The mmuser was successfully created when I ran make run-server

Creating mattermost-inbucket ... done
Creating mattermost-mysql    ... done
Creating mattermost-minio    ... done
Creating mattermost-postgres ... done
Creating mattermost-server_start_dependencies_run ... done
docker ps
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS                   PORTS                                                                          NAMES
fdc636927929        postgres:9.4                               "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes (healthy)   0.0.0.0:5432->5432/tcp                                                         mattermost-postgres
c895c2b34a4b        minio/minio:RELEASE.2019-10-11T00-38-09Z   "/usr/bin/docker-ent…"   4 minutes ago       Up 4 minutes             0.0.0.0:9000->9000/tcp                                                         mattermost-minio
18044c41bf3b        mysql:5.6                                  "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes (healthy)   0.0.0.0:3306->3306/tcp                                                         mattermost-mysql
b73b317b4ebe        jhillyerd/inbucket:release-1.2.0           "/con/context/start-…"   4 minutes ago       Up 4 minutes             0.0.0.0:10025->10025/tcp, 0.0.0.0:10080->10080/tcp, 0.0.0.0:10110->10110/tcp   mattermost-inbucket

I've ran make nuke and make run-server again and still run into this same problem.

That looks like it's running properly at least, so I'm not sure why the account isn't being set up correctly. Perhaps you can connect to Postgres and manually create the user? If you run docker exec -it mattermost-postgres psql -U postgres mattermost_test, that should let you log in as the root user and then you should be able to create the mmuser user and give them the correct permissions. I think the commands to do that should be:

create user mmuser with password mostest;
alter user mmuser with superuser;

After that, a make restart-server should hopefully let the server log into the database successfully.

Running docker exec -it mattermost-postgres didn't work but docker exec -it mattermost-postgres /bin/bash does.
Now, I'm logged in as the root user root@fdc636927929.
Then, I tried running psql -U postgres mattermost_test and it gives me psql: FATAL: role "postgres" does not exist
However, I am able to connect with psql -U mmuser mattermost_test which makes it seem like mmuser does already exist.
Just to confirm, running create user mmuser with password 'mostest'; says, ERROR: role "mmuser" already exists.
I am successful in running alter user mmuser with superuser; (Apparently user postgres doesn't exist in the database)

Finally make restart-server still gives me the same errors:

INFO[2020-10-08T13:00:37.553341-07:00] Pinging SQL                                   caller="sqlstore/supplier.go:235" database=master
ERRO[2020-10-08T13:00:37.561548-07:00] Failed to ping DB                             caller="sqlstore/supplier.go:247" error="pq: role \"mmuser\" does not exist" retrying in seconds=10

Looking at the logs from docker-compose logs postgres, I get:

...
mattermost-postgres   | server started
mattermost-postgres   | CREATE DATABASE
mattermost-postgres   | 
mattermost-postgres   | 
mattermost-postgres   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
mattermost-postgres   | 
mattermost-postgres   | waiting for server to shut down...LOG:  received fast shutdown request
mattermost-postgres   | .LOG:  aborting any active transactions
mattermost-postgres   | LOG:  autovacuum launcher shutting down
mattermost-postgres   | LOG:  shutting down
mattermost-postgres   | LOG:  database system is shut down
mattermost-postgres   |  done
mattermost-postgres   | server stopped
mattermost-postgres   | 
mattermost-postgres   | PostgreSQL init process complete; ready for start up.
mattermost-postgres   | 
mattermost-postgres   | LOG:  database system was shut down at 2020-10-08 18:04:46 GMT
mattermost-postgres   | LOG:  MultiXact member wraparound protections are now enabled
mattermost-postgres   | LOG:  database system is ready to accept connections
mattermost-postgres   | LOG:  autovacuum launcher started
mattermost-postgres   | FATAL:  role "root" does not exist
mattermost-postgres   | FATAL:  role "root" does not exist
...

I'm not sure why this happens.

Oh, interesting. So the Docker container is running correctly since the postgres user has been renamed to mmuser successfully, but Mattermost still can't connect to it. The error message you saw earlier must be misleading then.

If you go to the server's config/config.json, what are the SqlSettings.DriverName and SqlSettings.DataSource set to? We recently changed the default development database to Postgres, so maybe there's something wrong there? The ones I use are

        "DriverName": "postgres",
        "DataSource": "postgres://mmuser:mostest@localhost:5432/mattermost_test?sslmode=disable&connect_timeout=10",

Also, I'm running on MacOS in case that matters. There used to be some slightly different steps for different OSes on really old version of Docker, but that hasn't been the case for a while now.

I figured it out!!
I had another postgres listening on port :5432

➜  mattermost-server git:(master) sudo lsof -i :5432
COMMAND   PID      USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
postgres  818 kevintly1    5u  IPv6 0x46baf81e1ef8b46d      0t0  TCP localhost:postgresql (LISTEN)
postgres  818 kevintly1    6u  IPv4 0x46baf81e2e5ebafd      0t0  TCP localhost:postgresql (LISTEN)
com.docke 869 kevintly1   71u  IPv6 0x46baf81e1ef8898d      0t0  TCP *:postgresql (LISTEN)

I killed the other instance with sudo kill -9 818 and it started working!

Was this page helpful?
0 / 5 - 0 ratings